Possible to get child class from parent?

I have a TSubclassOf<class AInventoryActor> actorType; and would like to set it to whatever class is currently the child of AInventoryActor. Is that possible?

AInventoryActor : AActor
-actorType = AInventoryActor

AStaticMeshActor : AInventoryActor
-actorType = AStaticMeshActor

ASword : AStaticMeshActor
-actorType = ASword

A TSubclassOf can hold every subclass of the specified class, no additional work needed. If needed you could then cast it to the specific type.

Right, but is it possible in the parent’s constructor to set it to whatever the current class is?

What are you trying to achieve? The UClass* of a class can simply be retrieved via GetClass() if that is what you are searching for. If you filled your actorType with that in the constructor of AInventoryActor every class inheriting it’s constructor would set it to it’s respective class. But why would you need that anyway? You can just use GetClass() on the instance when needed, no need to store it anywhere.

Except if by: “would like to set it to whatever class is currently the child of AInventoryActor” you mean somehow getting the class of a subclass, which I don’t think is possible.

That’s what I was trying to do. Oh well, thanks anyways!

Well, actually, does this help?
https://answers.unrealengine.com/questions/330058/find-all-subclasses-of-a-certain-baseclass.html

Of course you would have to compare the classes you are looping over to your parentclass somehow. Also you need to think about the fact that a class can have multiple subclasses. But again: Why do you even need that? :slight_smile: Seems to me that there’s probably a better way to achieve whatever you are trying to achieve.