Spawn system according to number of players


I am making a co-op horror game in Unreal Engine. I am using Blueprint. I want to make a system. I have a grave blueprint called BP_GraveMarker. It also has static mesh etc. What I want to do is; I want to spawn graves as many as the number of players connected to the game. I created an Integer type variable called PlayerCount in Gamemode. I created a vector array called Spawn Locations and created 4 spawn points. The problem for now is,it spawns extra 1 grave. Also it is not replicated. Can anyone help me solve these?

Hello @Blacies,

When it comes to the extra spawning, I have a hunch I know what’s going on. Is the maximum number of players 4? If so, I believe your logic accounts for up to 6 players, which is where your error is coming from.

To break down what your code does:

Gets number of players 0-4
Increments number by 1 (now player count is 1-5)
Loops according to number of players

(For 4 players)
Loop 0
Loop 1
Loop 2
Loop 3
Loop 4
Loop 5

Likely, the solution you want is to subtract the player count by 1 so the number of players is between 0 and 3, and don’t increment the value.

1 Like


My game will be for 4 players max. I’ve changed the clamp max to 3. But this time,it’s fine if 2 players are connected. Like;
1 Player = 1 Grave
2 Players = 2 Grave. That’s working good,but if 3 or 4 players are connected,we still have 2 graves maximum… Where did I make mistake…

I’ve replicated the correct logic setup on my end- and in the construction script for easy in-editor debugging and a print string at the end to see how many times the loop is running.

As you can see, this is outputting 4 cubes at the 4 locations, and the print string is giving us values 0-3, which means the loop is running 4 times, which is what we want.

If you are still getting errors with this setup, your player count input is probably incorrect. You can debug this by attaching the player count variable to the print string.

1 Like

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