With the help of a certain function, I get all references to classes in the desired Gameobject .

Is it possible to get all the variables from this class without going through each class?

  • Most likely you do not need it, describe your real task - Andrey NOP
  • I do not know whether it is available in a unit, but in general for this you can use Type.GetFields and for the received fields FieldInfo.GetValue - yolosora
  • @AndreyNOP if I ask means it is necessary. Get all the variables and as a result the value of these variables - Kostya
  • I'm just trying to tell you that this is a misuse of language. Get a collection (dictionary) and work with it. - Andrei NOP
  • @AndreyNOP in each class to create a dictionary? I need only 1 time to get all the variables from each object - Kostya

1 answer 1

Unity3D is a toy creation engine => maximum performance is important.

What you describe is called reflexion, when an object moves through the bones to the extent that you can read and write protected properties, which reduces performance by several times due to the fact that metadata tables are being searched, and there is an active work with strings. . (See CLR VIA 4.5 from Richter).

And then on the pages of STEAM users will complain that the game slows down on CORE I9 and 1080TI :)

I suspect that you do not need it, but you need something else.

Create properties that allow you to read the data fields and you will be happy.

If you solve the problem of flexibility, then use interfaces or dependency injection.

  • I wrote somewhere that it wakes everybody in a client? It’s only for me in my client to develop - Kostya
  • I need what I wrote and nothing else - Kostya
  • You did not write why you need it. Perhaps there is a simpler solution. - iluxa1810
  • get all the variables and their values ​​to the console from each script at a time - Kostya