This is maybe kind of a silly question and I found some similar topics in the forum and also on Google but none of them answer my question. How does the spawn system work in UE4? And is there a way to override it?
I have a soccer field level with total 7 PlayerStarts (3 for each team and 1 for the ball). Before the game starts there is a “Wait for other players” widget and after that, the server spawns all players depending on which team they are (Kind of like in Rocket League)
I have dummy pawns as default pawn class that should all spawn at the same location but they spawn randomly (depending where the camera in the editor was, when the level was saved I believe)
Now is there a way to define on which PlayerStart the pawns spawn or do I have to make other objects (like target points or so) for my 7 spawn points and just one PlayerStart object?
The key is your GameMode. This is where the logic goes to handle player creation. If nothing is defined in the game mode, the game will simply select a random PlayerStart. If no PlayerStarts exist, the game will use 0, 0, 0.
If you click on your player start object you’ll see ‘Tags’ under Actor. This can be used to give your player starts an ID of some sort that you can reference in your blueprint. For example, you can fetch all of your player starts, then loop through looking for the ID you care about (using a Actor Has Tag node).
In your case I’d tag your PlayerStarts like:
blue_start_1, blue_start_2, blue_start_3
red_start_1, red_start_2, red_start_3
ball
Beyond that it’s a matter of tracking state to figure out where to spawn. When you’re trying to manually find a start position, you need to see if it’s available (another Actor could have taken it already). Actor is available? Possess it! Try exploring Find Player Start in your Game Mode returning a PlayerStart actor (I also believe Choose Player Start is an option to explore as well). Feel free to dig into the API docs to see what’s available (look for Blueprint functions, denoted on the left).
Hello. I hope that this answers your question. I have made a function in the gamemode script that can be called at any time, such as when the widget detects that all players connected. Here is a picture of the function.
That’s what I’ve setup already. The player spawning works fine. I did a similar thing like Discodude16 shows in the answer below. (Just the camera rotation is sometime on team 1 facing the wrong direction (character direction/rotation is fine).)
My question is more about the camera-pawn spawning that happens before the actual player character spawn. But I guess I have to set that up as well, like I did the soccer-player character spawn. I just thought that there is some other mechanics behind the spawning system of UE4.
Anyways, your answer made things clearer and now I know, that my attempts were all pretty much right.
Thanks for the BP screens. I’ve something similar setup already but this is kind of a simpler way than my solution. My question depends more on the camera-pawn spawn but I guess I have to set that up as well, like the actual soccer-player character.
I thought I might resolve this since I now know whats actually going on with the cameras.
There is an option in the Class Defaults of Player Controllers called "Auto Manage Active Camera Target"
True: the camera switches automatically, when posessing a pawn. If the pawn doesn’t have a camera attached, it “creates” one on the world location of the pawn and uses this one.
False: you’ll have to control the camera manually with functions like “Set View Target with Blend”, which takes an actor as input and uses the active camera of that actor. The camera will not automatically change on pawn posession
The way the camera flow works is like this:
Spawns Player Controller that has a Camera on the World Location: 0,0,0
Waits for a Player Pawn that gets posessed by the Player Controller to use its camera or waits until the camera gets set manually by code
So I guess the best way is to set the view target on Begin Play inside the Player Controller and not using dummy pawns for, in this case the “Wait for player” widget view.
For the actualy character spawning, use one of the above answers.