• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by bodhizafa · Nov 20, 2020 at 02:09 AM · physicsdots

DOTS trigger event is firing twice?

I'm trying to create a simple system that will delete any entity that comes in contact with an entity that has the "bounds" tag using current ECS best practices in unity 2020.2.0b12, and it seems that the entities are not being deleted until an update after the first trigger, leading the trigger to happen twice when it should only happen once.

It does work as intended (the entity is deleted), but I'm confused as to why I'm seeing two collisions rather than just one. I created an empty project, installed com.unity.physics and com.unity.rendering.hybrid and enabled the V2 hybrid renderer. There are 2 scripts, BoundsTag.cs:

 [Serializable]
 [GenerateAuthoringComponent]
 public struct BoundsTag : IComponentData
 { }

BoundsSystem.cs:

 [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
 public class BoundsSystem : SystemBase
 {
     struct BoundsSystemJob : ITriggerEventsJob
     {
         [ReadOnly] public ComponentDataFromEntity<BoundsTag> allBounds;
         public EntityCommandBuffer entityCommandBuffer;
         public void Execute(TriggerEvent triggerEvent)
         {
             var outOfBoundsEnt = allBounds.HasComponent(triggerEvent.EntityA) ? triggerEvent.EntityB : triggerEvent.EntityA;
             entityCommandBuffer.DestroyEntity(outOfBoundsEnt);
             Debug.LogFormat("Poof! {0} {1} {2} {3} {4} {5} {6}", outOfBoundsEnt, triggerEvent.EntityA, triggerEvent.EntityB, triggerEvent.ColliderKeyA, triggerEvent.ColliderKeyB, triggerEvent.BodyIndexA, triggerEvent.BodyIndexB);
         }
     }
     protected override void OnUpdate()
     {
         Debug.LogFormat("Update");
         var job = new BoundsSystemJob();
         var cbs = World.GetOrCreateSystem<EndFixedStepSimulationEntityCommandBufferSystem>();
         job.allBounds = GetComponentDataFromEntity<BoundsTag>(true);
         job.entityCommandBuffer = cbs.CreateCommandBuffer();
         this.Dependency = job.Schedule(World.GetOrCreateSystem<StepPhysicsWorld>().Simulation, ref World.GetOrCreateSystem<BuildPhysicsWorld>().PhysicsWorld, this.Dependency);
         cbs.AddJobHandleForProducer(this.Dependency);
     }
 }

The large cube has BoundsTag, Physics Shape (with Collision response set to Raise Triggers), and ConvertToEntity, the ball has Physics Shape, Physics Body, and ConvertToEntity (but not BoundsTag). I'd expect it to fall into the cube, emit one instance of the 'Poof!' log message, and then disappear. It does fall into the cube and disappear, but the Poof! message happens twice. The output is:

 Update
 Update
 ...
 Poof! Entity(1:1) Entity(1:1) Entity(0:1) ColliderKey { Value = 4294967295 } ColliderKey { Value = 4294967295 } 0 1
 Update
 Poof! Entity(1:1) Entity(1:1) Entity(0:1) ColliderKey { Value = 4294967295 } ColliderKey { Value = 4294967295 } 0 1
 Update
 ...

it doesn't really matter for this toy example, but it will definitely cause issues when I'm doing more complex logic. If there's a procedure for attaching a project folder to this question, I can do that.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bodhizafa · Nov 20, 2020 at 02:10 AM 0
Share

I've tried a few variants of the UpdateInGroup clause (including not having it at all) and different CommandBufferSystems, but nothing seems to change.

avatar image andrew-lukasik bodhizafa · Nov 20, 2020 at 01:17 PM 0
Share

Did calling this.Dependency.Complete(); before scheduling a new job changed anything?

avatar image bodhizafa andrew-lukasik · Nov 20, 2020 at 10:22 PM 0
Share

Nope. Neither did calling it before returning, or both.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

228 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you detect collisions in DOTS Physics? 0 Answers

Unity.Physics Pure ECS/DOTS Implementation Causes Transforms.Translation to error into NaN 2 Answers

[ECS] How to dynamically update body friction 1 Answer

Entities.Foreach.Run causes Invalid IL code 0 Answers

Must include HavokSimulation:SyncJob as a dependency 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges