GameObject (named 'MainCamera') references runtime script in scene file. Fixing!

GameObject (named ‘MainCamera’) references runtime script in scene file. Fixing!

runtime error~~~
I was using Unity5 personal Edition.
please help me ~~~

Need a lot more information here. What is happening? What are you expecting to happen? Are there errors?

This is due to you making the script unable to be on a gameobject. Either it’s not a MonoBehavior or you’ve made it inaccessible. What’s the keyword before the class?

I had the same issue and fixed it deleting the prefab that had the script… I don’t know if that was a good solution but it help.

3 Likes

@LucianoAdvenio works! thank you

This is a warning, not an error.

I have “GameObject (named ‘GameManager’) references runtime script in scene file. Fixing!” because I created a class that’s [System.Serializable] just to hold information, without using MonoBehaviour. I need this class to store information outside of the scene, so that it isn’t lost when I switch scenes. It’s sort of like global variables.

I also get a warning that this class is not derived from MonoBehaviour or ScriptableObject.

Is this a problem? The code works, but the warnings suggest that Unity doesn’t like it. I suppose another way is to use Singleton or Toolbox, but I am following a tutorial by Brackeys who seems to know what he’s doing and he’s doing it this way. In the tutorial, he didn’t get these warnings though.

Could someone please respond if this is okay, or should things be done differently? I’m fairly new.

To give more information, I have a GameManager that’s MonoBehaviour and a class called Question which is not MonoBehaviour, but is [System.Serializable], and simply stores a public string that’s the question, and a public boolean that’s whether the correct answer is true or not. It’s basically a very simple quiz game, where you answer true or false to each question.

The fact that the public class Question is not MonoBehaviour and is [System.Serializable] is throwing the Unity warnings. Please let me know if I should be concerned or if I’m using a poor coding practice. Thank you in advance.

Ok, I figured it out… sorry for the above question, but maybe my answer will help someone who made the same mistake.

You can make a [System.Serializable] class to store info, just don’t put it on a game object!!! Pretty simple, if I paid attention to the error message, I would realize this. So the class won’t be instanced anywhere in the game, but you can still use it in your other scripts, like in the GameManager or whatever runs your game.

That took away the warnings and the game runs fine. Sorry for all the hassle.

me too getting the same error but it was game object(main camera).
Pls help me to rectify this issue