Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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. alt text

or is this better alt text

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.

Product Version: UE 4.15
cast.jpg (42.5 kB)
ischild.jpg (46.8 kB)
more ▼

asked Apr 22 '17 at 03:27 AM in Blueprint Scripting

avatar image

6 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

The main reason you cast to anything is because you can't get access to functions or variables of this class other way.

more ▼

answered Apr 22 '17 at 04:03 PM

avatar image

851 31 13 49

avatar image dahZee Apr 22 '17 at 06:59 PM

That's exactly what i would assume, but I still see it being used frequently in this manner in tutorials or otherwise. Even on some peoples questions in the answerhub, it has been suggested. I also see the other way suggested, so I'm really interested in which one is better and in what cases.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 A

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.

more ▼

answered Apr 22 '17 at 09:52 PM

avatar image

1.9k 61 52 191

avatar image dahZee Apr 23 '17 at 12:03 AM

I am very aware of the actual use of each, but i guess that's useful to have here for others with the same question.

The last portion of your answer is more what i'm looking for, although no specific answer was given. I want to know in this specific case, which one of these methods are better, because they have to compile down to different code right?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question