NetCode and Spawn Classification Examples

I was just wondering if there were examples of all three spawning modes (delayed, predicted, and player spawned) in the current netcode samples.

For future reference because I have no clue what I’m looking at, can you please provide file names and line numbers of each instance in the asteroids sample.

  • The default spawn behaviour is “Delayed”. Calling EntityManager.Instantiate() with any entity ghost prefab (on the server) will give you this behaviour by default.
  • “Client Predicted” spawning is a layer on top of the above, where the client runs the same code as the server (via prediction) and therefore also spawns the entity (see Bullet spawning in Asteroids via the badly named SteeringJob. Note how the SteeringSystem is in the [UpdateInGroup(typeof(PredictedSimulationSystemGroup))]). The client bullet (which is a fake ghost) then gets mapped to the server bullet via the DefaultGhostSpawnClassificationSystem. If it fails to map within a time limit, we assume a miss-prediction occured, and the invalid client bullet is destroyed.
  • “Player Spawned” is “Client Predicted”. It must be predicted, because the client does not have the authority to spawn entities by themselves. I.e. The only thing the client is allowed to do is predict spawn a ghost that it expects the server to also predict spawn.
2 Likes

So just calling EntityManager.Instantate() forms these predictions and the location, whether inside the predicted loop or on the client or both, determines the spawn category?

Correct. If you notice, there is (correction) only one bit of code in the SteeringSystem that is client specific.
isFirstFullTick == 1 (which is populated via the NetworkTime singleton).

Because it’s in the PredictedSimulationSystemGroup, it’ll run identically on both the client and server. The only nuance is that on the client, prediction runs multiple times per frame, so isFirstFullTick ensures that you only create the bullet once on the client (the first time you predict this frame). I recommend reading this manual on prediction: https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/prediction.html

In earlier versions you had to explicitly define a client ghost as a predicted spawn (via an API), but we were able to remove that in 1.0. See CHANGELOG.md entry:

  • The GhostCollectionSystem.CreatePredictedSpawnPrefab API is deprecated as clients will now automatically have predict spawned ghost prefabs set up for them. They can instantiate prefabs the normal way and don’t need to call this API.
1 Like