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. Dismiss Notice

Bug The referenced script on this Behaviour (Game Object 'Text (TMP)') is missing!

Discussion in 'Editor & General Support' started by Anatnat-z, Sep 17, 2023.

  1. Anatnat-z

    Anatnat-z

    Joined:
    Oct 29, 2022
    Posts:
    1
    I'm adding a textmeshpro to the canvas and it looks fine, but if I leave the scene or press play on the game the text disappears and I'm getting this error.
    After that the text component looks like this:
    upload_2023-9-17_12-40-53.png
    upload_2023-9-17_12-41-2.png

    How can I fix this? I couldn't find any information about this problem online
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Sounds like you have a defective singleton (aka, "some script using DontDestroyOnLoad() inappropriately), perhaps one that is outliving the things it is referencing. That's my first guess in any case.

    The answer is always the same... ALWAYS!

    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

    Beyond that, here's how to make a proper singleton:

    Simple Singleton (UnitySingleton):

    Some super-simple Singleton examples to take and modify:

    Simple Unity3D Singleton (no predefined data):

    https://gist.github.com/kurtdekker/775bb97614047072f7004d6fb9ccce30

    Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:

    https://gist.github.com/kurtdekker/2f07be6f6a844cf82110fc42a774a625

    These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance
     
    Last edited: Sep 17, 2023