SpawnActor not replicating to clients

Im trying to have the player spawn an actor that it then saves as an Actor variable for use later. The issue Im having is that the server will show the Actor being created, but when I set it, the clients Actor variable isnt being set. I believe Im replicating it correctly, as I have other variable for animations replicating in a similar way.

player BP

Game mode doesnt really do anything besides spawn the actor, but its included for reference

game mode BP

Second try (I’m sorry)

  • Is the actor “MagnetSpot” set to replicate inside its BP?
  • What happens if you disconnet the link between remote and server*? This seems to be the issue IMHO
  • Have you tried setting both events to “reliable”?

But in general: Why would the GM spawn the actor? If you need it in the Player BP, just spawn it from there. Off “Has Authority” → spawn actor → Save reference in replicated variable. This way the server is creating the variable and if it is set to replicate, it will be visible and interactable for all players (depending on its functionality).

Since the event is called “Add Player”, is this variable only relevant for the respective player? Because if you have multiple characters, they will overwrite the variable to the reference of the last object spawned. You might need an array to store each spawned object to be linked to each player.

Let me know if this helped in any way

  1. Yes
  2. Havent programmed something in for it, but since the actor is just an empty scene root, I wasnt to worried about getting to it right away.
  3. I did do that.

So I was originally spawning directly on the client only, and it was mostly working(each client had their own actor), and I thought I wasnt getting the behavior I wanted(but that was a whole unrelated issue lol) Now that brings up the question, since it seems to be working perfectly fine just spawning from the client only, is it okay to leave it that way?

EDIT

player BP

1 Like

The Actor variable is also relevant to each player

“Just spawning from the client only”

No, I don’t think this would work in the long run. But you are not (just) doing this in the attached screenshot. You spawn it for the client and on the server. If you add the “Switch has authority” back again and spawn it only on the authority, it will be spawned on the server - existing and interactable for anyone - and should be stored in the replicated variable so that each client can access it.

Side-note: What you are doing is actually preferable for something like projectiles. You spawn two instances of the actor: One for the client (so that it shoots the projectile immediately and is not sending it to the server and waiting to get it back to actually start the shooting) and one for the server (so that all fellow players can actually see the projectile themselves). Since you haven’t replicated the variable, the client and the server will always access their own actor.

1 Like

Actor hasn’t been replicated to the client yet, thus the variable/reference would be empty. Also you are setting the reference on the servers proxy of the player.

The clients player class needs to get the reference. So set the magnet spot in the GM and then fire off a multicast. Have the multicast either pass it to the player, OR have the player get and set it.

e.g. get game mode → cast to game mode class → get magnet spot → set magnet spot.

1 Like

@JoshuaTheJoker What’s the overall use of the magnet spot? Is there one per player, or only one that all players need to reference. There could be a better way to handle this more efficiently.

@JoshuaTheJoker I was thinking about the whole thing since spawning off begin play is not a good practice. The following is surely what you need:
Add a child actor to your character! This way it is stored for each character respectively, is replicated and you don’t drain performance on run-time. Access the child actor by adding it to the BP and then use “get child actor” out of the child actor (otherwise you just refer to the child actor component and not the BP itself)
Demonstration

This should be the most efficient approach

1 Like

Its multiplayer, and the Magnet Spot is a spot that sticks each player to a spot

Heres a video with a quick example of what it is doing

I still havent gone through and added the replication to the Actors yet as I have been a lil busy, but I do like the suggestions and Im gonna figure out what works best with the code I have lol

1 Like

Is it strictly used as a location to spawn characters, or does it have further utilization?

Based off what I’m seeing it just looks like a target point for spawning. That being the case I would either use standard player start actors and place them where I needed them in the level or prefab the platforms etc and add a target point component.

The game mode has a few functions for spawning. You can override these to use your custom player starts (e.g. get all actors of class → loop → get target point).

End of day you shouldn’t be spawning player spawn points.

When the players arent moving, it acts as a point of where they are magnetized to. This is so when the ship moves, they stay connected to the ship

Heres how they help they players stay connected to the ship

So I finally went back and fixed it. I used the GameMode AddPlayer function from above and had the player doing this on BeginPlay. I kept it on BeginPlay because I want the player to be able to create a MagnetSpot every time they spawn, as it will also be destroyed when they die.