DOTS Gameplay: Trigger Events

preview_player
Показать описание
In this video, we setup a simple trigger event, introducing some extra interactivity to our mini-game demo. The simple act of picking up an item might need a little more scripting than you think. We're a long way from OnTriggerEnter!

Starter project:

Final project:

This is a double-size episode, so use the timestamps below:

TIMESTAMPS

0:42 Packages and Setup
1:30 Simple Physics Scene
2:52 Unity Physics Worlds/System Update Order
3:57 TriggerEvents Scene
4:25 ItemPickUp Setup and SubScene
5:27 PickUp Physics Authoring Components
6:54 Physics Debug Display
7:53 Spaceship Physics Authoring
8:22 PickUpTag Component
8:58 PickupOnTriggerSystem
9:51 Reviewing JobComponentSystem
10:39 Setting up ITriggerEventsJob
11:17 Set up Physics Worlds references
13:07 ComponentDataFromEntity
14:29 Execute logic
16:55 update System Order and disable Burst
17:57 Debug Play Test
18:43 EntityCommandBuffer
19:50 ECB Systems
20:45 Creating the EntityCommandBuffer / Destroying the PickUps
23:10 Second Play Test
23:53 More PickUps

Software: Unity 2019.3.14f1 (MacOS) with HybridRender Version 0.4.1 and Entities Version 0.9.0 from the PackageManager.

Also check out the previous videos in this series:

DOTS Gameplay: Basic Player Input and Movement:

DOTS Gameplay: Tags:

DOTS Gameplay: ComponentDataFromEntity:

DOTS Gameplay: EntityQuery

Unity DOTS: C# Job System:

Want to learn more about DOTS and ECS? Sign up for our mailing list to get notified when the premium course releases:

Let’s build something cool together!

Ready to go Pro? Get Unity Pro here (affiliate link):
Рекомендации по теме
Комментарии
Автор

The reason you are not having many hits on your DOTS videos are not because they are not good. It is simply because not many are still using DOTS. around 95% or even more Unity users are still chasing Game Objects on Tile Maps. New tech takes time to catch on. Your videos are by far the best on YouTube on this subject. There are two main courses on Udemy on DOTS and they are nothing compared to your high quality, well explained video. Kudos! I have shared your videos on several Unity forums and wish you good luck. May you be well! :)

diliupg
Автор

In Unity editor the "Physics Shape" component has no more a checkbox for "IS TRIGGER", you have to select from the dropdown "Collision Response" the option "Raise Trigger Events". And that's all!

TakeshiKovacs
Автор

Thanks! Please keep posting tutorials on DOTS!
Best content I've found so far on this topic!
Make a Patreon page so we can support you

_MG_
Автор

Thanks for sharing more DOTS Content! I'm excited to catch up through your back catalog. I'm really excited to learn ECS but I've been struggling. Resources like yours help a ton!

MatthewTrecozzi
Автор

I ran into an issue where Unity would tell me the fighter mesh was invalid when I tried to implement the physics side of things... if this happens, re-import the fighter prefab and be sure to tick the Read/Write box before you finish importing it.

zacharym
Автор

Will you include raycast in the course too? basic 2d physics? How to render 2d and use 2d collisions and triggers that would be really good

shirosurfer
Автор

Give this man more views! Great content as usual. Can't wait until you release your full course! Do you have a release date in mind? Sidenote, I really hope unity fixes the competability between different version of the dots preview packages it already gave me a lot of headaches. Keep up the great work sir!

tehuster
Автор

I get 3 entities of the ItemPickup created. 2 children of the other. When I collide, the parent disappears leaving the 2 children behind. Very strange. Don't know where the children are coming from as I have only 1 ItemPickup in the sub scene. Seems to be because of the 2 materials Hologram_mat and Letter_mat on the ItemPickup. If I remove Letter_mat it works but the letter is gone.

actsplosive
Автор

Hello, do someboody know what happens, if both entities are triggers and we want to change both values of the entities? I am mean their could be alot trigger events beeing involved with the same Entity, so why we can change them?

joepeters
Автор

Hi i started to follow a bit DOTS for Unity and i will follow your playlist but i dont know how you added the ECS in Projects => Create=>ECS (subfolder). I dont have the build and ECS in this contextual menu. If you have a link where you did this i would love to know. And it's rly good content Thx for sharing this knowledge MY BAD i got it after installing Entity but must say on 2020 there is some improvement or change that doesn't make this too easy ;)

madhackademy
Автор

Can't make it work in 2020.2 even after fixing all errors. Execute in PickupOnTriggerSystemJob is never triggered for some reason. Any ideas on how to fix it, please?

Ankhtepot
Автор

Hi i need upgrade score text every collision detected. can you help me?

erenkaraymir
Автор

it's so clear, thank so much (y) . Can you do one more for Collision instead of Trigger ?

justinduynguyen
Автор

Entity0.51 doesn't have JobComponentSystem anymore, that part might need change:




public partial class PickOnTriggerSystem : SystemBase
{
private BuildPhysicsWorld buildPhysicsWorld;
private StepPhysicsWorld stepPhysicsWorld;
protected override void OnCreate()
{
buildPhysicsWorld =
stepPhysicsWorld =
}
// [BurstCompile]
struct PickupOnTriggerSystemJob : ITriggerEventsJob
{
[ReadOnly] public allPickups;
[ReadOnly] public allPlayers;
public void Execute(TriggerEvent triggerEvent)
{
Entity entityA = triggerEvent.EntityA;
Entity entityB = triggerEvent.EntityB;
if &&
{
UnityEngine.Debug.Log("This:" + entityA + " Other:" + entityB);
return;
}
if &&
{
UnityEngine.Debug.Log("Pickup Entity A:" + entityA + " collided with player Entity B:" + entityB);
}
else if &&
{
UnityEngine.Debug.Log("player Entity A:" + entityA + " collided with Pickup Entity B:" + entityB);
}
}
}
protected override void OnUpdate()
{
PickupOnTriggerSystemJob triggerJob = new PickupOnTriggerSystemJob()
{
allPickups = GetComponentDataFromEntity<PickupTag>(true),
allPlayers =
};
Dependency = triggerJob.Schedule(stepPhysicsWorld.Simulation, Dependency);
}
}

qin
Автор

Wow ty vm.

What do you think of a networking course? You are very good teaching

Tomorrow I'll give this a try.. cool.

shirosurfer
Автор

Hi, for each pickup entity, i can see 2 more pickup entities with SceneTag, obviously only the one with the pickupTag is deleted. do you have an idea of what is happening?

MusicaPaLarumba
Автор

That seems like a lot of work to get an OnTriggerStay... but I think the performance benefits are worth it. Would you say it DOTS is ready to be used on a production environment?

autorotate
Автор

I click the starter link everytime but I get the final project everytime. Tried to figure it out but I just gave up and I delete stuff til I get back to the starter project. Anyone else?

kennethgriffin
Автор

I cannot open a scene from the starter project that I pulled down. I get an error and crash that states
"Size overflow in allocator. IntPtr)"

I've tried a couple different versions of dependencies ensuring they were compatible with each other. I haven't tried upgrading the entire project to 2020.1 from 2019.3.14f1 so I might do that next.

I deleted the Library/ folder to force Unity to re-import everything. Unity now just hangs.

Any ideas on how to remediate my original issue?

polardevs
Автор

Unity released a new version of Unity Physics, now 0.4.0, and the syntax for triggers seems to have changed. :/

isaacryu