Hi!
I’ve noticed that the Spawn System card seems to be a high priority.
(Codecks).
I’d like to work on this mechanic if possible.
Although, some clarification would be much appreciated:
What exactly is a “game level” in this context? Is this an independent scene, or can it be multiple places in the same scene?
There appears to be a separate “Scene loading system” card. Do these two systems work together, or independently?
If accepted by Unity, I would like to get some little bit more specifics on how exactly you want it to work like if the spawn is purely for scene changes or you want spawning/de-spawning to be done during runtime too.
If not specified I can just go wild and go free-style trying to cover all the features that I can think of.
Since there isn’t any principles provided(at least from what I’ve seen.) I am going to with KISS if stated otherwise.
In addition of spawning the character on scene changes + with a publicly callable SpawnCharacter method for runtime spawnings, I also implemented an event system which gets invoked after a character is spawned in scene.
The event takes the GameObject that was spawned as a parameter for furthermore runtime checks. This is an utility that I use on my own personal projects to check from my game manager which player is spawned, do the spawned player has any specific components, tags etc than act accordingly.
I don’t know wether to blame my poor english or my kinda poor Unity knowledge, but I don’t understand what this feature is supposed to do. What exactly means to “spawn” a player? Isn’t the player… already spawned, when we start the scene with the gameobject inside?
I’m sorry if mine is a dumb question, I want to contribute but I don’t know how to
Yeah, there seems to be a bit of uncertainty as to how the player will be transported around the world.
I assume there are the following 2 possibilities:
The spawn system must move the player between different scenes.
In this case, “spawning” the player would refer to instantiating a new player into the newly loaded scene.
OR
The spawn system is responsible for teleporting the player between different areas in the same scene.
In this case, “spawning” would simply refer to teleporting the player around.
I assumed it was the latter, and have submitted a pull request with my implementation of that system, but am not certain if that is how it will work in the final game.
Thanks for the reply. I thought about that second option, but in that case we wouldn’t need a separate scene just to handle scene loading, since we will be having very few scenes. But at this point I’m starting to think that I just really don’t know much about the engine because this isn’t the only card that I don’t understand.
That said, let’s try and see what I can do. If it goes wrong, I’m just going to do some story and narrative stuff instead
Usually a spawn system would populate the world with enemies, power ups, wildlife, npc’s, etc obects or even weather systems, particles, etc, and manage which are active or disabled as the player moves around the level. It may handle loading the level (if you had multiple), creating the right player character (if you had more than 1 character to choose from), randomize where dynamic things are created each time the game runs, etc.
If the game world is simple and its PC its probably fine to arrange meshes for the level through the editor but usually in games you’re conscious of performance and load items as needed with a spawner. If it were mobile or webgl and you had 100+ rigged bipeds, or even monobehaviours, in the level, you only take the hit of animating/rendering/running the ones around the player, not the ones that are offscreen across the map, to keep performance up.
Regarding scenes:
Scenes in Unity can be layered, so you could have all your UI stuff in a scene, have the level’s terrain and static meshes as a scene, and additively combine them into the live scene, its good for some things because you can load and unload them to free up memory when you’re done with that content. Often its for massive worlds but it can also be used for treating tutorials as a module you load/unload while the player is in the game.
Sometimes its nice to split UI into a scene for separation of duties, someone can be working on that scene and own everything in it, while someone else is working on the game world without having to merge each others work together every time they commit the monolithic scene.
My Idea about system is something like this:
Have a Player Prefab variable
StartLoaction transform Variable
List of CheckPoints location (checkpoints will be game object with a physics collider set to triggered)
lastCheckPoint Variable
Function ScanScene() called when new scence is open or if scenes are merged
first search for startlocation
the fuction will scan for if all the Check points and add it to Check points list
Function UpdateCheckPoints()
this will update the last checkoint reached by the player
Function Spawn()
to spawn player is not there on startLocation
or if exists but dead then spawn on the Last Checkpoint
As the System is will be inherited from singleton so it will be scene Independent
This is the official thread to discuss the Spawn System (roadmap card).
Please start with simple implementations that generally stick to what the card on the roadmap is saying. There will be time to expand the functionality.
I would like to discuss a phew points about the Card and Game Flow Chart.
My interpretation:
The card suggests it’s a Player spawn system, rather than a Generic Enemy/Item spawn system.
The way the game flow chart is presented it looks like designer placed enemies. Not that it can’t make use of a spawn system, it’s just that, based on the card, seems like a different task.
I requested to work on this functionality but didn’t start until they assign me to the task. I agree with you, will be waste of time and maybe frustrating if you work in something that is not even going to be considered.
The contribution guidelines also encourage people to work together on features.
The people in the Inventory system thread are having a nice discussion over the different ways to implement it. I think that would be fruitful here too ( Inventory System )
In that sense It might also make sense to have several people work on/discuss the same fork, rather than everyone forking for a specific feature seperately.
Based on that (I don’t mean to Hijack anything or kick anyone’s shins), im going to go out and propose the beginnings of a simple solution to start off the discussion.
Based on the card I think a few things can be highlighted: -Needs to be scene independent, and possibly one Prefab only with no dependencies.
Based on this I think a simple solution would be to use the position of the prefab in the scene as an indication as to where the player will be spawned. This would fit decently well with the requirement of ‘just having this prefab in allows the developer to just press play and test the game’ . An alternative is keeping the spawn coordinate(s) stored in the separate instances of the prefab. Especially when a scene can end up with more possible spawn locations.
This is part of the issue I think, there are some scenes where the player can be spawned in two or three locations, dependon on what ‘direction’ they entered the scene from. How will we know what position to spawn the player in if they also recommend we don’t have any dependencies? Will we be able to monitor the game state or ’ previous scene’ at some point?
I think based on the card and the current requirements a simple solution with a (list of) coordinate(s) will work for now, but determining the spawn location is a problem for the near future.
In my game I solved this by creating a simple scriptable object.
public class SceneIdentifier : ScriptableObject {}
That just identifies scene.
Also, in each scene there is one instance of component:
public class SetCurrentScene : MonoBehaviour
{
[SerializeField] private SceneIdentifier sceneIdentifier;
void Start()
{
AkaGameState.LastVisitedScene = sceneIdentifier;
}
}
Also, for each “door” that leads to current scene there is another component
public class PlayerSpawnPoint : MonoBehaviour
{
[SerializeField] private SceneIdentifier fromScene;
}
And finally player spawn system:
public class PlayerSpawnSystem
{
void OnSceneLoaded()
{
var lastScene = AkaGameState.LastVisitedScene;
var spawnPoint = FindSpawnPointFromScene(lastScene);
player.transform.position = spawnPoint.transform.position
}
}
That’s all pseudocode. I hope you get the main idea. Feel free to ask any question.