Answer the question
In order to leave comments, you need to log in
How to set a reference to an object instance in Unity?
In my game, by calling a method, a prefab clone is created. I threw a script on the prefab, from this script I turn to the variables of another script.
public Game ScriptGame;
An object is created only when a method is called and therefore I cannot designate another script, an error appears when calling:
NullReferenceException: Object reference not set to an instance of an object
As I understand it, I need to somehow specify a reference to the script inside the script through this method, but how to do that?
Answer the question
In order to leave comments, you need to log in
If this "other script" is one, then you can use the singleton pattern.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question