I am currently writing in a script that is a component of Beam. Does anyone know how I can access the GameOverUI I tried both creating a normal reference and using GameObject.FindGameObjectWithTag("GameOverUI) but I am still struggling to find a way that works. When I tried to use the FindGameObjectWithTag, Rider showed me this and wouldn't acess it properly.
#How to access a GameObject's parent from within a script?
1 messages · Page 1 of 1 (latest)
Well it's saying that the GameOverUI tag doesn't exist
also the GameOverUI object isn't a parent of Beam
So for FindGameObejectWithTag to work the GameObject has to be a parent of Beam?
No, the tag must exist
Are you sure there aren't spaces in the tag name or it's not UL with a lowercase L
Rider might also just be disconnected. It's a warning not an error
Rider usually doesn't have these issues.The autofill typically works just fine.
I'll try deleting and remaking the tag to test.
Rider still says the same thing. Does C# have anything to access the parent of something?
I'm used to Lua where I can do Script.Parent.Parent.Canvas.GameOverUI
Idk if Unity has something similar.
Try if it still works? Just because Rider doesn't find it doesn't mean it's broken
It doesn't
You can do transform.parent.parent but it's not generally recommended. Optimally the UI manager would be a singleton or you'd assign a direct reference to the UI
Okay, I'll try that.
Findwithtag doesn't find inactive objects
I don't think
I cant really test until later but I dont think thats the problem
What makes you think it's not the problem
It definitely doesn't find inactive objects (just checked the docs)
There’s an optional bool param
Oh okay, is there an alternative?
You can use gameObject.transform.parent or create singletone and attach your gameobject to public or serialized field and then call your GameOverUI from the singleton.
or use search in inactive objects invlude var gameOverUI = Object.FindFirstObjectByType<GameOverUI>(FindObjectsInactive.Include);