And here’s a screenshot of the GameObject Inventory being searched for:
At no point in time through any of my debugging does the GameObject Inventory ever go inactive, so that’s not the issue. The script is able to find PlayerDick (don’t mind the name, I had a similar issue of finding object the other day that was solved by renaming player to something else, oddly similar to this issue). But it isn’t finding the other two, I get a null error.
The function above is on a prefab, once it is created it has to find the tooltip script so it knows how to make tooltips of itself, but for some reason it just flat out isn’t finding it despite the names being perfect matches, I’ve even tried changing the name of inventory but still no luck. This script was working perfectly fine and suddenly while I was working on another script, it just stopped being able to find the object.
This bug is basically causing my entire inventory system to not work, and it’s driving me nuts. Plx halp.
So just to update, I was able to BYPASS the issue, but not solve it or figure out why it appeared in the first place.
Update: I was able to fix the issue by having the script that creates the prefabs assign the variables instead, which was doable without the Find because ‘TempInventTest’ was the one making them. This still does not explain to me why the GameObject.Find stopped working though.
It’s usually not recommended to use GameObject.Find in a big project because it demands a lot of resources. GameObject.FindGameObjectWithTag is much faster and much less demanding!
At start, its not an overly large issue how you get your objects. And when dealing with instantiated objects that need references to a static object, it is one of the most useful ways of Finding an object when you are a beginner.
The issues occur when for absolutely no reason, it just stops finding objects.
The best way to find objects is to use a singleton for managers and anything that you need access to can be found in the related manager.
A classic example of this is a script manager, that managers all your scripts and their update, starts etc.
If you ran a GOFIND every time you needed to add or remove items from an SM you would be breaking the game fast. OnEnables turn many scripts on using singleton references, and circumvent major overhead.
Another example is Navigation manager, that has a grid that an entity needs access to after Instantiation.
If you use GOFind on 200 entities, every entity needs to search your entire scene reference list. If you have 10k+ objects in your scene… just ask yourself how much work that is.
~But access via a singleton is a 0(1). Instantaneous access using already existing references.
So if you arrived here with a problem, step away from using GOFind and start using singletons and proper management scripts. You will be the better for it.