Casting to Parent class

Hello, so i have a weapon system where every weapon is its own actor then i have an Actor Socket on my character where i set what weapon actor i wanna use like this:

And then i more or less use the weapons animation blueprint for all the functions, but to replicate the shoot function correctly i think i need to run it on my servers character right? So i need to cast back to the character ( The parent ).

But i have no idea what to put in here:

I dont know how to reference my character, the game is a multiplayer game so i cannot do PlayerController because that makes all the players on the map shoot.

Do i need to first cast back to the weapon actor from the animation blueprint, and then cast to the parent or something?

Thanks! :DD

If your character contains all the shooting logic, which it seems like it does: Inside the animation blueprint, use the “Get Owning Pawn” and cast that to your character class that handles the shooting logic.

If your character doesn’t contain the shooting logic, it’s handled by your child actor class instead. Inside the animation blueprint, use the “Get Owning Actor” and cast that to your weapon actor class.

I noticed you posted here too, which I also answered. Check it out.

Yea it turns out that the casting was not the problem. there seems to be an issue on the characterBP replication:

This is in the AnimationBP ^^

Here is the characterBP ^^ As you can see the CustomEvent is “RunOnServer”, Still this happends:

I dont get it, i am replicating the custom events? why is the server not replicating back to the clients?

You are obtaining player character 0. Try using the “Get Owning Pawn” it’s dynamic. then cast to your character, then obtain the child actor from that, then cast to your weapon class, then call the event. See how that goes.

Edit: I think I see the problem.

Your server is the only one doing the line trace. In your character blueprint, you need to tell the server to do something, then get the server to tell every client to do it. So;

use an event that is set to “Replicate to server(if owning client)”
Then get the server to use a “Replicate to all(If server)”

That should solve it.

The Cast from AnimBP fails if i use TryGetPawnOwner, GetPlayerCharacter is the only thing that succedes the cast. Or… It says it works, but i get no linetrace what so ever ingame when i shoot if i cast using TryGetPawnOwner.

I Guess that is what you ment because there is no such thing as GetOwningPawn in the list when i try to cast from AnimBP

EDIT: Get PlayerPawn Works, though it gives the same result, Linetrace only shows at the Server

Sorry yeah, that’s what I meant. Try connecting a print to see what’s actually coming out of the cast. Have you tried the multiplayer events I suggested yet?

I Will, try to build some different blueprints from what you suggested and see if that takes me anywhere, i’ll update later with my results!

Thanks for the support so far!

Good luck mate!

So i cannot go this way, because if i set the CustomEvent to ExecuteOnAll ( Multicast )

Then when the host fires, all clients fires as well

Okay so i have tried going all crazy ways in the characterBP, and i either get the same result ( Only fires on the Server )
Or none can Fire.

However, if i run the Linetrace inside the animationBP everything works exacly ow i should, so i dont know, if nothing works on the characterBP i guess i have to go with doing the linetrace inside the AnimBP instead. The problem with that is that do now have the CameraPosition to start the Linetrace from, but i’ll try to reference it into the animBP in some way.

Alright i give up, no more!

This will have to do:

This is running inside the AnimBP

1 Like