How to get a variable by its name from an unspawned class?

I do not think that what you are describing is possible. You can only access a variable if a class declares the variable. Otherwise it would be a compiler error even for C++

I will talk about two options. Using a parent class would be less cumbersome but it would only work if your randomly spawned classes have enough in common to have a base class. If not you could define an interface.

  1. Parent Class You could make your random classes all have a single parent class. You would then define your variable on the Parent Class. When you spawn the random object, you would cast it to the parent class and access your variable from there.
  2. Using Interfaces If your random classes have very little in common and you do not want them to have a single parent class you could use an interface.
  • Create a blueprint interface

210494-capture1.png

  • Define an interface function (i.e. Get Variable ) within the newly created Interface

  • In each of your random classes you implement the interface by adding it to the list of interfaces on Class Defaults and by adding the new event on the Event Graph

  • Now you can send a message to your randomly spawned class (use the interface Message not Function Call)

210497-capture3.png