When a player starts a new game there is a script that assigns a sprite to the character, using a class I've created called CharacterSprite (the class will do more later but right now it just stores a reference to a sprite). Code (CSharp): [System.Serializable] public class CharacterSprite { public Sprite sprite; } Inside my character class it's just a reference to an instance of that object: Code (CSharp): public CharacterSprite sprite; I then have code elsewhere in the game that loads the character and assigns the sprite to a UI Image component, like this: Code (CSharp): public Image photo; public void UpdatePanel(Character character) { photo.sprite = character.sprite.sprite; // Other code unrelated to the sprite } After I start a new game, the sprites load and display fine. I create a save file, then continue playing the game for some time, and the sprites continue to load and display without error. Then, after some period of time passes (the specific amount of time varies) when I play the game and go to the screen with the UpdatePanel function, I start getting the error "MissingReferenceException: The object of type 'Sprite' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object." If I pause the game and view my Character object in the Inspector, the Sprite object says "Type mismatch." What would cause this error? The strange thing is that it all works just fine for some period of time, days or even weeks, and then suddenly I start getting the type mismatch error and it won't display the sprites any more.
The answer to this is ALWAYS the same, it never changes. How to fix a NullReferenceException error https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/ Three steps to success: - Identify what is null <-- any other action taken before this step is WASTED TIME - Identify why it is null - Fix that
Since this is a question about type mismatch and not NullReferenceException, I'll address that. All I know so far for myself is when I replace my Sprite with a new one via Sprite.Create, I get a type mismatch in all the Inspector references to it, which then leads to a NullReferenceException elsewhere. I feel like Sprite.Create should work. I offer this insight as another thing to hopefully cross off your list. As for me, I will continue my search. Best wishes.