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.
asked Sep 13 '15 at 08:26 PM in C++ Programming
Try IsA(Class), it's function in actor so you need to use it this way:
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:
answered Sep 14 '15 at 12:21 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here