Search Unity

Resolved PredictedPhysicsValidationSystem make an error debug

Discussion in 'NetCode for ECS' started by hxhloveunity, May 29, 2023.

  1. hxhloveunity

    hxhloveunity

    Joined:
    May 27, 2022
    Posts:
    34
    if a ghost have a physics chirldren entity,then this system will log error message:
    The default physics world on the client contains a dynamic physics object which is not a ghost. This is not supported, in order to have client-only physics you must setup a custom physics world for it.

    because a ghost children entity only including the 'GhostChildEntity' component but not the 'GhostInstance' component.
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    Thanks for the report hxh, please file it as a Unity bug report for tracking purposes (and link back to this thread).
     
  3. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    895
    The error is actually correct. We don't support that by default right now. PhysicsVelocity is not replicated for child entities (this is the current default setup). Nor their transform or other components (again this is the default).
    So if you are using this pattern, be aware that the child entity state may be not synched to the client, unless you modify the variant to use for this child entity.

    Also worth noticing: Physics objects are kinda special in general. Even if they are child in a hierarchy or prefab, they are disconnected by that hierarchy at runtime. They have no parent, and they are always root objects (in terms of transform).
    Transform is in fact not synched either, you need to have joint or do that manually in case you need.

    That being said, it you setup the replication for that child, so it work as expected, and that error is annoying or blocking you, it can be easily removed by changing the query builder at line 169 in PredictedPhysicsSystemGroup.cs

    Code (csharp):
    1.  
    2. var builder = new EntityQueryBuilder(Allocator.Temp)
    3. .WithAll<PhysicsVelocity, PhysicsWorldIndex>()
    4. .WithAbsent<GhostInstance, GhostChildEntity>();
    5.  
    However, this is the fundamental fact, changing this check, without having another way to verify that the behaviour and replication configuration of the child ghost entity has been setup correctly can lead to errors or replication issue that at first glance may be harder to understand.

    NOTE 2: The NetcodePhysicsRateManager requires that at least one physic entity with a PredictedGhostComponent exist at the moment. While that may be not a problem (you have other root ghosts with physics), in general, with child, that may be not sufficient to make replicated physics run.
     
  4. hxhloveunity

    hxhloveunity

    Joined:
    May 27, 2022
    Posts:
    34
    how to setup the replication for children? have some sample?
     
  5. hugeandy

    hugeandy

    Joined:
    Nov 2, 2016
    Posts:
    131
    @CMarastoni also coming across this problem with "nested" physics bodies. Our hierarchy is:

    GhostPrefabRoot
    -Body
    -InnerBody1
    -InnerBody2
    -InnerBody3
    -InnerBody4

    The 4 inner bodies are connected to Body using joints. We have a Ghost Authoring Component on GhostPrefabRoot. We get the exact same error as reported in the initial message (The default physics world on the client contains a dynamic physics object which is not a ghost. This is not supported, in order to have client-only physics you must setup a custom physics world for it.)

    With the knowledge that the entities with PhysicsBodies are "unparented", I tried adding Ghost Authoring Components to each of them, however they are un-interactable in the inspector.

    Please could you explain exactly how to make this situation work as expected?

    Cheers!
    Andy