Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 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 pastersteli · Aug 04, 2021 at 04:41 PM · physicsdestroycollidedots

Entity System Collider And Destroy

Whats wrong with this code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Unity.Entities;
 using Unity.Jobs;
 using Unity.Mathematics;
 using Unity.Physics;
 using Unity.Physics.Systems;
 
 public class CollideAndDestroyController : JobComponentSystem
 {
     private BuildPhysicsWorld buildPhysicsWorld;
     private StepPhysicsWorld stepPhysicsWorld;
 
     private struct DestroyJob : ITriggerEventsJob
     {
 
         public ComponentDataFromEntity<CollideAndDestroy> collideAndDestroyGroup;
         public ComponentDataFromEntity<BallFollowData> ballFollowGroup;
         private EntityCommandBuffer.ParallelWriter commandBuffer; 
         public void Execute(TriggerEvent triggerEvent)
         {
             if (collideAndDestroyGroup.HasComponent(triggerEvent.EntityA))
             {
                 if (ballFollowGroup.HasComponent(triggerEvent.EntityB))
                 {
                      commandBuffer.DestroyEntity(triggerEvent.EntityB.Index,triggerEvent.EntityB);
                 }
             }
 
 
         }
     }
 
     protected override JobHandle OnUpdate(JobHandle inputDeps)
     {
         var destroyJob = new DestroyJob
         {
             collideAndDestroyGroup = GetComponentDataFromEntity<CollideAndDestroy>(),
             ballFollowGroup = GetComponentDataFromEntity<BallFollowData>()
 
 
         };
         return destroyJob.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, inputDeps);
     }
 }    
 

error: NullReferenceException: Object reference not set to an instance of an object CollideAndDestroyController.OnUpdate (Unity.Jobs.JobHandle inputDeps) (at Assets/Scripts/Systems/CollideAndDestroyController.cs:44)

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 · Aug 04, 2021 at 07:28 PM


com.unity.physics 0.50.0-preview.43


 using System.Collections.Generic;
 using UnityEngine;
 using Unity.Entities;
 using Unity.Jobs;
 using Unity.Collections;
 using Unity.Mathematics;
 using Unity.Physics;
 using Unity.Physics.Systems;
 using BurstCompile = Unity.Burst.BurstCompileAttribute;
 
 [UpdateInGroup( typeof(FixedStepSimulationSystemGroup) )]
 [UpdateAfter( typeof(StepPhysicsWorld) )]
 public partial class CollideAndDestroyController : SystemBase
 {
 
     StepPhysicsWorld _stepPhysicsWorld;
     EntityCommandBufferSystem _commandBufferSystem;
 
     protected override void OnCreate ()
     {
         base.OnCreate();
         _stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
         _commandBufferSystem = World.GetOrCreateSystem<EndFixedStepSimulationEntityCommandBufferSystem>();
     }
 
     protected override void OnStartRunning ()
     {
         base.OnStartRunning();
         this.RegisterPhysicsRuntimeSystemReadOnly();
     }
 
     protected override void OnUpdate ()
     {
         var collideAndDestroyData = GetComponentDataFromEntity<CollideAndDestroy>( isReadOnly:true );
         var ballFollowDataData = GetComponentDataFromEntity<BallFollowData>( isReadOnly:true );
 
         var destroyJob = new CollideAndDestroyJob{
             collideAndDestroyGroup  = collideAndDestroyData ,
             ballFollowGroup         = ballFollowDataData ,
             commandBuffer           = _commandBufferSystem.CreateCommandBuffer()
         };
         this.Dependency = destroyJob.Schedule( _stepPhysicsWorld.Simulation , this.Dependency );
 
         var triggerJob = new TriggerAndDestroyJob{
             collideAndDestroyGroup  = collideAndDestroyData ,
             ballFollowGroup         = ballFollowDataData ,
             commandBuffer           = _commandBufferSystem.CreateCommandBuffer()
         };
         this.Dependency = triggerJob.Schedule( _stepPhysicsWorld.Simulation , this.Dependency );
 
         _commandBufferSystem.AddJobHandleForProducer( this.Dependency );
     }
     
 }
 
 [BurstCompile]
 struct CollideAndDestroyJob : ICollisionEventsJob
 {
     [ReadOnly] public ComponentDataFromEntity<CollideAndDestroy> collideAndDestroyGroup;
     [ReadOnly] public ComponentDataFromEntity<BallFollowData> ballFollowGroup;
     public EntityCommandBuffer commandBuffer;
     public void Execute ( CollisionEvent evt )
     {
         Entity A = evt.EntityA, B = evt.EntityB;
         if( collideAndDestroyGroup.HasComponent(A) )
         if( ballFollowGroup.HasComponent(B) )
             commandBuffer.DestroyEntity(B);
     }
 }
 
 [BurstCompile]
 struct TriggerAndDestroyJob : ITriggerEventsJob
 {
     [ReadOnly] public ComponentDataFromEntity<CollideAndDestroy> collideAndDestroyGroup;
     [ReadOnly] public ComponentDataFromEntity<BallFollowData> ballFollowGroup;
     public EntityCommandBuffer commandBuffer;
     public void Execute ( TriggerEvent evt )
     {
         Entity a = evt.EntityA, b = evt.EntityB;
         if( collideAndDestroyGroup.HasComponent(a) )
         if( ballFollowGroup.HasComponent(b) )
             commandBuffer.DestroyEntity(b);
     }
 }


raise collision events


screenshot-2021-08-06-171529.jpg (39.4 kB)
Comment
Add comment · Show 3 · 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
avatar image pastersteli · Aug 06, 2021 at 02:30 PM 0
Share

No error but dont destroy objects I make collide raise collision events for them. colliding but no events work

avatar image andrew-lukasik pastersteli · Aug 06, 2021 at 03:18 PM 0
Share

do you even raise collision events?

avatar image pastersteli andrew-lukasik · Aug 06, 2021 at 03:37 PM 0
Share

Uh I am missing the physics body for one of objects. Thanks now works properly.

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

205 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

Related Questions

Cannot move anything with pure ECS Physics instantiation 1 Answer

Changing mesh collider's mesh cause objects go into mesh. 1 Answer

how to make destructable items 0 Answers

How do you make a bullet disappear upon contact with another object 2 Answers

(DOTS) How to slowly rotate an object to face a point? 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