My project is a couch co-op 2 player game.
I’m trying to add online multiplayer to my project but I’m experimenting with mixing online/local couch co-op.
So basically 2 players play local and 2 player more can join online for example.
I just noticed that when the second player joins with SpawnAsPlayerObject in editor, the first player’s “IsLocalPlayer” and “IsPlayerObject” in the network object becomes false for some reason.
Which makes me think there can only be 1 playerobject per client or something.
Is it possible to have multiple player objects on a client and how would I do it?
The trick is to either not rely on the built-in “player prefab” automatism, or to use it to spawn a LocalPlayers object which takes over the spawn/despawn requests for local couch coop players. That way every client has its own player prefab instance, which is sort of the networked LocalPlayerManager where you do your IsOwner checks etc.
The actual players are independent of the player prefab instance and are both (all) “owned” by the same client (the machine they play on). If you need to distinguish between the local players, this is what the LocalPlayerManager provides. Ideally it would be a simple array/list so you can use indexes for local players 0 and 1.
When such a player’s OnNetworkSpawn runs, it looks for the LocalPlayerManager and tells it that it was spawned, so it gets added to the list (but only if IsOwner is true).