- Home /
How to reference a prefab to the script that doesn't exist in Hierarchy
So I have a Prefab called Apple and It doesn't exist in hierarchy. The Apple have a script called DestroyExistingApple and I'm trying to reference it from the script. The apple doesn't exist in hierarchy at all, it gets instantiated in random position after the game is fully started. The Script: public class Snake : MonoBehaviour { public DestroyExistingApple appleScript; private void Awake() { appleScript = GameObject.Find("Apple").GetComponent(); } } The Error I'm getting: NullReferenceException: Object reference not set to an instance of an object Snake.Awake () (at Assets/Scripts/Snake.cs:15) (Sorry for bad english)
Your answer
Follow this Question
Related Questions
call a another scripts function from a prefab 1 Answer
script type variables 1 Answer
How to modify prefab permanently via script. 0 Answers
How do do i reference standard asset scripts in another script? 1 Answer
Referencing in a prefab 1 Answer