Which is better? 'Is a child of' or 'CastTo' ?
I've been looking at many blueprinting tutorials for building my inventory system, and I've seen both of these methods used to check if a blueprint is a child of another.
I have no idea which one of these methods are the better practice. In either case, I only need to check if the class of the blueprint in question is a child of the other.
Here are some pictures to clarify.
or is this better
I'm especially interested in which one of these might be 'better practice' in terms of performance, or otherwise. It just feels a bit weird to me to use the CastTo if i'm not doing anything with it other than checking if it succeeded.
asked Apr 22 '17 at 03:27 AM in Blueprint Scripting
The main reason you cast to anything is because you can't get access to functions or variables of this class other way.
answered Apr 22 '17 at 04:03 PM
Both functions have their use!
Casting is used to cast an instance of A to B and vica versa!
Preferably used if the object is derived from same type and you want to get that specific type, it can be child or parent.
So lets say you have two classes.
Class B derived from A.
You have an instance of B then you can cast it back to A. and get access to it, but you can also cast it back to B again and get access to B, since the instance is still the same instance as it was before nothing has changed.
While the is Child of only tells if your class is derived from a parent class. With this you can simply check:
Is B child of A?
About performance i am not sure that such a small thing should matter at all, but probably checking the class type is better for what you want to achieve, so use IsChildOf to check if A is child of B. And use casting if you want to get cast something and do something with the result. But casting can be used for the same purpose if you feel like.
Follow this question
Once you sign in you will be able to subscribe for any updates here