# Find all subclasses of a certain baseclass?

**URL:** <https://forums.unrealengine.com/t/find-all-subclasses-of-a-certain-baseclass/337736>\
**Category:** C++\
**Tags:** subclass, unreal-engine, question, CPP\
**Created:** [November 7, 2015, 9:33am UTC](https://forums.unrealengine.com/t/find-all-subclasses-of-a-certain-baseclass/337736 "2015-11-07T09:33:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_882e135e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_882e135e](https://forums.unrealengine.com/u/anonymous_user_882e135e)\
**Post date:** [November 7, 2015, 9:33am UTC](https://forums.unrealengine.com/t/find-all-subclasses-of-a-certain-baseclass/337736/1 "2015-11-07T09:33:43Z")

</div>

I have an item-baseclass that is probably going to have a lot(100+) of subclasses. Is there a way to automatically get a reference to every subclass, so that I can spawn a random one out of that list? Or will I have to manually include/add all the subclasses in a spawner class?

Thanks in advance for any help 🙂

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 7, 2015, 4:25pm UTC](https://forums.unrealengine.com/t/find-all-subclasses-of-a-certain-baseclass/337736/2 "2015-11-07T16:25:17Z")

</div>

Manually create array of subclasses on init, even engine does that:

[https://github.com/EpicGames/UnrealEngine/blob/a27ad66f0a075f3b74ef8f68a4b2b0da4882425e/Engine/Source/Editor/UnrealEd/Private/SoundCueGraphSchema.cpp#L492](https://github.com/EpicGames/UnrealEngine/blob/a27ad66f0a075f3b74ef8f68a4b2b0da4882425e/Engine/Source/Editor/UnrealEd/Private/SoundCueGraphSchema.cpp#L492)

So it loks like this:

```
for(TObjectIterator<UClass> It; It; ++It)
{
	if(It->IsChildOf(USomeAwesomeClass::StaticClass()) && !It->HasAnyClassFlags(CLASS_Abstract))
	{
		Subclasses.Add(*It);
	}
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_882e135e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_882e135e](https://forums.unrealengine.com/u/anonymous_user_882e135e)\
**Post date:** [November 7, 2015, 10:19pm UTC](https://forums.unrealengine.com/t/find-all-subclasses-of-a-certain-baseclass/337736/3 "2015-11-07T22:19:10Z")

</div>

Thank you very much, that is excatly what I have been searching for. Didn’t know it would be as simple as just running an iterator over UClass, but hey, the simpler the better 🙂

---

<div class="post-metadata">

**Author:** ![BitRot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bitrot/32/498776_2.png) [@BitRot](https://forums.unrealengine.com/u/BitRot)\
**Post date:** [November 3, 2024, 6:57pm UTC](https://forums.unrealengine.com/t/find-all-subclasses-of-a-certain-baseclass/337736/4 "2024-11-03T18:57:29Z")

</div>

Here’s another way of doing it, for those coming in off google:

```auto
	TArray<UClass*> OutClasses;
	GetDerivedClasses(UBaseClass::StaticClass(), OutClasses, true /* bRecursive */);

```
