# Simulator Connection Issues & LiveQuery

**URL:** <https://community.coherence.io/t/simulator-connection-issues-livequery/304>\
**Category:** Help\
**Created:** [June 22, 2023, 11:53am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304 "2023-06-22T11:53:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 22, 2023, 11:53am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/1 "2023-06-22T11:53:27Z")

</div>

Hello, I’ve been messing around with getting simulator and server authoritative npcs working for a while now.

I’ve managed to get the simulator to connect only during local testing in the editor. (not with running a local simulator, nor uploading a cloud build). What I found success with is: Changing the editor project settings to COHERENCE\_SIMULATOR, and then manually connecting via script which connects to local 127.0.0.1 and world id 123.

When I did that it worked as expected.

Problem 1: I ran into an issue with LiveQuery. I put one on my player object which simulates in Server + Client input. and that worked great. But if I also put a LiveQuery on an object that the simulator spawns(that spawned object simulates in just Server…), as soon as the player object gets into range, the client controlling it loses input and cannot be controlled anymore.

Problem 2: If I remove the code that manually connects the simulator and instead use the Auto Simulator Connect component, nothing seems to work. Not on local and not on cloud.  
My process is to coherence hub \> Simulators \> build and upload headless linux client. Then change the server to use the new simulator slug and save/restart.  
I also tried local simulator build.

I’ll also add that i’m just modifying the demo scene for AreasOfInterest while testing this stuff.

---

<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:** [June 22, 2023, 2:07pm UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/2 "2023-06-22T14:07:30Z")

</div>

Hi Travis! And I’ll assume you are “clonze” on Discord, right?

> [@Travis\_Miller](#):
>
> Problem 1: I ran into an issue with LiveQuery. I put one on my player object which simulates in Server + Client input. and that worked great. But if I also put a LiveQuery on an object that the simulator spawns(that spawned object simulates in just Server…), as soon as the player object gets into range, the client controlling it loses input and cannot be controlled anymore.

As Miguel replied, you might have stumbled into a bug present on pre `1.0` versions affecting LiveQueries parented to other objects. It will be fixed for `1.0`, as we definitely intend to support that use case.  
For now I would suggest to leave the LiveQuery component on the root of the Player prefab - so you circumvent any issue.  
(again, for now)

I would also suggest to set these `CoherenceLiveQuery` components to disable when you don’t have or lose authority on the player. You can use the so-called “Component Actions” to do it all automatically. They are briefly explained [on this page](https://docs.coherence.io/get-started/prefab-setup#6.-disable-input-on-replicated-object), and also [in the first lesson](https://docs.coherence.io/learning-coherence/first-steps-tutorial/1-basic-syncing#how-its-set-up) of our tutorial project.

---

<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:** [June 22, 2023, 2:16pm UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/3 "2023-06-22T14:16:16Z")

</div>

> [@Travis\_Miller](#):
>
> Problem 2: If I remove the code that manually connects the simulator and instead use the Auto Simulator Connect component, nothing seems to work. Not on local and not on cloud.  
> My process is to coherence hub \> Simulators \> build and upload headless linux client. Then change the server to use the new simulator slug and save/restart.  
> I also tried local simulator build.

For this one, I would say, can you share the Logs of the Simulator? I usually get them from the World interface, but there should be some also for Rooms. This way we can see what’s happening when the Simulator tries to connect, and fails.

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 3:50am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/4 "2023-06-23T03:50:55Z")

</div>

I’m running a world simulator, not using rooms at the moment.  
Not sure if i’m getting the correct logs here, this is off of the cloud upload. The logs just look like a bunch of shader warnings for headless build or something…

Simulator logs:

> **[SIMULATOR - Pastebin.com](https://pastebin.com/hqaYcABj)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Replicator logs:

> **[REPLICATOR - Pastebin.com](https://pastebin.com/semsWYXp)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 4:32am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/5 "2023-06-23T04:32:36Z")

</div>

I’m a little bit confused because the LiveQuery components do not show up as a component that I can disable with component actions:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/8f9df212a55e8a946123410459f611e4b585c764.png)  
Also I noticed when the player moves into the simulator server object’s live query radius, it despawns my player and respawns it as a [networked] [local] named object rather than just a [local]. Thats when I lose control and can only visually rotate the character with input keys. The simulator also can adjust the visual rotation of the object, but neither can actually move it.  
[![](https://i.imgur.com/ovIkcou.gif) ](https://i.imgur.com/ovIkcou.gif)

Sorry if I’m not understanding something and wasting your time explaining this to me.

---

<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:** [June 23, 2023, 7:47am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/6 "2023-06-23T07:47:26Z")

</div>

> [@Travis\_Miller](#):
>
> Sorry if I’m not understanding something and wasting your time explaining this to me.

It’s perfectly fine! I am happy to try and help 🙂

> [@Travis\_Miller](#):
>
> The logs just look like a bunch of shader warnings for headless build or something…

The Simulator logs generally do. Nothing super wrong that I can see, except maybe this line:

`Error response from daemon: network with name cgria0lbo1hvlpoltfhg already exists`

But I don’t know what it means. I have asked our Online team.

On the Replication Server side, I can see that you do have some Simulator successfully connect, but not always. You can notice them if you look in the logs for `IsSimulator: true`, that’s when a Client successfully connected as a Simulator.

---

<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:** [June 23, 2023, 7:58am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/7 "2023-06-23T07:58:37Z")

</div>

> [@Travis\_Miller](#):
>
> I’m a little bit confused because the LiveQuery components do not show up as a component that I can disable with component actions:

Interesting! It’s probably intentional, because the LiveQuery is a bit of a special component from the network point of view. But you can always disable it manually, by hooking into CoherenceSync’s callbacks, like `OnStateRemote` and `OnStateAuthority`. But I also want to clarify one thing:

Before, I suggested you to disable these LiveQueries. But what I meant is, disable them on the Simulator! As in, on the Simulator you want only the LiveQueries that concern the Simulator to be active.  
On a Client, you want only the ones who concern the player to be active, otherwise they can effectively cheat, because they see too much.

To make an example:  
A big world shooter game. Each character prefab has a LiveQuery component parented to it. On spawn, the remote characters disable their LiveQuery. Say we have 2 Clients connected (A and B) and a Simulator (S) driving a bunch of bots.  
You will have:

- Client A: Here we have Player A with an active LiveQuery on them, while Player B and the bots have none.
- Client B: Here we have Player B with an active LiveQuery on them, while Player A and the bots have none.
- The Simulator: from their point of view, Player A and Player B have no LiveQuery, but the bots all have one. This is the case if you want the human Clients to have full authority on their Player characters. For a **server-authoritative setup** , You might as well have a special LiveQuery for the Simulator which is set to radius 0, so they see it all!

So each network node sees only what concerns them, and they never lose sight of their owned players!

Does this clarify it a bit?

So my next question is, were you using them differently? Perhaps disabling the Client’s own LiveQuery? Maybe that’s what was creating the issue?

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 8:50am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/8 "2023-06-23T08:50:21Z")

</div>

> [@ciro](#):
>
> Before, I suggested you to disable these LiveQueries. But what I meant is, disable them on the Simulator! As in, on the Simulator you want only the LiveQueries that concern the Simulator to be active.  
> On a Client, you want only the ones who concern the player to be active, otherwise they can effectively cheat, because they see too much.

Thanks for the response, I’ll go through what you said and try it out.

To answer your question I was not disabling any live queries. I had a server authority object which exists in the scene before runtime. I noticed that the simulator did not see the player object so I thought adding a livequery to the server object is the correct way to fix that.

My goal is to have a server authoritative game. right now i’m working on trying to get enemy NPCs to detect the players on the simulator.

```auto

I'll try to give you a way to reproduce this problem:
1) start with the coherence demo. Load up the scene areasOfInterest in editor.
2) modify the player prefab to be authority: Server + Client Input
3) add input fields to the CoherenceInput component: "Horizontal", "Vertical", "Jump" 
4) add a livequery to the root player object with 10 radius.
4) Create a new object in the scene, add coherence sync
5) Set the new object to be simulated in: "Server"
6) Add a livequery to the root new object with 10 of radius.
7) Load up the world server, start a simulator, start the client, walk the player into the server object and lose control.

I don't think this is working as intended. When I switch the player to be just client side, everything starts working again as it should. So the key thing here is simulator with livequery is rubbing up against Player object that has authority: Server + Client input.
```

---

<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:** [June 23, 2023, 8:57am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/9 "2023-06-23T08:57:28Z")

</div>

> [@Travis\_Miller](#):
>
> To answer your question I was not disabling any live queries. I had a server authority object which exists in the scene before runtime. I noticed that the simulator did not see the player object so I thought adding a livequery to the server object is the correct way to fix that.

Ah yes, one gotcha: previously I described the setup for a client-side authorship. If you want the gameplay to be server-driven, then you need the Simulator to see all the Player’s entities at all times. As such, I suggest having a special LiveQuery on the Simulator set to radius 0 (infinite).

I have edited my above reply for clarity, so it doesn’t confuse others!

Thanks for the detailed steps, I’ll try them out!

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 9:04am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/10 "2023-06-23T09:04:36Z")

</div>

Okay, thanks again for being so responsive!

I thought there would be some performance gain for the simulator if it didn’t see every player but I suppose that probably doesn’t matter, and it makes sense that all the players actions need to be simulated anyhow.

---

<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:** [June 23, 2023, 9:09am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/11 "2023-06-23T09:09:44Z")

</div>

> [@Travis\_Miller](#):
>
> I thought there would be some performance gain for the simulator if it didn’t see every player

There is, because the Simulator is nothing else than another Unity build with no graphics. And framerate is not guaranteed. So the less it sees, the less it has to process.

But if it has to **drive** the gameplay… well then it needs to see what it’s doing!

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 10:26am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/12 "2023-06-23T10:26:46Z")

</div>

Okay, so now i’ve tried with your suggestions.

1. setting 0 radius on the simulator livequery.
2. using awake to hook into OnStateAuthority for player objects and disabling the livequery
3. using awake to hook into OnStateAuthority for the simulator server object to disable the livequery for clients.

I’ve also tried both having the livequery for players as a child object of the root object and also just having the livequery component on the root object itself. both cases gave same results.

With the new 0 radius setting, the player objects now immediately lose control.

Please let me know if you’ve tried it yourself and found it to be working.

![](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/6b409c0cac1cc95a2de7520218e2adbe5755ff11.png)

---

<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:** [June 23, 2023, 11:20am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/13 "2023-06-23T11:20:42Z")

</div>

Quick question: do you have the correct scene in the Simulator Build Options, within the Simulators tab of the coherence Hub?

 ![Screenshot 2023-06-23 alle 13.20.20](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/65e1a0ce9768823a30a00a2c132eea0f751078df.png)

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 11:22am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/14 "2023-06-23T11:22:40Z")

</div>

yes i do

 ![](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/437e96d7476fc01e82ff40ac2cd376987bf4bb47.png)

---

<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:** [June 23, 2023, 11:24am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/15 "2023-06-23T11:24:13Z")

</div>

Ok cool.  
I’m testing in the project, following the exact steps you detailed. Will come back soon 🙂

---

<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:** [June 23, 2023, 11:45am UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/16 "2023-06-23T11:45:20Z")

</div>

Ok, so, I think what you are seeing is according to norm. I’ll explain, starting from what I think is the mistake:

I presume you think that the `CoherenceInput` script will automatically apply your input based on those 3 fields (“Horizontal”, “Vertical”, “Jump”), but that is not the case.  
You can read more about it here: [Server-authoritative setup - Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/coherence-sdk-for-unity/authority-overview/input-queues#using-coherenceinput)

What is happening then, is this:

- When you start the game, the Player character - which is supposed to be driven by the server - is actually outside of the Simulator’s LiveQuery. As such, the Simulator doesn’t know about it, and the Player retains full control.  
You can verify this in the `CoherenceSync`:  

- When you walk into the Simulator’s LiveQuery, the Simulator goes: “hey, that’s mine!” and takes control of the player’s state. You can see that the `CoherenceSync` reflects this:  

- The reason why you can’t walk anymore is because, as soon as you lose authority, both `PlayerInput` and `Move` are disabled, as configured in the coherence Config window, third tab (Components):  

What you really need to do is to familiarise yourself with [CoherenceInput](https://docs.coherence.io/coherence-sdk-for-unity/authority-overview/input-queues#using-coherenceinput), and modify the whole setup accordingly.

This probably means removing my `PlayerInput` script altogether or disabling it when player becomes remote, but keeping the `Move` script active so you can pass to it - on the Simulator - the inputs that the Sim receives through the network.

Hope it helps.

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 12:53pm UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/17 "2023-06-23T12:53:03Z")

</div>

> [@ciro](#):
>
> hen you start the game, the Player character - which is supposed to be driven by the server - is actually outside of the Simulator’s LiveQuery. As such, the Simulator doesn’t know abou

Thank you. Sorry about that… I was assuming it was working before 🥶 This makes much more sense now, before I thought it was pure magic… no delay on server authoritative? yup I can feel it now! Now I gotta see if I can smooth it out and if it’s worth putting effort into this for anti cheating.

I also had to mark the rigidbody to leave as it for no authority action for anyone else stumbling across this.

---

<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:** [June 23, 2023, 1:01pm UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/18 "2023-06-23T13:01:05Z")

</div>

> [@Travis\_Miller](#):
>
> I also had to mark the rigidbody to leave as it for no authority action for anyone else stumbling across this.

If you want to do prediction locally, you could. But wouldn’t it make more sense to still have it as kinematic on the Client, given that if any physics event happens, they will be detected on the Simulator?

---

<div class="post-metadata">

**Author:** ![Travis\_Miller](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/travis_miller/32/246_2.png) [@Travis\_Miller](https://community.coherence.io/u/Travis_Miller)\
**Post date:** [June 23, 2023, 1:03pm UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/19 "2023-06-23T13:03:24Z")

</div>

Yes, well I just meant that after the initial spawn, the simulation’s version of the rigidbody gets marked as kinematic with the default settings, so that was causing movement not to occur.

---

<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:** [June 23, 2023, 2:46pm UTC](https://community.coherence.io/t/simulator-connection-issues-livequery/304/20 "2023-06-23T14:46:05Z")

</div>

Ah, right, of course!  
Yeah I think for your setup you might want to not use the Config window, which is intended for simple use cases and for people who can’t put their hands into code.

Keep in mind that you can also handle variables and commands in code: [[Sync] and [Command] Attributes - Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/coherence-sdk-for-unity/networking-state-changes/sync-and-command-attributes)
