Skip to content

Client-authoritative NetworkTransform spawns in wrong position  #2531

Description

@Maclay74

Description

When spawning a NetworkObject using SpawnAsPlayerObject method, it always appear in 0,0,0, ignoring the position it had when it was instantiated.

Reproduce Steps

  1. Create a simple ClientNetworkTransform component that overrides OnIsServerAuthoritative method to return false
  2. Assign this component to a prefab
  3. Spawn prefab on server in some place, other than origin

Actual Outcome

Spawned prefab teleports immediately to scene's origin

Expected Outcome

Spawned prefab should remain the same position it had before spawning over the network.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • OS: Windows 11
  • Unity Version: 2023.2
  • Netcode Version: 1.3.1 (dev branch)

Additional Context

Please take a look at this video.

spawn_client_authoritative.mp4

The way I instantiate and spawn the prefab:

public class SceneManager : NetworkBehaviour {

    public GameObject playerPrefab;
    public Transform spawnPosition;

    public void Start() {
        NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
    }
    void OnClientConnected(ulong clientId) {
        if (IsHost) {
            var newPlayer = Instantiate(playerPrefab, spawnPosition.position + spawnOffset, Quaternion.identity);
            newPlayer.GetComponent<NetworkObject>().SpawnAsPlayerObject(clientId);
        }
    }
}

Thanks a lot!

Metadata

Metadata

Labels

type:supportQuestions or other support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions