x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Creating class variable

How to get that done in code?

alt text

Product Version: Not Selected
Tags:
classarray.png (2.5 kB)
more ▼

asked Oct 23 '14 at 03:55 PM in C++ Programming

avatar image

Illusive_S
60 10 13 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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)

more ▼

answered Jul 10 '15 at 08:33 PM

avatar image

Pearticle
51 2 17 7

avatar image cmann Apr 07 '16 at 08:46 PM

Thanks, this should be marked is the correct answer.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

Doug Wilson

more ▼

answered Oct 23 '14 at 04:11 PM

avatar image Illusive_S Oct 23 '14 at 04:17 PM

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.

avatar image Doug E ♦♦ STAFF Oct 23 '14 at 05:09 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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).

more ▼

answered Aug 24 '16 at 09:32 PM

avatar image

Nico90
68 6 7 11

avatar image Pearticle Aug 24 '16 at 10:01 PM
 TSubClassOf<MyClass> 

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).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question