prefab lose script reference when is instantiated at run time
Hi! I have a character that moves to a specific waypoint that instantiates an object (with a referenced script) when a character enters in that point. The problem is, in doing so, the following error appears: "Object reference not set to an instance of an object" . The reason is that when the object is instantiated, it loses the referenced script. I have tried to reference it from the code, but I still get the same error. This is the script of the instantiated object:
public class InstantiatedScript : MonoBehaviour {
public GameObject the_Object_Where_Is_The_Reference_Script;
public referenceScript reference_Script;
private void Start()
{
reference_Script= the_Object_Where_Is_The_Reference_Script.GetComponent<referenceScript>();
}
}
I don't know how to solve this. Hope someone can give me a hand. Thank you very much for your attention and, I hope, your help.
Your answer
Follow this Question
Related Questions
Invisible Prefab spawning at location of Player before being instantiated 1 Answer
Why do my first 50 instances of a prefab have the same properties? 1 Answer
How do you set a variable to a prefab variable? 1 Answer
“Object reference not set to an instance of an object 1 Answer
Alternative to FindObjectOfType and calling function from another script 1 Answer