Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Spawn non-controllable character prefabs for player avatars.

Discussion in 'Netcode for GameObjects' started by FrenchCardinal, Jun 28, 2021.

  1. FrenchCardinal

    FrenchCardinal

    Joined:
    Oct 28, 2018
    Posts:
    8
    To my understanding with MLAPI, within the network prefabs you can assign a controllable character as a default player prefab that will spawn when you are a host or a client joining a host. But when a client joins the host, each player's game spawns the same default player prefab that has the camera and functionality scripts as the avatar for the other player which causes issues with the player's character controls.

    I saw a method of removing/deactivating the functionality of the controllable character using if(!IsLocalHost) within the OnNetworkStart override function. But if your character is more complex and has a lot of different components then it can get daunting to disable/remove those components.

    Is there a way to spawn the default player prefab for the player playing the game while spawning a different player prefab that has no functionality to represent that player to the other players?
     
    agogiam_1 likes this.
  2. agogiam_1

    agogiam_1

    Joined:
    Jul 6, 2021
    Posts:
    3
    Hi,
    I am looking for a similar solution, did you get any breakthrough? I need some of my players to join as spectators that can select and follow the playing players in the scene. I tried changing the default prefab to a camera prefab using the following code on Start method of my script -
    GameObject hostGameObject = Instantiate(followCameraPrefab, transform);
    hostGameObject.GetComponent<NetworkObject>().SpawnAsPlayerObject(NetworkManager.Singleton.LocalClientId)
    I am new to unity and MLAPI, please help. Thanks!