Replicated movement of a spawned actor via character ability.

I’m not sure if anyone will see this, kind of confused because my last few posts didn’t receive any feedback. But here’s hoping this one catches someone’s interest. I’ve got way too much spaghetti code to give any visuals at the moment so lets just keep this as a theoretical conversation for the time.

Right now I’m working on a project that has multiple characters that have different abilities, which need to be replicated since it is working towards being an online multiplayer project. One of the characters has the ability to spawn a sentry turret and then after it spawns a second ability can then be used to move the turret where ever the player character is looking via a line trace hit. As of right now the turret can spawn and attack dummy targets and the other client character fine, the move turret ability is the problem at the moment. It moves fine and replicates fine, but since both the clients are playing the same character they can both tell the turret to move. Let’s say they both spawn their own turrets, which ever turret was last spawned is the turret that moves.

So, how might one go about making it to where which ever client spawns their turret then that turret is completely bound to the player controller that spawned it and only moves when the ability is called from the owning player controller? Thank you for taking the time to read this and I hope to hear back from someone. :slight_smile:

lots of ways to do this,

  1. the player could keep a reference to the turret they spawned.
  2. the turret can have a ref to the owning player controller and expose it on spawn
  3. since your using abilities you might have some sort of ability manager that send input to the ‘selected’ ability

Thank you for the input, I’ll look into these options and test them out. :slight_smile:

Right after the SpawnActor node I promoted the Return Value as a variable to store a reference of the spawned turret actor. I then used that variable as a Get and called to the move function within the Turret Actors blueprint. Tested it out and the player character that spawned the turret was the only one who could move it. Now I just have an error that states when the move turret ability was called by the other player character that it returned None. I believe I know how to fix that, but I wanted to thank you for your advice. Helped out a lot. :slight_smile:

1 Like

it should be none for the other player so just use an IsValid check to handle the error

Turret needs to be spawned on the server by the characters server proxy. Then Set Owner, create a reference to the turret.

Call move and other actions on the turret via direct ref event/function calls… Server-side.

Yup, that’s what I did and it stopped showing the error.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.