I have one problem with my script in C#.
I try to find one Game object that is in one Canvas.
But the script not found.
I try with:
if I put it out of the canvas work.
How can i do?
What if you derive it from the Canvas? Canvas.FindObjectOfType?
Per your reply the problem is that the gameobject is inactive. Find only returns active objects.
There are two ways to find inactive objects that I know of:
- Resources.FindObjectsOfTypeAll - you can search by script (better) or by GameObject then find the object you want in the returned list. SLOW.
- Manually searching the transform tree. In your case you could start at the canvas object. Can be slow.
However, I suggest you rethink your approach to the problem. If the object exists in the scene hierarchy at design time (i.e. not added via Instantiate or streamed assets) then just setup a reference to it in the inspector. Have a public field in the script that needs to access the script you are trying to find, then assign it in the editor. This will also avoid any performance hit.