Index Based Spawning

I have not been able to get working Index based spawning using coherence, so experience in a car racing game is… not good, because when we want to spawn cars at locations, then we aren’t able to do so, because we land on each other when two players play, alteruna is hard for car racing, other wise i would have used alteruna since it has spawn position based index, player 1 goes to spawn point 1, player 2 goes to spawn position 2 etc…

BUT COHERENCE, JUST JUST coherence can’t do that?? this is so sad :disappointed::disappointed:
I thought coherence making multiplayer so simple, can’t do that??

I need HELP!!!

Hi @muhammadkhankk945, and welcome to the forums!

The concept of index-based spawning is not a universal concept (I had never heard of the term!) but rather, specific to how each game does spawning.

As I imagine it, you’re describing a racing game where each player who joins gets spawned on a starting grid… like in a formula 1 game?

If that’s the case, it’s easy! You just need a network entity that manages it. Whoever has control of that entity, they can just have some code like:

  1. Have a list of starting positions
  2. Have an index that starts at 0
  3. Everytime someone joins, pick a new position from the list and move their car (or spawn a car for them) there. Increment the index.
  4. Repeat

Now, who owns this manager entity and who owns the cars themselves depends on how you want to structure the game. For a competitive game with a server (we call them Simulators), it would be the server who does that, spawns the cars and retain authority on them.

For a more relaxed distributed-authority game, you could have one of the clients do this. The first one to connect also becomes the car-spawner. So they spawn cars, and then pass authority on those cars to the player who just joined. Imagine:

  1. Client 1 joins. They take authority on the CarSpawner network entity.
  2. Client 1 spawns a car for themselves at position 0.
  3. Client 2 joins. Client 1 gets notified of that (using Client Connections) and creates a car for Client 2 at position 1, then moves the authority on that car to Client 2.
  4. Repeat
  5. Start the match

So as you can see, it’s not a pre-made solution, but also quite easy to imagine and implement. But let us know if you get stuck on some step.

How does it sound?

Amazing i hadn’t thought of it like that, but i don’t know how to do it, and infact, i know little bit only about coherence yet, and that is: Coherence Lobby and Coherence Sync, so i need help in how to set it up.

Here is how i configure it:
first the scene loads up with a Carselection, where the user can select a car.
then click start, after that they come into a race scene where they have the option to make a room or join one, and then anyone can join it further causing cars to collide in each other causing cars to fly and become upside-down.

So i need help since i just started using coherence a few days back.
Anyway Thanks for the idea, but please reply for a solution

Don’t use lobbies for now. Just use Rooms directly. There’s a sample UI included in the package that makes connection trivial.
You can worry about lobbies later, once you’ve understood coherence more.

For the spawner, look into our Package samples. They are included in the Unity package (so in Package Manager). There’s one scene about spawning.

Also look at the First Steps demo. By reading through its docs it’s gonna make things easier.

hmm, so let me a send a rec of how it looks in the game scene

so still i can’t understand how to work it out

The problem is with the different location spawning like you mentioned earlier in the 1st reply, and that is my problem, so can you list like steps for me to follow?

Sorry I don’t understand exactly what’s going on from the video, except that I can see you can connect.

Have you checked the Package sample that I suggested?

In the video i changed it from lobby to room creating and joining​:slightly_smiling_face::slightly_smiling_face:
and that’s what i wanted to show you.

here is what i did and couldn’t find it:


i checked the package sample and above is the video, Maximize it

You have it there, in the video: Sample Scenes.

The first sample is it??

No it’s like, 3rd or 4th… (I can’t check, I’m from my phone). If you open all the scenes it’s going to be clear which one is it.

Sorry, double checked now: it’s scene n.7, called 7_PlayerSpawner
Check the script GameManager.cs that instantiates PlayerSpawner.cs.

(as a side note, they could probably be made into one script, so don’t think too much about the fact that they are two)

hmm, let me check this thing out then, it is example 7?
The “Steam one?”.

Sorry for the late reply(was travelling).

No, it’s Sample Scenes. Then you open scene n.7, called 7_PlayerSpawner

So scene example 1 and in it is 7_playerspawner?

Yes, that’s the one :slightly_smiling_face:

I will check if it works for me and If I get problems then I will ask for help, thanks

1 Like

I am still not able to make this work, i tried to make it’s scene look like my scene, but i have no idea of what to do, since it is not working i would like a step by step.
i could show how i setup my scene, but please give me a step by step guide

Sorry to hear that.

Generally speaking, the step by step was the one I posted above:

  1. Client 1 joins. They take authority on the CarSpawner network entity.
  2. Client 1 spawns a car for themselves at position 0.
  3. Client 2 joins. Client 1 gets notified of that (using Client Connections) and creates a car for Client 2 at position 1, then moves the authority on that car to Client 2.
  4. Repeat
  5. Start the match

Is there a particular step where you get stuck?