Download

Question about Casting

Hi all,

I’m new here to UE4, which is an awesome tool. I have experience with UDK or Unity game developing.

I’m just confused on how casting works in UE4(4.7.2). :frowning: I read the material on casting form other blueprints, but when I try it, it doesn’t work for me.

For example, I try casting an int from an player BP to enemy BP(let’s says invisibility), it doesn’t work for me.

I try creating a variable with that actor type, picking it from the drop down list, etc, but it feels like a bug.

Casting to the player always works for me via “get player controller” node, though. I’m still confused.

Thank you for your time.

In your first example, you try to cast an int32 to an UENUM (which is not just a simple native enum, but a complex type). You can cast an UENUM type to the “Byte” type and vice versa, and you can make a Byte out of an int32

If you want to cast a complex type, there are the “Cast To” nodes. These only work if the object you want to cast from is a base class of the type you want to cast it to. For example, you have a Blueprint, which derives from AActor (Actor). Then you could try to cast any “Actor” to that new Blueprint Type (Let’s say BP_MyActor). This cast may fail, however, if the Actor is not a BP_MyActor object. In this case, there are two different nodes:

Ok, I understand a little more.

So should I cast to broad Actor(like AIController), then set my “object” pin to whatever is a child of said actor(PawnController that inherits AIController)?

Thank you.

Well, I don’t really know what you want exactly. What is it that you want to accomplish? Cast an AIController to a specific class of yours which inherits the AIController class?
Could you provide a more accurate example?

First make an int in your enemy bp called invisible

In your player bp you first need to get a ref for the enemy bp - I often do this with a get all actors of class node choosing enemy bp as the thing to find, then do a get 0 on the array that it makes. Then you can cast to this ref and if you drag off the cast node (not the execution pin) and start typing ‘set invisible’ then you can set the var in that bp.

Good luck