Skip to content

GetPlayerNetworkObject should throw exceptions if used wrong #581

Closed
@LukeStampfli

Description

@LukeStampfli

Is your feature request related to a problem? Please describe.
NetworkSpawnManager.GetPlayerNetworkObject will only work on the server for all clients because clients aren't aware of each other. If I use this as a client for another clients id it will just return null.

Describe the solution you'd like
Add the following lines at the beginning of it:

if !(NetworkManager.Singleton.LocalClientId == clientId){
    throw new NotServerException("Only the server can find player objects from other clients.");
}

Describe alternatives you've considered
In theory the client could be aware of player objects of other clients. Because we always populate owner id and whether an object is a player object over the network. So we could maintain all clients which have at least 1 owned NetworkObject in the NetworkManager.Singleton.ConnectedClients dictionary.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good-first-issueContributions are welcome. Good first issue for newcomers or first time contributors.type:featureNew feature, request or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions