Open Moe-Baker opened 2 weeks ago
@Moe-Baker
This part of your steps:
I need a bit more context as to why you want the in-scene placed NetworkObject to spawn the players? Is there any way you could provide me with a replication project (it will help me narrow down the issue faster)? If not, then I need some additional details behind using the in-scene placed NetworkObject as opposed to just using the client to handle the spawning...even just the script on the in-scene placed NetworkObject would help me understand the sequence better.
I need a bit more context as to why you want the in-scene placed NetworkObject to spawn the players
I find that this better organizes my project, we have a few different game modes, with a few different player prefabs, so choosing the player prefab inside the loaded scene is more convenient for me.
Is there any way you could provide me with a replication project
I'll create a replicated project and share it later.
even just the script on the in-scene placed NetworkObject would help me understand the sequence better
For the time being, these are the two scripts stripped down to the offending parts. Player Script & Level Script
@Moe-Baker
What I would recommend is to:
Use something like this adjusted MiniGamesLevel component script:
public class MiniGamesLevel : NetworkBehaviour
{
public GameObject PrefabToSpawn;
// When a client finishes synchronizing it invokes this
protected override void OnNetworkSessionSynchronized()
{
var instance = Instantiate(PrefabToSpawn).GetComponent<NetworkObject>();
instance.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId, destroyWithScene: true);
base.OnNetworkSessionSynchronized();
}
}
There is a known issue where the Multiplayer SDK "re-enables" the "Auto Spawn Player Prefab" setting when joining a distributed authority session, but a PR to remove that is in place and should be in the next update.
Until then, you can not assign a player prefab to avoid the initial automatic spawn and just rely on the MiniGamesLevel to handle this for you.
Let me know if this helps?
Description
NetworkObjects spawned inside a scene are spawned before the scene is loaded on late-joining clients using Distributed Authority.
Reproduce Steps
NetworkManager
session owner and loads a scene "Scene".NetworkBehaviour
script.OnInSceneObjectsSpawned
override and will spawn a "Player"NetworkObject
on it.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId, destroyWithScene: true)
.NetworkBehaviour
with anOnNetworkPostSpawn
override and will register itself with the Level.Actual Outcome
A null reference exception as Client A's Player tries to register itself on the Level script before the Scene is even loaded.
Expected Outcome
That the logical flow of scene and object spawning is maintained. When a late-joining client joins the game, they should first load the active scene, and then spawn NetworkObjects, not just randomly do both.
Environment