Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 MKFusion · May 07 at 11:19 AM · collisiontriggerdetectiondots

How to implement ECS trigger collisions? (Unity.Physics 0.50)


How could I set a simple ECS collision detection in Unity DOTS, on trigger.


I haven't seen any decent documentation about it and I haven't found any tutorials with Entities 0.50. I have Raise Trigger Events selected in Physics Shape, but from there I don't know what to add / implement it in SystemBase ?


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andrew-lukasik · May 09 at 11:54 AM

I haven't seen any decent documentation about it and I haven't found any tutorials with ECS 0.50


It's all here: https://github.com/Unity-Technologies/EntityComponentSystemSamples

(.../triggers)


I suggest downloading the whole repo as there are quite a few interesting samples in there.


TriggerWarningAuthoring.cs:

 using Unity.Collections;
 using Unity.Entities;
 using Unity.Jobs;
 using Unity.Physics;
 using Unity.Physics.Systems;
 using UnityEngine;
 
 public class TriggerWarningAuthoring : MonoBehaviour, IConvertGameObjectToEntity
 {
     [SerializeField] string _message = "How dare you!";
     void IConvertGameObjectToEntity.Convert ( Entity e , EntityManager dst , GameObjectConversionSystem cs )
     {
         if( !enabled ) return;
 
         dst.AddComponentData( e , new TriggerWarning{
             Message = _message
         } );
     }
 }
 
 public struct TriggerWarning : IComponentData
 {
     public FixedString4096Bytes Message;
 }
 
 [Unity.Burst.BurstCompile]
 struct TriggerWarningJob : ITriggerEventsJob
 {
     [ReadOnly] public ComponentDataFromEntity<TriggerWarning> TriggerWarningData;
     public void Execute ( TriggerEvent evt )
     {
         Entity A = evt.EntityA;
         Entity B = evt.EntityB;
 
         if( TriggerWarningData.HasComponent(A) )
             Debug.Log($"a message: {TriggerWarningData[A].Message}");
         
         if( TriggerWarningData.HasComponent(B) );
             Debug.Log($"a message: {TriggerWarningData[B].Message}");
     }
 }
 
 [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
 [UpdateAfter(typeof(ExportPhysicsWorld))]
 [UpdateBefore(typeof(EndFramePhysicsSystem))]
 public partial class TwitterSimulationSystem : SystemBase
 {
     StepPhysicsWorld _stepPhysicsWorldSystem;
     protected override void OnCreate ()
     {
         _stepPhysicsWorldSystem = World.GetOrCreateSystem<StepPhysicsWorld>();
 
         RequireForUpdate( GetEntityQuery( new EntityQueryDesc{
             All = new ComponentType[]{ typeof(TriggerWarning) }
         } ) );
     }
     protected override void OnStartRunning()
     {
         base.OnStartRunning();
         this.RegisterPhysicsRuntimeSystemReadOnly();
     }
     protected override void OnUpdate ()
     {
         var job = new TriggerWarningJob
         {
             TriggerWarningData = GetComponentDataFromEntity<TriggerWarning>( isReadOnly:true ) ,
         };
         Dependency = job.Schedule( _stepPhysicsWorldSystem.Simulation , Dependency );
     }
 }


Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

220 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

Related Questions

Full Performance On Melee Combat 0 Answers

Detect when a trigger has entered a collider 1 Answer

Trigger Collision Detection 1 Answer

Particles colliding/triggering Particles. Is it possible? 2 Answers

Adds too many points to the score? 0 Answers


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