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
Create a simple ClientNetworkTransform component that overrides OnIsServerAuthoritative method to return false
Assign this component to a prefab
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!
Description
When spawning a
NetworkObjectusingSpawnAsPlayerObjectmethod, it always appear in 0,0,0, ignoring the position it had when it was instantiated.Reproduce Steps
ClientNetworkTransformcomponent that overridesOnIsServerAuthoritativemethod to return falseActual 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
Additional Context
Please take a look at this video.
spawn_client_authoritative.mp4
The way I instantiate and spawn the prefab:
Thanks a lot!