Spawn Point System

serenity

New member
Hello,

I have a few questions regarding the Spawn Point System:

1) It seems to only work with characters and not other objects like healthpacks, am I correct?
If that is correct why does the Respawn component attached to healthpack prefab have the option to select between "Spawn Location" and "Spawn Point"?

2) I see in the multiplayer demo in the Demo Manager GameObject that there are multiple SpawnPoint children GameObjects. How are those points setup in the SpawnPointManager? I don't see a public field that I can assign a reference to these spawn points? Is it done through code?

Thanks
 

Justin

Administrator
Staff member
1) It seems to only work with characters and not other objects like healthpacks, am I correct?
No, it'll work with any object type. You can check what is going on by placing a breakpoint within Respawner.Respawn.

2) I see in the multiplayer demo in the Demo Manager GameObject that there are multiple SpawnPoint children GameObjects.
Each SpawnPoint has a grouping. A random spawn point will be selected from that grouping. No scripting is required unless you change that grouping index dynamically.
 

serenity

New member
Each SpawnPoint has a grouping. A random spawn point will be selected from that grouping. No scripting is required unless you change that grouping index dynamically.
Thanks
So I created 4 Spawn Points GameObjects (Gave them the SpawnPoint Script Component) but the HealthPack is only respawing using the position of the last added spawnpoint GameObject. I also tried changing the grouping of the HealthPack itself and the 4 SpawnPoints to 1 instead of -1 and the problem persists. If I go ahead and add a 5th spawn point this will be the position of all respawns. Am I missing anything?
 

Justin

Administrator
Staff member
Can you place a breakpoint within Respawner.Respawn and determine where within SpawnPointManager.GetPlacement it returns the existing position? My guess is that the spawn point collides with another object so there isn't a valid spawn point.
 

serenity

New member
I don't think it is a collider issue as I removed all walls and just kept a floor and separated the SpawnPoints so they done overlap even in the bounding area.

This code is the one always called:

// Optionally try to spawn in the first spawn point.
SpawnPoint firstSpawnPoint;
if (m_FirstSpawnPreferred && m_FirstSpawnPoint.TryGetValue(grouping, out firstSpawnPoint)) {
if (firstSpawnPoint.GetPlacement(spawningObject, ref position, ref rotation)) {
Debug.Log("Optionally try to spawn in the first spawn point");
return true;
}
}

Even though the code snippet before it doesn't say that no SpawnPoints where found:

List<SpawnPoint> spawnPoints;
if (!m_SpawnPointGroupings.TryGetValue(grouping, out spawnPoints)) {
Debug.LogError("Error: Unable to find a spawn point with the grouping index " + grouping);
return false;
}

What I mean is the second code I pasted does not show the error in console

And the last code in the function doesn't seems to run:

// Choose a random spawn point and get the spawn placement.
ShuffleSpawnPoints(spawnPoints);
var attempt = 0;
while (attempt < spawnPoints.Count) {
if (spawnPoints[attempt].GetPlacement(spawningObject, ref position, ref rotation)) {
return true;
}
attempt++;
}
Debug.Log("Spawn Attempt " + spawnPoints[attempt]);
 

serenity

New member
I think this piece of code is being called all the time not giving the chance for the code next to it to spawn randomly using the shuffle function.

C#:
// Optionally try to spawn in the first spawn point.
            SpawnPoint firstSpawnPoint;
            if (m_FirstSpawnPreferred && m_FirstSpawnPoint.TryGetValue(grouping, out firstSpawnPoint)) {
                if (firstSpawnPoint.GetPlacement(spawningObject, ref position, ref rotation)) {
                    return true;
                }
            }
When I comment it, random spawning seems to work.
Any Input?
 

Justin

Administrator
Staff member
Code:
SpawnPoint firstSpawnPoint;
if (m_FirstSpawnPreferred && m_FirstSpawnPoint.TryGetValue(grouping, out firstSpawnPoint)) {
if (firstSpawnPoint.GetPlacement(spawningObject, ref position, ref rotation)) {
Debug.Log("Optionally try to spawn in the first spawn point");
return true;
}
}
So it always returns true on this line? Do you have First Spawn Preferred enabled?
 

serenity

New member
So it always returns true on this line? Do you have First Spawn Preferred enabled?
Yes this is the problem. I though there must be an option like this but couldn't find a checkbox in neither "checkpoint" or "respawner" scripts but after you mentioned it I searched again and it is in script attached to "Game" GameObject
Thanks :)
 
Top