Casting node help

First of all Thanks for taking the time to look at this. Second of all congrats if you read all of it :slight_smile:

i have recently started playing around with UE4, I’m 42 years old and the only other programming/game creation i have done was on a ZX Spectrum.

For the most part I think I am picking it up quite quickly, or rather its sinking in quite well. But I don’t seem to be able to grasp the concept of the casting node properly. I think I have the general idea of it, please correct me if I’m wrong.

I need to cast to another blueprint if I need to retrieve variables or run an event.

I have a cast set up in my (animation_BP) to go to (Playercharacter_BP) with object set as {Get player Character} and I think that works because the information I need is in the ****CharacterMovement ****in Components of the Blueprint.

But If my (PlayerCharacter_BP) is holding a sword (Greatsword_BP) and I want my (Animation_BP) to communicate with my Greatsword_BP to turn on a particle effect, using notifications at the start of the montage animations, I don’t understand what goes in the Object pin. My own presumption would be something to do with the mesh because I’m spawning the particle along bone sockets, but have failed miserably every time I try.

Does the required object pin depend of the information I require from the blueprint or does it depend on the type of blueprint class created? Like Actor/Pawn/Character/PlayerControler

please could someone explain the mechanics behind the casting object, in a way that a non programmer could understand or point me in the direction I could learn from, everything I have read so far is full of jargon. I would rather learn the concept than somebody just saying you need to connect the object pin to this.

Thanks in advance for anyone that takes time out of their day to read or reply.

No time to look at your specific use case. But threads like this should help.:wink:
Casting is something you just have to repeat until it becomes more intuitive.
I recommend taking projects apart as rinse repeat really helps you to nail it.

In anim BP you’ll cast to character class. As PlayerCharacter_BP -> Get the sword and cast to Greatsword_BP. From there you have 100% access to all of the swords functionality, events, variables etc.

Casting gives you that 100% access to the class. Without casting you only get top level access.

thank you both for the reply, it gives me a lot more reading to do and another way of trying to try understand it… at the moment it feels like its a bottleneck in my learning.

If it helps… At its simplest, casting is a way to access a hierarchy / tree / organizational-structure. Example1: You need to access an instance of office-janitor versus ceo-management. You need a way to do that while differentiating between all the other worker classes in-between, including call-center-employees versus sales-marketing-staff.

Example2: You design your own general class system called Vehicle. You then create 2 sub-classes such as Car / Plane, from which you create 2 specific instances, such as Lambo / Cessna. Casting helps you access specific properties of those different objects. Overall, you don’t need to cast to get something like location (up-casting). But you do need to cast to get specific properties such as each objects different wheel sizes (down-casting).

BTW: Creating your own classes may help you to unlock this area, as it will make it more concrete and less abstract. :wink:

i have been reading most of the day about casting and im not sure if im using it in the right way, so i will try to explain a bit clearer. In my animation i have a notifier called TrailStart.


when that triggers im trying to cast to my BasicGS blueprint like this.

to perform this event.

first of all, is this the correct way to do this? or would something like blueprint interface be a better way to do it?
sorry to drag up the post again but i feel like im missing something, or rather i keep overlooking something.

my brain is fried with so many different people using different analogies.

For a cast to work, YOU MUST ALWAYS have an actor / object on the left and the right (blue wires). Right now you only have the cast wired with exec wires (white wires). Maybe take a break for a few days since your head is wrecked.

yeah, the left pin is blank because whatever i plugged in, got error message saying it would always fail.

but i think you’re right, i need to do something else and come back with a clear head.
thanks for the response.

When you spawn an actor in your character class (great sword) that’s going to be attached you should promote the “return value” to variable. Name it “Great Sword Ref”. Beyond this manual reference approach there’s no other efficient way to really get a reference to it than “get attached actors”… which returns an array that would need to be looped through.

At Spawn there’s no need to CAST.

In your anim BP you should initialize a reference to the character. The **“Blueprint Initialize Animation” **event is executed once when the Animation Blueprint instance is created to perform initialization operations.

From this point forward you have 100% access to the characters data AND you no longer have to cast to the character from the anim BP.

From here it’s as simple as … Get reference to character -> get reference to sword -> call event.