How to FIND GameObject by NAME through code in Unity











>> YOUR LINK HERE: ___ http://youtube.com/watch?v=h5znpUSx78I

In this video we see how to FIND A GAMEOBJECT BY THE NAME that has assigned in the hierarchy of a scene in Unity, we will do this in a Script, defining a variable that can store this object, then execute an instruction that finds the object of the scene by its name and store the object in that variable, this way we will have the reference of the object and thus be able to read its variables and execute its public functions. • This method requires that we know the precise name of the GameObject we want to find, spaces and capital letters included. Also in Unity there can be two GameObjects with the exact same name and these objects can be in any hierarchical level, therefore it is necessary to be careful when looking for a GameObject of the scene by its name in Unity since the reference that we obtain could be a different object to the one that we are looking for, if we do not take care of the names of the objects. • This method is used to find GameObjects at runtime, usually in some initialization function like Awake or Start. It is not recommended to use this method in an update function such as Update or FixedUpdate since finding an object by name in Unity requires, in the worst case, scanning all objects in the hierarchy to find the object with the specified name. • The instruction to find a GameObject by name in Unity is: • GameObject.Find( Name of the object ); • In the above instruction we execute the static function Find of the GameObject class and we pass as parameter the name of the object of the scene that we want to search, we can enter the name directly between quotes as in this case, but we can also pass the name into a string variable that has the value of the name. This function goes through the hierarchy looking for a GameObject that has the indicated name, when it finds it, it returns that GameObject and we can assign it to a GameObject variable. • If on the other hand there is no GameObject in the scene with the indicated name, the function returns null. If it was not possible to find a GameObject with the indicated name and then we try to use that GameObject in the code, either to read some variable or to execute some function, we will have a NullReferenceException error. • INTRODUCTION VIDEO OF THE REFERENCE SERIES IN UNITY: •    • Video   • ARTICLE ON HOW TO FIND A GAMEOBJECT BY NAME IN UNITY: • https://gamedevtraum.com/en/game-and-... • ____________________________________________________________ • LINKS • Portfolio: https://gamedevtraum.com/en/portfolio... • LinkedIn:   / gamedevtraum   • Downloads: https://gamedevtraum.itch.io/ • Contact:   / gamedevtraum   • ____________________________________________________________

#############################









Content Report
Youtor.org / YTube video Downloader © 2025

created by www.youtor.org