Search Unity

Question Unity player crashing: Monobehaviour reference 0xFFFFFFFetc

Discussion in 'Scripting' started by Peeling, Nov 24, 2022.

  1. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    443
    I've got a 100% repeatable player crash in the current build of our game:

    Code (CSharp):
    1.        if (referenceCamera)
    2.         {
    3.             Vector3 cent = referenceCamera.transform.position + referenceCamera.transform.forward * 30f;
    4.  
    The 'if' passes, but attempting to access referenceCamera.transform triggers an unhandled exception because 'referenceCamera' is 0xFFFFFFFFFFFFFFFF

    Not sure how to go about debugging this, as the problem seems to be internal to the player rather than anything to do with scripts. Any suggestions?

    EDIT: I think I know what's happening, but I'm not sure why it's crashing the Unity player.

    In previous builds, 'referenceCamera' was a field of type Camera. For various reasons it got changed to a GameObject, and its assignment got changed from:

    Code (CSharp):
    1. referenceCamera = thing.activeCamera
    to

    Code (CSharp):
    1. referenceCamera = thing.activeCamera.gameObject
    I suspect the crash stems from thing.activeCamera being briefly null - but one would expect this to raise an error and leave referenceCamera unchanged, not assign it a corrupt value.
     
    Last edited: Nov 24, 2022
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    Are you sure you don't have this variable serialized in the editor? If it is serialized, make sure you assign the right object type to it. Changing the type of an already serialized field is never a good idea. Personally I never had such an issue, so not sure if that may be the reason. Though it's the only thing that I can think of.
     
  3. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    443
    I don't think that's the issue. It's assigned in code, not serialised, and it definitely seems to be the assignment that causes the issue.
    .