Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Unity player crashing: Monobehaviour reference 0xFFFFFFFetc

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

  1. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    344
    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:
    2,435
    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:
    344
    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.
    .