Actor replication through blueprint not working when attaching actor to player

Hey all,

I’m new to unreal engine and I’ve gone through several of the tutorials on constructing game logic through blueprints and I’m having a problem with replication of an object over the network. This is for a capture the flag modification on the shooter sampler.

What I’m doing is having the flag object spawned via the level blueprint(as per this tutorial and then when a player character of the correct team collides with the flag item, I use the attach to actor function to attach the player to the actor. This part works fine, from the perspective of the actor picking up the flag, the problem I’m having is that I’m not seeing the flag moving on several of the other client players(I’m testing through the unreal editor). I’ve tried numorous combinations of the replication options through the blueprint but I’ve yet to see the flag consistently through all players. I assume the editor window for the UE4 is actually the server side of the item. I’m wondering exactly what settings I need to have such that the flag position will replicate to all players.

Any help is appreciated,

In multiplayer situations all spawning and destroying must be done on the server if you want all the clients to be able to see it. So, you must use an event set to ‘run at server’. And the actor that you are using for your flag must be set to replicate. Your problem is that the client knows it has picked up the flag but the server has not passed that info on to anyone else.

sometimes that don’t work for me,

make a custom event “run on client” in gamemode with necessary pins u need such as “actors” variables or whatever and an attach to node.

make another custom event in your character that gets fired when u pick up the flag, make it “run on server” and then look for “get gamemode” > cast to gamemode > the custom event in the gamemode above.

this trick basically goes like this, client requests the server to attach something to the player that picked up the flag and does the attach actor process for the requested client and shows it to all clients as well.

so you don’t make the “attach to” in the flag blueprint nor the character, you do it in the gamemode. and custom events to pass the information to the gamemode.


It does not have to be built into the gamemode, but that is the major server authority blueprint. Any actor with “replicate” enabled in the actor defaults can call replicated events.

Fantastic! i got the flag grabbing to work now(following your advice Okja 101) and it’s replicated to all the clients. I do need to go and move the scoring logic to the game mode now too since all of this was being handled in the flag blueprint now. Thanks again for the help.

I did deviate from your advice in one regard, but maybe it’s a semantics thing. I didn’t need to create a custom event for the players pawn. I instead just called the function from the game mode for the flag pickup. I don’t know if this will cause a problem down the line but it seems to work fine for my purposes. Let me know if you guys have anymore input.

Also thanks to PodgyHodgy for the conceptual information and input.

I’ve run into an issue with implementing this solution. The cast to my custom game mode is causing a circular reference which prevents the project from loading. I added an interface to try an remove the reference to game mode, but I still need to call the game mode in order to pass the character the target. Right now, I’m not seeing a way around this. If there’s a way to call and cast the gamemode for the target in my character then I’m not seeing it outright. I suppose I could add the interface to the gamemode.h base class. Input is appreciated to remove the circular referencing.

Mockforce, I think you need to sit back and think about how you have structured this. I do not see why you are involving the game mode except to keep score. First of all solve the attachment and replication. This needs no game mode involvement at all.
In the flag actor use the OnComponentBeginOverlap event. This will give you the actor that has overlapped with the flag.
in the flag actor create a custom event to run on server - lets call it PickedFlagUp. - give it an input, an actor reference variable.
in the flag actor Create another custom event to multicast. - lets call it EveryoneUpdateTheFlag. - again give it an input actor reference variable.
OnComponentBeginOverlap (which happens on the client) calls PickedFlagUp (which runs on the server.)
All PickedFlagUp does is call EveryoneUpdateTheFlag and passes the actor reference along. (but you must do this and go via the server though it looks pointless at first. A client cannot talk directly to other clients. )
The EveryoneUpdateTheFlag event runs the nodes to attach the flag to the Actor whose reference you have passed along to everyone. So every client and the server runs this code. They all see the flag attach to the actor whose reference you have given them.
I think that is it.
Note that everything is in the Flag actor blueprint and there is no need to involve the gamemode at all.
Test it and see.
For keeping score you can add some extra nodes. The PickedFlagUp event is running on the server so can get the game mode (which is exclusive property of the server) and add to the score of the player or team - depends how you are doing it.
I think that is it.