#NetworkServer.Spawn(character) didn't work correctly when new client connect.

1 messages · Page 1 of 1 (latest)

rich olive
#

i create several network identity gameobject on server ,but when client connected,these gameobjects created before connected can't be seen on client,but gameobjects created after connected can be seen .could please help me to solve this problem?thanks

wanton pier
#

Are you using additives/subscenes?

#

@rich olive

rich olive
#

@wanton pier just mainscene

timber ice
rich olive
#

all the gameobject are "PlayerHands“

timber ice
rich olive
#

can you see it?

timber ice
#

also you need to clear both of these

timber ice
rich olive
rich olive
timber ice
#

You don't appear to be calling NetworkServer.AddPlayerForConnection anywhere (that isn't in commented out code)

rich olive
#

because these players are not owned by any client .it just run on the serve and i use the client just for watch.so i just use NetworkServer.Spawn(character);

timber ice
#

Nothing spawns on client until player is spawned for client

#

make an empty prefab with network identity and use that for client's player. assign to PlayerPrefab in network manager and turn on auto-create

rich olive
#

i don't understand why CryInside

timber ice
#

You can do as I suggested or not...up to you

rich olive
#

thank you .i will try your method again.

timber ice
# rich olive

You don't have a Transport assigned either and I don't see anywhere in your code that you're setting it to anything

timber ice
# rich olive this is the script i create player https://pastie.io/iiufdf.cpp

This code is unnecessary. Mirror will spawn all to client when client gets a player

    public void OnServerAddClient()
    {
        Debug.Log($"New client connected:  Synchronizing existing characters...");
 
        // 遍历所有已创建的角色并重新 Spawn
        foreach (var character in createdCharacters)
        {
            if (character != null)
            {
                NetworkServer.Spawn(character);
            }
        }
        Debug.Log($"Synchronized {createdCharacters.Count} characters to client ");
    }
#

I also don't see where you're calling NetworkClient.RegisterPrefab for anything you're spawning and they're not in this list

rich olive
#

it begin to work correctly !!!