- Home /
Question by
miramaslow · Jun 21, 2018 at 07:17 PM ·
gameobjectnullreferenceexceptioninstancesaccessing
Instantiated cloned GameObject returns Null outside Start method
I'm attempting to access a cloned 'Goal' GameObject from a different function inside the same script. I'm getting the information in the Start method, assigning the GameObject find/get component script code to a variable. When I'm printing the results outside the Start method, it returns null, even though the 'goal' variable is public.
void Start()
{
GameObject goalTemp = (GameObject)Instantiate(goal,respawnGoalLocation[CreateLevel.currentLevel-1],Quaternion.identity);
goal = goalTemp.gameObject;
}
public void Explode()
{
Debug.Log(goal);
Instantiate(rockParticle, goal.transform.position, goal.transform.rotation);
Instantiate(explosionParticle, goal.transform.position, goal.transform.rotation);
}
What am I doing wrong here? Thanks for your time!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612165222im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NullReference when accessing GameObject in array (C#) 1 Answer
How to add a gameobject to a null gameobject 1 Answer
NullReferenceException, I don't understand why. 1 Answer
Assign collider and linerenderer to list 1 Answer
NullReferenceException: Object reference not set to an instance of an object error? 1 Answer