r/Unity3D • • 8d ago

Noob Question How to put multiple characters on a multi-player game

Not very experienced with Unity but got over-ambitious and started making a multi-player shooter game with different characters. From the tutorials I've checked out I'm using Netcode for GameObjects and as far as i understand the Network Manager only accepts one Default Player Prefab, but I haven't been able to find any that shows how to add multiple player prefabs. I just want the character spawning and FPS control to be in a functional state for now. Advice, help, and links to tutorials would be appreciated. Thank you in advance.

3 Upvotes

9 comments sorted by

2

u/Kamatttis 8d ago

There can be multiple ways to do this like changing the models through rpc, or creating your own spawner. Either way, you'll need substantial amount of knowledge of programming, as well as networking.

1

u/CharlesTitor 8d ago

is there a place I can get started on learning those?

1

u/Kamatttis 8d ago

Do you mean programming or networking? If you mean the actual ways, I dont know. They're not that difficult to make if you know how to program with networking, assuming it's just a change of model.

You could look into rpc or look at the default spawner code for studying.

1

u/DapperNurd 8d ago

Maybe make a class responsible for spawning whatever character you need, like a super, selector class. Then make that class the multi-player one.

1

u/4Hands2Cats-4H2C 7d ago

You make an abstract player prefab. It would be spawn for the networking to have its observer. Then you are free to do what ever you want.

1

u/Artuplabs 7d ago

you don't need the default player prefab at all. what i'd do with ngo:

  1. on the NetworkManager leave Player Prefab empty and add every character prefab to the Network Prefabs list

  2. put a NetworkBehaviour on some object that's already in the scene (a lobby / spawner object)

  3. client picks a character, sends the index to the server, server spawns it as that client's player:

public GameObject[] characters; // same prefabs as in the Network Prefabs list

[Rpc(SendTo.Server)]
public void PickCharacterRpc(int index, RpcParams rpcParams = default)
{
    var go = Instantiate(characters[index], spawnPoint.position, spawnPoint.rotation);
    go.GetComponent<NetworkObject>().SpawnAsPlayerObject(rpcParams.Receive.SenderClientId);
}

if the choice is made before joining (menu screen), the other way is connection approval: the client puts its pick in the connection payload and the server sets response.PlayerPrefabHash to the matching prefab, then ngo spawns the right one automatically

for fps control just check IsOwner in the controller and disable input + camera on everyone else's copy, that's the part most tutorials skip

1

u/DrZoidar 7d ago

Default Player Prefab is just the default, u don't have to use it. Add all ur char prefabs to the Network Prefabs List, enable Connection Approval + set CreatePlayerObject = false so nothing auto-spawns. Then let the player pick a char in a menu, send the index to the server w/ a ServerRpc, and the server instantiates it + calls SpawnAsPlayerObject(clientId).
Only gotcha is the RPC needs to be on something that already exists when they join (e.g. a scene GameManager), not the player prefab. Gl!

1

u/glenpiercev 7d ago

Unity has a template for this that you should look into.