Skip to content

Player spawn ignores position and rotation (connection approval) #3074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SubatomicPlanets opened this issue Sep 25, 2024 · 5 comments
Closed
Assignees
Labels
priority:high This issue has high priority and we are focusing to resolve it stat:imported Status - Issue is tracked internally at Unity type:bug Bug Report

Comments

@SubatomicPlanets
Copy link

SubatomicPlanets commented Sep 25, 2024

When using connection approval and setting the players position and rotation, it doesn't work correctly. It always spawns at 0,0,0 with rotation 0,0,0.

I upgraded from 1.7.1 to 2.0.0, and everything seems to be working fine (not a complex project) except for the spawning of players. Obviously they should spawn at the position and rotation that I set.

Example:

Transform spawner = GameObject.FindGameObjectWithTag("Spawner").transform;
response.Approved = true;
response.CreatePlayerObject = true;
response.Position = spawner.position;
response.Rotation = spawner.rotation;

When adding Debug.Log to check the position and rotation, it prints the expected values (in my case, somewhere around 30, 60, 50 for position). This means the Transform spawner was found, and all of this is working. But when the player spawns, it's always at 0,0,0.

I tried different player prefabs and different settings, but nothing worked. I also just created a new project with the Bootstrap sample and just added this code to the BootstrapManager:

private void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
{
    response.Approved = true;
    response.CreatePlayerObject = true;
    response.Position = Vector3.one;
    Debug.Log(response.Position); //prints 1,1,1
    response.Rotation = Quaternion.identity;
}

and networkManager.ConnectionApprovalCallback += ApprovalCheck; before it starts the host on line 21. Then I also enabled connection approval on the network manager in the scene. I would expect the player to spawn at 1,1,1 but it spawns at 0,0,0.

I use Netcode 2.0.0 and Unity 6000.0.20f1 on Windows

@SubatomicPlanets SubatomicPlanets added stat:awaiting-triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Sep 25, 2024
@SubatomicPlanets
Copy link
Author

SubatomicPlanets commented Sep 26, 2024

I looked around the code trying to see what I could change and I think it might actually be a really simple fix.
In the GetNetworkObjectToSpawn method in NetworkSpawnManager.cs on line 756 it says this:
networkObject = UnityEngine.Object.Instantiate(networkPrefabReference).GetComponent<NetworkObject>();
I believe the fix could be as simple as changing this line to this:
networkObject = UnityEngine.Object.Instantiate(networkPrefabReference, position, rotation).GetComponent<NetworkObject>();

I tested it using multiplayer play mode and it seemed to work.

@NoelStephensUnity NoelStephensUnity added priority:high This issue has high priority and we are focusing to resolve it stat:import Status - Issue is going to be saved internally and removed stat:awaiting-triage Status - Awaiting triage from the Netcode team. labels Sep 26, 2024
@NoelStephensUnity NoelStephensUnity self-assigned this Sep 26, 2024
@NoelStephensUnity
Copy link
Collaborator

You are indeed correct on this regression bug.
I will have a PR up for this hopefully by today/tomorrow and it will be included in the v2.0.1 update.

Thank you for the follow up and the investigation you did (helped me quickly verify the bug with your findings).

@SubatomicPlanets
Copy link
Author

Okay, great! Do you have any idea of when v2.0.1 will release?

@NoelStephensUnity
Copy link
Collaborator

NoelStephensUnity commented Sep 27, 2024

Soon... I am not allowed to discuss actual dates but I can say within a few weeks from today.
Until then, you can always replace your com.unity.netcode.gameobjects manifest.json file entry with this:
"com.unity.netcode.gameobjects":"https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#develop-2.0.0",

That will provide you with the most recent fixes that have been merged for NGO v2. Once the new package update is released you can just update to that via the package manager.

@fluong6 fluong6 added stat:imported Status - Issue is tracked internally at Unity and removed stat:import Status - Issue is going to be saved internally labels Oct 7, 2024
@SubatomicPlanets
Copy link
Author

This is now fixed in the newest version, closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:high This issue has high priority and we are focusing to resolve it stat:imported Status - Issue is tracked internally at Unity type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

3 participants