Forum rules - please read before posting.

MissingReferenceException: The object of type 'SpriteRenderer'... Problem with save/load?

edited December 2023 in Technical Q&A

Hello,

(Using Unity 2018.2.12f1 and AC1.71.8)

I've suddenly encountered this bug when i move between scenes in the game.

MissingReferenceException: The object of type 'SpriteRenderer' 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.
UnityEngine.SpriteRenderer.get_color ()
AC.FollowTintMap.ResetTintMap () (at Assets/AdventureCreator/Scripts/Camera/FollowTintMap.cs:138)
AC.EventManager.Call_OnInitialiseScene () (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:1662)
AC.SaveSystem.InitAfterLoad () (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:608)
AC.MultiSceneChecker.Start () (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:63)

I am not doing any coding myself. What could be the cause? The only thing I remember doing in the editor player running "continue from last save" even though I didn't have any saves.

Comments

  • The line endings in your error don't appear to match your AC version - is v1.71.8 correct and unmodified?

    It's a very old release. Either way, it looks related to your Tint Map. If you open FollowTintMap.cs, what are the contents of its OnDisable function?

  • edited December 2023

    Thank you for your answer.

    1. Yes, under "about" it says v1.71.8. I have not made any modifications that I know of.
    2. The content of OnDisable function is Eventmanager.OnInitialiseScene += ResetTintMap;

    Screenshot: https://ibb.co/Qvw45PV

  • Thanks for the details.

    I'm afraid I can't recreate the issue, but try replacing line 138 of that script:

    _spriteRenderers[i].color = new Color (1f, 1f, 1f, _spriteRenderers[i].color.a);
    

    with:

    if (_spriteRenderers[i]) _spriteRenderers[i].color = new Color (1f, 1f, 1f, _spriteRenderers[i].color.a);
    

    If that still gives an error, check if the error is exactly the same (line endings included).

  • edited December 2023

    I tried replacing that line, but I still got the same error at line 143 instead.

    MissingReferenceException: The object of type 'SpriteRenderer' 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.

    UnityEngine.SpriteRenderer.get_color ()
    AC.FollowTintMap.ResetTintMap () (at Assets/AdventureCreator/Scripts/Camera/FollowTintMap.cs:143)
    AC.EventManager.Call_OnInitialiseScene () (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:1662)
    AC.SaveSystem.InitAfterLoad () (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:608)
    AC.MultiSceneChecker.Start () (at Assets/AdventureCreator/Scripts/Game engine/MultiSceneChecker.cs:63)

    I only get this error after moving between scenes, not when I only play a single scene. The problems are game breaking:

    • The player does not start at the right spot.
    • Characters and objects that should be invisible are visible.
    • The camera cannot move.
    • Interactions are fine and the player can move fine
  • Make a similar change to line 143, i.e. replace:

    _spriteRenderer.color = new Color (1f, 1f, 1f, _spriteRenderer.color.a);
    

    with:

    if (_spriteRenderer) _spriteRenderer.color = new Color (1f, 1f, 1f, _spriteRenderer.color.a);
    
  • Thank you! That seemed to fix it.

    Except I got the same error at line 130 when I entered scenes that did not have a default tint map assigned. Assigning default tintmap fixed it.

    What do you think could have caused this error and what could I do to prevent it happening again?

  • Can you share the new error in full?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.