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.

Weird MissingReferenceException when assigning a serialized sprite

Discussion in 'UGUI & TextMesh Pro' started by adhdchris, Aug 24, 2014.

  1. adhdchris

    adhdchris

    Joined:
    Nov 13, 2013
    Posts:
    45
    So this is a weird one: I have an array of gameObjects with serialized sprite properties. When I try to access the sprite or it's properties from another script everything works as it should, but when I try to assign it to another gameObject's Image component I get a MissingReferenceException and the gameObject's Inspector panel goes blank. Any idea what the issue could be? Here's the error message btw:
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,165
    Can you paste the code you are using?
     
  3. adhdchris

    adhdchris

    Joined:
    Nov 13, 2013
    Posts:
    45
    Hey Tim, so I've figured out what was causing the exception. Basically I was porting our existing UI which was using Textures instead of Sprites and even though I converted the textures to sprites and changed the property type in code, the types didn't automatically get updated in prefabs. I've attached a repro project just in case my explanation of the issue doesn't really make sense.

    As you can see the image's texture type is set to Sprite and the Supply.cs holds a Sprite reference in the SupplyPrefab but we're still getting the MissingReferenceException. Re-assigning the sprite to the prefab solves the issue.
     

    Attached Files:

    lclemens likes this.
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,165
    If this is a bug please make sure to log it using the bug tracker, it seems like a very corner case thing though as it's from porting an old project.
     
  5. cowlinator

    cowlinator

    Joined:
    Mar 15, 2012
    Posts:
    69
    Thank you adhdchris, you saved me some time.

    I had the same issue. I refactored a serialized field from Texture to Sprite, but the inspector retained the reference to a texture (instead of complaining or breaking the inspector reference because the type was no longer valid).

    Tim C -- I don't think it's such a corner case, as I was not porting an old project. I'm still on Unity 4, so I don't know if this is still an issue in 5.
     
  6. kintovt

    kintovt

    Joined:
    Jan 5, 2017
    Posts:
    12
    The same issue in 2022
     
  7. myazuid

    myazuid

    Joined:
    Jan 29, 2019
    Posts:
    24
    Just had this exact same issue! And yeah, renaming the the sprite references to something new (from the name they shared with the original texture reference) did the trick and got rid of the error.