- Home /
How do I wait for an object to load before accessing it's information?
Hi,
I'm building an iOS game that requires items to be generated dynamically, it then looks in a folder hierarchy after a corresponding file which has the item's name and icon.
Since in some cases I need to access the item's information straight away I'm getting null pointers because the item I'm trying to access hasn't loaded / generated all it's information yet (loading from resource folder). For example: Loading items to Inventory at start and having labels with it's name, where I get an error because the name isn't available yet.
This is a problem I've stumbled upon a few times before in other project but somehow found a way around it. In this case I'd like some help figuring out what the proper way of doing this is. Unfortunately loading all items at the start isn't really an option.
Apologies if this has been answered before, my search skills must be lacking :)
Grateful for any help, thanks!
Phil
$$anonymous$$aybe check to see if the object is null before accessing it?
Answer by Starkid225 · Feb 18, 2013 at 02:31 AM
Maybe perform a yield/coroutine and have it run a function to gather all the information first. Then it will continue and shouldn't have any null pointers. Just my thoughts...
This page may also be of help
I've been thinking about using coroutines but was curious to what other solutions there were. For now I'm going with coroutines. I load the resources, I then pass the information to it's label or whatever it is. Not the best solution but it works :)
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613092903im_/https://answers.unity.com/themes/thub/images/avi.jpg)