Question by
bieloruss · Dec 16, 2019 at 11:58 PM ·
gameobjectinstantiatereference
How to convert an Addressable as Gameobject
Is there a way to do it? I need to have a reference of the object Instantiated with addressables to change it's properties.
This is an example instantiated direct from prefab (that way I can easily have the reference and do some changes) :
for(int i = 0; i < pool.size; i++)
{
//GameObject obj = Instantiate(pool.prefab);
var obj = Addressables.InstantiateAsync(pool.tag);
obj.SetActive(false);
objectPool.Enqueue(obj);
}
I need to do the same but with Addressables (Something like this):
for(int i = 0; i < pool.size; i++)
{
GameObject obj = Addressables.InstantiateAsync(pool.tag);
obj.SetActive(false);
objectPool.Enqueue(obj);
}
Comment
Answer by temoorwali · Feb 10, 2021 at 03:27 PM
var obj = Addressables.InstantiateAsync("Addressable");
if (obj.IsDone)
{
GameObject myObj = obj.Result as GameObject;
myObj.SetActive(false);
}
Cast addressable object in GameObject then you can use it normally.
Your answer
Follow this Question
Related Questions
How to get instantiate object(clone) to get the reference of the original object with scripts? 0 Answers
How to find the (original) Prefab of a GameObject? 2 Answers
How can I get an object reference from a Raycast? 1 Answer
Instantiating GameObject and Adding to list 3 Answers
Destroy Instantiate is not working 0 Answers