Search Unity

Question How to absent "PhysicsVelocity"? just like the manual says...

Discussion in 'Physics for ECS' started by Bob_work, Sep 28, 2022.

  1. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
  2. mattdymott

    mattdymott

    Joined:
    Dec 27, 2016
    Posts:
    29
    EntityManager.RemoveComponent<PhysicsVelocity>(entity);

    or if using EntityCommandBuffer:

    commandBuffer.RemoveComponent<PhysicsVelocity>(entity);


    if you mean in terms of Authoring then don't add a PhysicsBody component on GameObject just use a PhysicsShape component and the authored entity will be static.
     
    Anthiese likes this.
  3. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    Thank you for your reply!

    Actually I need the traditional Rigidbody sleep effect: Rigidbody.Sleep(). When the character leaves an area, those entities no longer need to do physical calculations, thereby freeing up CPU computing resources. Reactivate the rigid body when needed, just like Rigidbody.Weakup().

    If I remove <PhysicsVelocity> in DOTS, and when I need it then add it, just like you wrote : EntityManager.AddComponent<PhysicsVelocity>(entity).

    But I remember that this kind of operation of add/remove components belongs to "structural change". It seems that it can only be performed in the mainthread, right? It seems that it cannot be executed in the general SystemBase:OnUpdate(). I will try more, such as ForEach(), IJobxxx, ECB, etc.
     
  4. mattdymott

    mattdymott

    Joined:
    Dec 27, 2016
    Posts:
    29
    You can use an EntityCommandBuffer to Add/Remove in a job which is not on the main thread, but yeah eventually it will be called at a sync point on the main thread. I don't think Unity.Physics has a sleep method in place.
     
  5. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    Yeah, with the deepening of use, more and more found the imperfection of DOTS.