# Creating an array of classes

**URL:** <https://forums.unrealengine.com/t/creating-an-array-of-classes/298992>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 15, 2014, 2:42am UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992 "2014-11-15T02:42:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_435a64b01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_435a64b01](https://forums.unrealengine.com/u/anonymous_user_435a64b01)\
**Post date:** [November 15, 2014, 2:42am UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/1 "2014-11-15T02:42:55Z")

</div>

I made a Map Spawner class in c++. part of what it uses was an Array of classes that it used to instantiate map pieces using:

(AMapChunkBase\*)GWorld-\>SpawnActor(FchunkType);

where Fchunk was of type UClass\* FchunkType;

I wanted to have an array of FchunkTypes, and instantiate and test them.

However I’m doing 99% of my code in blueprint. So I made my map spawner class an actor and made a blueprint that inherited from it. I was planning on adding my map types to a UClass\* array and have the code use them.  
However I cannot use this as blueprints can’t use UClass. blueprints can however story arrays of class types. So I could have an array of MapChunkBase’s and instantiate from there. However I do not know how to declare an array of class types in c++, only in blueprints?

Does anyone know how to make a class type variable in c++?

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 15, 2014, 1:22pm UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/2 "2014-11-15T13:22:24Z")

</div>

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Any)  
TArray\< TSubclassOf \> ArrayOfClasses;

This is how you declare an array of class types in ue4 c++. The base class should be the class all your map types inherit from (preferably you created a base class and inherited from that, you can still have the unreal classes too). You can manipulate this in the editor, blueprints, and c++.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_435a64b01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_435a64b01](https://forums.unrealengine.com/u/anonymous_user_435a64b01)\
**Post date:** [November 15, 2014, 5:00pm UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/3 "2014-11-15T17:00:29Z")

</div>

This worked perfectly thank you very much!

---

<div class="post-metadata">

**Author:** ![pezz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pezz](https://forums.unrealengine.com/u/pezz)\
**Post date:** [November 27, 2017, 4:53pm UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/4 "2017-11-27T16:53:58Z")

</div>

How do I then add a class to such array in C++? Let’s say I have something like `TArray<TSubclassOf<USkill>> Skills`  
and a couple of classes (e.g. Skill0, Skill1…) that inherit USkill. I would like to then add Skill0 and Skill1 to the Skills array.

---

<div class="post-metadata">

**Author:** ![Arveanor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arveanor](https://forums.unrealengine.com/u/Arveanor)\
**Post date:** [April 13, 2018, 1:22am UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/5 "2018-04-13T01:22:45Z")

</div>

I suppose after this long it may be silly to even ask but have you got this figured out for yourself?

---

<div class="post-metadata">

**Author:** ![pezz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pezz](https://forums.unrealengine.com/u/pezz)\
**Post date:** [April 13, 2018, 9:51am UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/6 "2018-04-13T09:51:12Z")

</div>

Partially. I managed to do this in blueprints simply by using arrays related nodes on my Skills array. I wasn’t able to do this using cpp though.

---

<div class="post-metadata">

**Author:** ![Arveanor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arveanor](https://forums.unrealengine.com/u/Arveanor)\
**Post date:** [April 16, 2018, 11:43pm UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/7 "2018-04-16T23:43:54Z")

</div>

Ok so I thought I had a simple answer for you but when I actually looked at my code I believe everything I’m doing with TSubclassOf involves setting default values through a blueprint inherited from my c++ class, and this is probably how that type should usually be used.

That being said I don’t want to assume that this will be enough for you, and I have managed to find another topic that seems to describe dynamically getting a class reference that can be used to populate the value of a TSubclassOf, and from there it should be no problem to add it to an array of the same.

> **[Assigning TSubClassOf in C++](https://forums.unrealengine.com/questions/177409/assigning-tsubclassof-in-c.html)**
>
> Hi, I'm doing some modifications on the First Person Example project and I want to assign/change the type of projectile that is used in code. The variable is of type TSubclassOf. I'm using the code found here to get a reference to the blueprint...

I know this is from 2015 so things may have changed a bit, and it seems a little bit messy to me, but also fairly manageable if you need to be able to populate your TSubclassOf from c++

Sorry I couldn’t give you as clean of an answer as my memory told me I could, but hope this will be helpful to you either way.

---

<div class="post-metadata">

**Author:** ![Boremor24](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Boremor24](https://forums.unrealengine.com/u/Boremor24)\
**Post date:** [December 28, 2020, 5:01am UTC](https://forums.unrealengine.com/t/creating-an-array-of-classes/298992/8 "2020-12-28T05:01:09Z")

</div>

Thank you! I’ve been looking for this information for three million years. And thanks to I found it. It is so good that there are people like you !!!
