Reference Game Objects in Unity

Publicado el: 24 diciembre 2021
en el canal de: Boxfriend
802
33

These are some of the best ways to reference game objects in the Unity engine. There are other methods of getting a reference such as the GameObject.Find and GameObject.FindObjectsOfType methods, but those methods are generally slow because they need to traverse the hierarchy to find the object and you don't get to choose which object it finds if you have multiple that match the parameters of the search.

My thoughts on the Singleton pattern:
It's a great design pattern and can be incredibly useful. However a lot of new game developers tend to overuse them and make everything a singleton just for easy references. This is bad practice, only use the singleton pattern when it is actually necessary, for example your UI doesn't need to be a singleton, it can subscribe to events to get updates from your player or other objects.

For more info about events, take a look at these resources:

Unity Learn: https://learn.unity.com/tutorial/even...

Jason Weimann on C# Events or UnityEvents:    • Events or UnityEvents?????????  

TIMESTAMPS
00:00 Serialized References
01:26 Singleton Pattern
03:09 Dependency Injection
05:07 Events


En esta página del sitio puede ver el video en línea Reference Game Objects in Unity de Duración hora minuto segunda en buena calidad , que subió el usuario Boxfriend 24 diciembre 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 802 veces y le gustó 33 a los espectadores. Disfruta viendo!