Creating class variable

How to get that done in code?

18768-classarray.png

Hey Illusive_S-

In the header file for your class (the .h file) you want to add a declaration of the variable. As an example, the declaration of “bool bCanRun” defines a boolean variable named “bCanRun”. Then in the source code file (the .cpp) you can set a value to the variable such as “bCanRun = true;”.

Cheers

Perhaps i should elaborate
I meant how to create a variable that can hold a class not an object, or in that case an array of those. I know how to make blue thingies, no idea how to do violet thingies.

If you create a class, you can then make a variable that is of that class type. For instance, if you create a class called Time that has variables for hours, minutes, and seconds; you can then create a variable of type Time and assign that variable the necessary hours, minutes, and seconds.

I realize this is an older post, but what you’re looking for is, I believe, TSubclassOf.
So to declare your array in code, it would look like:

TArray<TSubclassOf<AActor>> UnitsToCreate;

(assuming your array is an array of actor classes. If not, replace AActor with whatever)

Thanks, this should be marked is the correct answer.

Hello, sorry for bumping up that old thread. But can you explain this a little more? What exactly is the code for a Class Variable? And how do I make it public to blueprint. As the author of this thread, I want to create something like a static variable in C++. (So the violet variables in BP).

TSubClassOf
will give you the class of MyClass.

TArray<MyType>

will declare an array of MyType.

So

 TArray<TSubclassOf<AActor>> 

will declare an array of the class of AActor.

If you want to expose a variable to the editor, you will have to use the macros. An example can be found here

If you just want to use the values in actual blueprint scripting, I think you can just use them without doing anything else (it has been a while though, so I might be wrong on this).