Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question NetworkVariable replication determinism across components of the same NetworkObject?

Discussion in 'Netcode for GameObjects' started by UnkelRambo, Dec 15, 2022.

  1. UnkelRambo


    Oct 26, 2012

    I'm curious if I can rely on two network variables being delivered to clients in the same "update"? If they're part of the same NetworkBehaviour or not?

    Here's my situation:

    I'm working on adding Join-In-Progress handling to my ability system (built on the TPL.) How this works is:
    1. The owning client/host uses an ability, starts a predicted version of the ability, and fires a Server RPC requesting its use.
    2. The Server RPC responds by creating a replicated ActiveAbilityState object in the AbilitySystemComponent network behaviour.
    3. Remote clients are notified of an ability being used when they receive the replicated ActiveAbilityState object, where they run the ability.

    Timing is adjusted properly for each scenario here.

    In one of my (more complex) abilities, I set a replicated variable in ANOTHER NetworkBehaviour (called 'carriedObject') on the same NetworkObject and on the same frame the ActiveAbilityState is created on the server.

    So my question is this:
    During Step 2 above, when the server creates the ActiveAbilityState, runs the ability, and sets 'carriedObject' in the same frame for the NetworkObject using the ability, can I rely on Step 3 having an up-to-date replicated 'carriedObject' on the same frame it gets the replicated ActiveAbilityState (thus firing the ability?)

    In other words, if I have two NetworkBehaviours A and B, can I rely on this to be true:

    A.Foo = X;
    B.Bar = Y;

    Client (on receiving notification that A.Foo changed)
    A.Foo == X
    B.Bar == Y

    This was always a problem with Unreal, where component replication resolution order is non-deterministic, so I'm used to working around it. Still, I'm curious if replicated object updates happen per NetworkObject or per NetworkBehaviour?

    I'll investigate a bit myself but I'm in the middle of a pretty massive refactor and I'm hoping for a quick answer, if anybody knows of course :)

  2. CodeSmile


    Apr 10, 2014