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

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:


How can I fix this? I couldn’t find any information about this problem online

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):

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

These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance