Comparing class variable to object variable's class

So for example, in one place I have a TSubclassOf variable. Then I have a UThing* variable elsewhere that the previous variable is used to spawn. I’m trying to perform a check to see if the UThing* is an instance of the same subclass of UThing that I have stored in the TSubclassOf variable. I’m a bit stumped on how though - my first thought had been to compare the TSubclassOf variable to the return value of GetClass() called on UThing*, but that didn’t work. I have a controlled scenario where I know the can’t be any other subclasses spawned (because right now there’s only one and I can see instances of it in the details panel), but it’s still returning false. I’m not sure where to look for other solutions, either. I’ve looked at reference documentation for TSubclassOf, but I didn’t see anything that immediately jumped out at me as a way to solve the problem.

Try IsA(Class), it’s function in actor so you need to use it this way:

SomeObject->IsA(UThing::StaticClass());

Is a returns true if actor is related to class you inputed, you use GetClass() comparison if you want to check if object is exactly that class you searching for, that the difference between those 2 methods.

Also TSubclassOf is template for UClass* which limit selection to specific class relation, if you use UClass* insted of TSubclassOf it will show you all UObjects classes. TSubclassOf got operator override to UClass* it’s work the same. So if you look for refrence you should look here:

3 Likes