- Home /
The question is answered, right answer was accepted
Set gameobject to null in a function
I've got a gameobject that is set to a new gameobject and if it's already spawned once it'll run a function to reset that new gameobject and get a new object.
What I tried is:
void ResetSlot(GameObject ResetMe){
Debug.Log("Slot resetted: " + ResetMe.name);
ResetMe = null;
}
Any suggestions? Is it even possible?
Looking forward to any and all answers!
Answer by Dinosaurs · Oct 22, 2015 at 09:14 PM
It seems like you need to pass the class with the GameObject variable that you want to reset in, and set the variable to null on that class. When you pass a reference variable into a method, it creates a new reference so you're only setting the ResetMe variable to null inside ResetSlot().
You might want to read the C# documentation on reference variables to get a better idea what I mean: https://msdn.microsoft.com/en-us/library/s6938f28.aspx
Follow this Question
Related Questions
Storing component of instance in an array 2 Answers
Please help my head is burning from this problem : i have multiple gameobject , same script 1 Answer
Script on multiple objects not working properly! 1 Answer
transform.SetParent(null); Not Working 1 Answer
Changing alpha value of a canvas from a different game object 1 Answer