I
I
ikryloff2021-09-04 19:39:31
Unity
ikryloff, 2021-09-04 19:39:31

Static instance of the Monobehaviour object?

Please tell me, I found an example of a class that can be accessed from anywhere by creating a static entity of this class in the Awake method.
public static GameClass instance = this;

From any other class, you can now access the public methods and properties of this class.

GameClass.instance.SomMethod();

Similar to a singleton, but without uniqueness checks.
What are the disadvantages of such an approach? Is it possible to do so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-09-04
@GavriKos

This is the singleton.
You can do it if you understand the consequences and causes of occurrence.
Well, what are the shortcomings ... Connectivity, architecture, life control ... Everything is classic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question