Skip to content

NetworkSpawnManager.GetLocalPlayerObject only works on host #580

@LukeStampfli

Description

@LukeStampfli

Describe the bug
NetworkSpawnManager.GetLocalPlayerObject only works on host. A client calling this function will always return null.

To Reproduce
Steps to reproduce the behavior:

  1. Use a MLAPI project which uses player prefabs
  2. Call NetworkSpawnManager.GetLocalPlayer as the client

Expected behavior
NetworkSpawnManager.GetLocalPlayer should give me my local player object as the client.

Environment (please complete the following information):

  • MLAPI Version: release/0.1.0

Additional context
Code for GetLocalPlayerObject is:

        public static NetworkObject GetLocalPlayerObject()
        {
            if (!NetworkManager.Singleton.ConnectedClients.ContainsKey(NetworkManager.Singleton.LocalClientId)) return null;
            return NetworkManager.Singleton.ConnectedClients[NetworkManager.Singleton.LocalClientId].PlayerObject;
        }

But ConnectedClients as indicated by its XML doc is only populated on the server. I talked with Albin about this and one solution which we figured makes sense would be to polulate ConnectedClients with the own local client upon connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good-first-issueContributions are welcome. Good first issue for newcomers or first time contributors.type:bugBug Report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions