Skip to content

SpawnAsPlayerObject can't set client spawn position above 255 on the y axis. #3729

@Digital-Kyle

Description

@Digital-Kyle

Description

SpawnAsPlayerObject can only set position < 256 meters on the y axis. Other axis seem to work fine. This only happens to connecting clients, not the host. NetworkTransform is attached to the player, with Owner as the authority. I've also tested this with interpolations off on the rigidbody and network transform component.

Here is the code I'm using to spawn player network objects:

Vector3 spawnPosition = testSpawnPosition;
GameObject playerGO = Instantiate(player, spawnPosition, Quaternion.identity);
NetworkObject netObj = playerGO.GetComponent<NetworkObject>();
netObj.SpawnAsPlayerObject(clientID, true);

testSpawnPosition works at (0,255,0) but not at (0,256,0).

I've also encountered another similar bug when using an object pool. The server can set the spawn position when it's the object's first time being spawned (using SpawnWithOwnership). But every other time it's spawned, it defaults to it's first given spawn point. I solved this by adding a SetPositionClientRpc to the ClientNetworkTransform sample script, and sending the correct position right after spawning. I kinda don't want to do that every time I spawn an object, but if that's the way it is, I'll do it. I'm guessing this same fix will work for players.

Reproduce Steps

  1. Start a hosted game
  2. Instantiate a player network object and set their spawn position to 0,256,0 before spawning
  3. Spawn the player network object with SpawnAsPlayerObject

Actual Outcome

Spawn position defaults to 0,0,0 when spawn position is above 255 on the y axis.

Expected Outcome

Spawn objects above 255 with correct position

Environment

  • OS: Windows 11
  • Unity Version: 6000.2.6f2
  • Netcode Version: 2.6.0
  • Netcode Commit: idk how to find this
  • Netcode Topology: Distributed Authority

Additional Context

Video demonstration: https://youtu.be/RlVHg-r4M3Q

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions