- Home /
How to get a referance to an instantiated prefab clone ?
Hi guys I am trying to make a simple game , I have 3 sapwn points that Instantiate a random prefab from 5 prefabs , and what I am trying to do is get a referance to that Instantiated prefab , I want to check if the prefab is active or not , I made an empty gameObject and attached a script to it , and the script is something like this : public class Checker : MonoBehaviour {
public GameObject enemy11, enemy22, enemy33, enemy44, enemy55;
private void Update()
{
Order();
}
void Order()
{
if(enemy11.activeInHierarchy == true)
{
Debug.Log("Enemy1");
}
}
}
the problem is that the spawn point , Instantiate a clone of a prefab not the actual game object (enemy11) so the Debu.Log never gets called .
Answer by Edward_Wolfeee · Sep 02, 2020 at 10:26 PM
when you instantiate the prefab instead of doing
Instantiate(0bj,Vector3,Quaternion.identity)
do this
Gameobject thisObj = Instantiate(0bj,Vector3,Quaternion.identity);
you can also use a list to do this
GameObject[] thisObj = Instantiate(0bj,Vector3,Quaternion.identity);
my bad do it like this
public List<Gameoject> objects;
void Update
{
GameObject object = Instantiate(obj,new Vector3, Quaternion.identity);
objects.Add(object);
}
Your answer
Follow this Question
Related Questions
gameObject are not referenced 2 Answers
Reference missing in runtime 1 Answer
Reference Player When Instantiating A Prefab 0 Answers
Assigning a prefab to itself. 1 Answer
How do I assign a prefab reference to a private variable? 1 Answer