Search Unity

Resolved NetCode: IGhostDefaultOverridesModifier doesn't seem to work for syncing NonUniformScale

Discussion in 'NetCode for ECS' started by mpcomplete, Oct 16, 2020.

  1. mpcomplete

    mpcomplete

    Joined:
    Feb 20, 2019
    Posts:
    4
    I'm using the method described here[1] to cause Unity.Transforms.NonUniformScale to sync from server to client. The editor appears to register the change (the GhostAuthoringComponent highlights Unity.Transforms.NonUniformScale in bold, and shows the fields to be synced), but the component does not get sent to the client.

    Here's my class that implements IGhostDefaultOverridesModifier (I also have the corresponding assembly definition ending in .NetCodeGen):
    Code (CSharp):
    1.  
    2. public class GhostOverrides : IGhostDefaultOverridesModifier {
    3.   public void Modify(Dictionary<string, GhostAuthoringComponentEditor.GhostComponent> overrides) {
    4.     overrides["Unity.Transforms.NonUniformScale"] = new GhostAuthoringComponentEditor.GhostComponent {
    5.       name = "Unity.Transforms.NonUniformScale",
    6.       attribute = new GhostComponentAttribute { PrefabType = GhostPrefabType.All, OwnerPredictedSendType = GhostSendType.All, SendDataForChildEntity = false },
    7.       fields = new GhostComponentField[] {
    8.         new GhostComponentField {
    9.           name = "Value",
    10.           attribute = new GhostFieldAttribute{Quantization = 100, Interpolate = true}
    11.         }
    12.       },
    13.       entityIndex = 0
    14.     };
    15.   }
    16.  
    17.   public void ModifyAlwaysIncludedAssembly(HashSet<string> alwaysIncludedAssemblies) {
    18.     alwaysIncludedAssemblies.Add("Unity.Transforms.NonUniformScale");
    19.   }
    20.  
    21.   public void ModifyTypeRegistry(TypeRegistry typeRegistry, string netCodeGenAssemblyPath) {
    22.   }
    23. }
    24.  
    And attached is what it looks like in the editor before and after implementing this class. As you can see, the editor appears to indicate that the values will be synced, but the NonUniformScale component appears on the entity only on the server, and not on the client.

    What am I doing wrong?

    [1] https://docs.unity3d.com/Packages/com.unity.netcode@0.4/manual/ghost-snapshots.html
     

    Attached Files:

  2. mpcomplete

    mpcomplete

    Joined:
    Feb 20, 2019
    Posts:
    4
    I figured out my issue. The base entity prefab had no scaling to start with - only the instances were scaled. So the prefab didn't have a NonUniformScale component. I guess Unity only syncs components that are present in the prefab, even if the instances have additional components.