HELLO im so confused Im working on Multiplayer Game But now iwant to Respawning actor After he dead and i want to respawn in diffrent location and respawn in location far away from another player because i dont want to be killed immediatly
First of all, take it easy, don’t get confused. Second of all, there are 100% many options to how you can approach this but here’s the approach off to top of my head: Have an actor that manages all your PlayerStarts (in case you use them to spawn your players) and when a player dies, and you want to respawn him, you line trace to opposing players to check they are not near. FindPlayerStart is the function you would want to override in this context. It’s inside GameMode actor and it’s really a good candidate actor to manage this behavior.
Spawning & Destroying…
Spawning and Destroying actors is expensive. The more complex the actor, the more expensive. Characters are generally pretty robust. Better solution is to re-use the character.
Say No to Destroying. Yes, to Object Pooling…
Instead of destroying a character on death you’d:
- Un-Possess
- Ragdoll/death animation montage
- Set timer by event (15s)… leaves a corpse on the ground for a few seconds
- Timer event → Hide Actor
- Disable Character movement component
- Disable Capsule Component collision (no collision)
Picking a Respawn Location…
Depends on your Game Mode in general. Death Match, Team Death Match would have a completely different setup for spawning locations than say Capture the Flag or Domination.
For DM/TDM you can setup a grid system using box collisions. Use overlap events “running on the server only” to track the number of players and their affiliation in each grid cell.
Use this data to select an empty or team friendly grid cell. Choose a random location inside the bounds of the grid cell, Add n to Z axis (location vector). Then Teleport a corpse (un-used character) to that location.
Possess the Character
- Enable Capsule component collision
- Enable Character movement component
- Unhide Actor
You have officially mitigated resource waste and increased overall performance.