# Index Based Spawning

**URL:** <https://community.coherence.io/t/index-based-spawning/603>\
**Category:** Help\
**Created:** [October 31, 2024, 2:03pm UTC](https://community.coherence.io/t/index-based-spawning/603 "2024-10-31T14:03:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [October 31, 2024, 2:03pm UTC](https://community.coherence.io/t/index-based-spawning/603/1 "2024-10-31T14:03:51Z")

</div>

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 😞😞  
I thought coherence making multiplayer so simple, can’t do that??

I need HELP!!!

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [October 31, 2024, 3:41pm UTC](https://community.coherence.io/t/index-based-spawning/603/2 "2024-10-31T15:41:47Z")

</div>

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?

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/274b06c9d3dea24f6edbe9c5972581bec287f80a.jpeg)

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](https://docs.coherence.io/manual/simulation-server)), 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](https://docs.coherence.io/manual/client-connections)) and creates a car for Client 2 at position 1, then [moves the authority on that car](https://unityapi.coherence.io/docs/v1.3.1/api/Coherence.Toolkit.CoherenceSync.TransferAuthority.html#Coherence_Toolkit_CoherenceSync_TransferAuthority_Coherence_Connection_ClientID_Coherence_AuthorityType_) 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?

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 2, 2024, 6:30am UTC](https://community.coherence.io/t/index-based-spawning/603/3 "2024-11-02T06:30:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 2, 2024, 9:57am UTC](https://community.coherence.io/t/index-based-spawning/603/4 "2024-11-02T09:57:12Z")

</div>

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](https://docs.coherence.io/getting-started/samples-and-tutorials/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](https://docs.coherence.io/getting-started/samples-and-tutorials/first-steps-tutorial) demo. By reading through its docs it’s gonna make things easier.

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 2, 2024, 9:58am UTC](https://community.coherence.io/t/index-based-spawning/603/5 "2024-11-02T09:58:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 2, 2024, 10:00am UTC](https://community.coherence.io/t/index-based-spawning/603/6 "2024-11-02T10:00:51Z")

</div>



---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 2, 2024, 10:04am UTC](https://community.coherence.io/t/index-based-spawning/603/7 "2024-11-02T10:04:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 2, 2024, 11:40am UTC](https://community.coherence.io/t/index-based-spawning/603/8 "2024-11-02T11:40:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 2, 2024, 2:00pm UTC](https://community.coherence.io/t/index-based-spawning/603/9 "2024-11-02T14:00:11Z")

</div>

In the video i changed it from lobby to room creating and joining​🙂🙂  
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

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 2, 2024, 3:29pm UTC](https://community.coherence.io/t/index-based-spawning/603/10 "2024-11-02T15:29:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 3, 2024, 12:16pm UTC](https://community.coherence.io/t/index-based-spawning/603/11 "2024-11-03T12:16:41Z")

</div>

The first sample is it??

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 3, 2024, 9:29pm UTC](https://community.coherence.io/t/index-based-spawning/603/12 "2024-11-03T21:29:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 4, 2024, 9:15am UTC](https://community.coherence.io/t/index-based-spawning/603/13 "2024-11-04T09:15:17Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 4, 2024, 3:24pm UTC](https://community.coherence.io/t/index-based-spawning/603/14 "2024-11-04T15:24:26Z")

</div>

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

Sorry for the late reply(was travelling).

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 5, 2024, 2:36pm UTC](https://community.coherence.io/t/index-based-spawning/603/15 "2024-11-05T14:36:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 7, 2024, 3:55am UTC](https://community.coherence.io/t/index-based-spawning/603/16 "2024-11-07T03:55:57Z")

</div>

So scene example 1 and in it is 7\_playerspawner?

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 7, 2024, 8:56am UTC](https://community.coherence.io/t/index-based-spawning/603/17 "2024-11-07T08:56:03Z")

</div>

Yes, that’s the one 🙂

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 9, 2024, 4:33am UTC](https://community.coherence.io/t/index-based-spawning/603/18 "2024-11-09T04:33:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 14, 2024, 5:47am UTC](https://community.coherence.io/t/index-based-spawning/603/19 "2024-11-14T05:47:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 14, 2024, 9:36am UTC](https://community.coherence.io/t/index-based-spawning/603/20 "2024-11-14T09:36:15Z")

</div>

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](https://docs.coherence.io/manual/client-connections)) and creates a car for Client 2 at position 1, then [moves the authority on that car](https://unityapi.coherence.io/docs/v1.3.1/api/Coherence.Toolkit.CoherenceSync.TransferAuthority.html#Coherence_Toolkit_CoherenceSync_TransferAuthority_Coherence_Connection_ClientID_Coherence_AuthorityType_) to Client 2.
> 4. Repeat
> 5. Start the match

Is there a particular step where you get stuck?

[Next page](https://community.coherence.io/t/index-based-spawning/603.md?page=2)
