Help with Coherence sync prefab ( player ) not syncing variables from Simulator to non-authority

I feel like I must be missing something simple because this is working for a client connecting to the Simulator.

The client connecting has a child object that is getting a rotation value based on coherence input.

This client has Input Authority, and State Authority on the Simulator.

On the Simulator:
image

And setup like:


Which shows the connected client child object, it’s setup for sync ( set to sync rotation ), and Rotation values in the inspector.

I connected a second client w/ the Unity Editor to the same Simulator to be able to view/inspect the other connected clients.
The same connected client w/ no authority ( what other clients would see ):
image

And viewing the setup in the inspector:


Viewing the same child object, showing that it has rotation sync, but has no Rotation values.

Shouldn’t the values from the Simulator be synced to non-authority network objects as well? I found another answer post, and the suggestion was to turn off interpolation. I tried both default & none, but it was the same.

Hey Marvin.

Before I go into the post (haven’t even read it fully), I want to clarify one thing. You don’t connect Clients to Simulators. You could imagine Simulator and Clients on the same conceptual level: they are all Unity builds connecting to the Replication Server (RS).
Just wanted to mention it in case it was unclear.

From the images I can’t tell much. But my hunch tells me that probably, on both instances of the editor you have the input script running, which is forcing that object to be rotated in a certain way. So even if in the second screenshot you should be using the rotation that is coming from the network (because the object is remote), you might be forcing it to a certain value every frame, so you never see it update.

To resolve this, make sure that the input for remote objects is not active. That your script(s) are not modifying values that they shouldn’t.

We have a quick way to do this using the Components part of the Configuration panel (the one shown in the images). This behaviour is described on this page, specifically at this section: Prefab Setup: CoherenceSync - Unity Multiplayer SDK Documentation | coherence
Give it a read :slight_smile:

I would also suggest reading through at least the first 3 sections of this tutorial: First Steps tutorial - Unity Multiplayer SDK Documentation | coherence
Even if you don’t download the project, it’s probably going to guide you on the right path to understanding how to setup prefabs for syncing.

Let us know how it goes!

I understand the client is connecting to the RS first, and the Simulator is just taking taking State Authority based on the client being set for Server side w/ client input.

I don’t believe this is the case, because I’m disabling it for non-authoritative network objects. Here is the config:

I was only mentioning the SECOND CLIENT in the Editor to illustrate that I would be able to inspect the values of the FIRST CLIENT connecting. This gives me the ability to view the network object in a non-authoritative state.

I have scoured the documentation, and I do have the projects downloaded to refer back to for runtime & code examples.

Hmm. The setup seems correct from what I can see.

Are you using Unity’s Third Person controller from Starter Assets? With no modifications? Maybe I can create a reproduction case and make it work, and share it.

That is the base of setup, but it is heavily modified at this point for my use case. It has been tailored to work with Coherence.

After some investigation, I spotted something in the project that might be the cause for issues. I want to post it too, in case.

While this setup is correct:

I found out that Marvin also syncs the enabled property of those scripts. This can lead to undesirable results.

What we usually want is that input-reading scripts work on the client that has authority. If the prefab is spawned on another client, we want that script to disable (which is what the Components tab does for you).
But if we sync the enabled property, the script will be turned back on because - hey the Client with authority has it enabled, so it needs to be enabled everywhere!

So turning the syncing of those properties off should be a first step to see if it solves the de-sync.

Let me know how it goes, Marvin!

I’ve done some testing, and I rely on those scripts being enabled because they process logic on the State Authority ( Simulator ), as well as the Input Authority ( Client ).

So it seems I need to add logic for non-authority objects. Or maybe it would help to break out the scripts into enabled everywhere, and only enabled on State Authority. I’m doing some of that with:

if (SimulatorUtility.IsSimulator)
{
}

You give examples for checking Authority:

public void Update()
{
    if (coherenceSync.HasStateAuthority || coherenceSync.HasInputAuthority)
    {
        ProcessMousePosition();
    }

    if (coherenceSync.HasInputAuthority)
    {
        SendMousePosition();
    }
}

I see.

Yes, sometimes it can also make sense to break things into multiple scripts and leave some of them enabled, while disabling others.

Or, you can do what you did here, if breaking the logic apart is too complex or would lead to a lot of data duplication!

If you don’t mind, I’ve marked my reply that seems to contain the key info as the solution, so someone that might be searching for similar keywords can find it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.