Answer the question
In order to leave comments, you need to log in
How to access the fields of a disabled object?
Hello everyone
I want to get access to the field of the object (inventory), which I turn off at startup
public GameObject inventoryBlank;
void Start()
{
inventory.SetActive(false);
}
Object reference not set to an instance of an object
MeshRenderer render = gameObject.GetComponentInChildren<MeshRenderer>();
render.enabled = false;
Answer the question
In order to leave comments, you need to log in
please give an example of where exactly the access to the inventory is and what exactly is there in the inventory for the code.
and partly Konstantin Kitmanov is mistaken. and freeExec is partly true to you. that when you refer to an object, you will have access to fields and methods.
and here's what it would be important for you to understand, NO SEARCH works on DISABLED objects.
GetComponentInChildren is also a SEARCH. and everything like him will not be able to find anything on turned off objects.
maybe in your inventory you don’t just get a value,
but something like
inventory.GetItemInfo(0);
///
void ItemInfo(int itemIndex)
{
something.GetComponent<T>();
}
Actually, no way. The only way out is to turn it off somehow differently, disable the renderer, disable handlers, skip Update, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question