Тёмный

DOTS Gameplay: ComponentDataFromEntity 

Wilmer Lin GA School
Подписаться 12 тыс.
Просмотров 8 тыс.
50% 1

In this episode, we create a new Chaser Entity to showcase how to create relationships between Entities. We can add a component to hold another Entity's ID, then use the ComponentDataFromEntity structure to get access to its Translation. With a few extra tweaks to our existing Systems, the new Chaser Entity is born!
Starter Project:
github.com/Uni...
Final Project:
github.com/Uni...
TimeStamps:
0:44 GameAcademy.school Updates
1:09 StartProject and Packages
1:48 Disabling the Asteroids
2:17 Setup Chaser GameObject
4:00 ChaserTag
5:14 TargetData
7:23 Revising FaceDirectionSystem
9:31 Input Parameters for Entities.ForEach
10:10 ComponentDataFromEntity
13:40 Play Testing FaceDirection
14:00 Revising MoveForwardSystem
14:39 Play Testing Chaser
15:44 Man V Missiles
16:10 Adding more Chasers
16:49 Enabling the Asteroids
17:23 Chaser Subscene
18:16 Outro
Software: Unity 2019.3.11f1 with HybridRender Version 0.5.0 and Entities Version 0.10.0 from the PackageManager.
Also check out the previous videos in this series:
DOTS Gameplay: Basic Player Input and Movement
• DOTS Gameplay: Basic P...
DOTS Gameplay: Tags
• DOTS GamePlay: Tags
Want to learn more about DOTS and ECS? Sign up for our mailing list to get notified when the premium course releases:
gameacademy.sc...
Want to support this channel? Subscribe to our premium courses at GameAcademy.school:
gameacademy.sc...
Let’s build something cool together!

Опубликовано:

 

11 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 62   
@LukeAps
@LukeAps 2 года назад
This is still the best tutorial series on ECS that I've found.
@ves3219
@ves3219 4 года назад
BEst tutorial from DOTS! Plise MORE, MORE, MORE videos.
@HadiLePanda
@HadiLePanda 4 года назад
I really like these tutorials, they're concise and robust, would love to see more :)
@GameAcademySchool
@GameAcademySchool 4 года назад
HadiLePanda I will have a few more here. Then probably the rest in the full course
@nephylumsaracen6722
@nephylumsaracen6722 4 года назад
Where did I subscribe to you? And my... I even enabled the bell icon notifications. Your tutorials are good and to the point. I like you, man!
@davtam
@davtam 4 года назад
Looking forward to the complete course! Awesome content with great articulation :)
@Ben-bd6ro
@Ben-bd6ro 4 года назад
Love these ECS tutorials! Hoping to see more in the future. Subscribed!
@LucGendrot
@LucGendrot 4 года назад
I've been waiting for an ECS tutorial as complete as these have been, thank you so much!
@TheGenis1234
@TheGenis1234 4 года назад
Nice! I am eager to work on that tomorrow!
@GameAcademySchool
@GameAcademySchool 4 года назад
Have fun!
@wrinklymon
@wrinklymon 4 года назад
Just subscribed, these tutorials are great! Hope you cover singletons at some point.
@alexanderyurchenko7513
@alexanderyurchenko7513 4 года назад
I love these! More plz.
@jasonmann2902
@jasonmann2902 3 года назад
if (!allTranslations.Exists(targetData.targetEntity}) the exists method is obsolete but .HasComponent is a direct replacement
@RubberDuck5
@RubberDuck5 3 года назад
Thanks!
@scriptsengineer
@scriptsengineer 4 года назад
PERFECT TUTORIALS! MORE MORE VIDEOS!
@fhq0jjitlyr299
@fhq0jjitlyr299 3 года назад
NICE TUTORIAL!!!
@MusicaPaLarumba
@MusicaPaLarumba 4 года назад
Hi, another great tutorial. i was having an issue and i was forced to move out the foreach this line: ComponentDataFromEntity allTranslations = GetComponentDataFromEntity(true); reading the coments i added .WithoutBurst() and now is running inside the foreach. now i'm having another issue, the next line is moving my chaser, and it always chace my spaceship. any Idea? moveData.direction = dirTotarget; fullcode: Entities. WithNone(). WithAll(). ForEach((ref MoveData moveData, ref Rotation rot, in Translation pos, in TargetData targetData) => { ComponentDataFromEntity allTranslations = GetComponentDataFromEntity(true); if (!allTranslations.Exists(targetData.targetentity)) { return; } Translation targetPos = allTranslations[targetData.targetentity]; float3 dirTotarget = targetPos.Value - pos.Value; moveData.direction = dirTotarget; //FaceDirection(ref rot, moveData); }).WithoutBurst().Run(); I am using entities 0.10.0 and hybrid renderer 0.5.0
@MusicaPaLarumba
@MusicaPaLarumba 4 года назад
ok i found my problem, i was missing my player tag filter in the player movement system
@FillerCraft
@FillerCraft 4 года назад
Like!! Guys, i have 3 questions 1° is there native multiplayer using dots? 2° is it really worth learning dots? I felt a little difficult to understand, but after I saw the difference in perfomance, in fps with and without dots, I was intrigued by this... What is the opinion about the use? 100%? Hybrid 50% dots?? 3° if you were to create an online mmorpg(open world).. With dots or without dots?
@GameAcademySchool
@GameAcademySchool 4 года назад
Hosehulk Yes. They have a Netcode framework under construction. Honestly I would go with Classic if you’re still new to Unity. It’s easier at first. And you can definitely build a full game with it. Anything complicated...and that’s we’re here at DOTS. It’s much more performant.
@FillerCraft
@FillerCraft 4 года назад
@@GameAcademySchool *THANKS* I was impressed with the DOTS, I thought it was a solution that could only give a difference of 5 fps/10fps in the game or help with organization, but after seeing the examples i saw. They were an absurd gain perfomance in fps 😵, I wanted to learn how to use definitely ...."Well. Unfortunately his logic is kind of confusing to me haha :("
@jonathan7fea
@jonathan7fea 4 года назад
I have a really curious question. Is ECS faster than other unity methods? How is the speed compared to generic methods? Frankly if its not fast is there a reason to go for ECS?
@GameAcademySchool
@GameAcademySchool 4 года назад
It is much much faster than “classic” Unity. Depending on what you are doing it can be 10x-30x faster.
@LukeClemens
@LukeClemens 4 года назад
Is there an advantage of using GetComponentDataFromEntity() and fetching the whole native array of translations instead of using GetComponent(targetEntity) and only fetching the translation we're interested in? Is one method more performant than the other?
@-.._.-_...-_.._-..__..._.-.-.-
@-.._.-_...-_.._-..__..._.-.-.- 3 года назад
I'm still learning, but I think the advantage is that GetComponentDataFromEntity can return a readonly, and a readonly is faster. I don't think we can get a readonly from GetComponent.
@LukeClemens
@LukeClemens 3 года назад
@@-.._.-_...-_.._-..__..._.-.-.- I wrote that question 5 months ago, but now I've been ECS coding for 5 months so I understand it a little better :-). GetComponentDataFromEntity() returns a ComponentDataFromEntity struct, which has an accessor that lets you access the data like an array. You call it outside of the job (or foreach). GetComponentData(), on the otherhand, is mainly meant to be called inside of the job (or foreach). Instead of an array, it uses a dictionary based lookup. GetComponentData() is newer and is used more often, especially in SystemBase with ForEach. Both can be read-only. After calling GetComponentData(), you can "write" to the returned value, but won't go into effect until you call SetComponentData() and pass it that same data you modified.
@-.._.-_...-_.._-..__..._.-.-.-
@-.._.-_...-_.._-..__..._.-.-.- 3 года назад
@@LukeClemens Thank you for the insight!
@shirosurfer8864
@shirosurfer8864 4 года назад
Nice 😁
@twiggeh3577
@twiggeh3577 4 года назад
Amazing video series, I love it a lot ! :) Quick question if you have time to answer : usually I would toggle visibility with smth like : myGameObject.SetActive(false), but I couldn't find a way to do something similar with an Entity
@GameAcademySchool
@GameAcademySchool 4 года назад
Twiggeh EntityManager has a SetEnabled method.
@twiggeh3577
@twiggeh3577 4 года назад
@@GameAcademySchool Thanks a lot :) Is there a more efficient way to just not render an entity ?
@TheGenis1234
@TheGenis1234 4 года назад
Good Morning Everyone!, I have a problem with the GetComponentData inside de EntitiesForEach. The error is the following: error DC0002: Entities.ForEach Lambda expression invokes 'GetComponentDataFromEntity' on a ComponentSystemBase which is a reference type. This is only allowed with .WithoutBurst() and .Run(). I do an EntitiesForeach ended with a Run() and the only solution i got working is to move this line of coude outside the lambda expression. It is working, but could anyone tell me what is the problem? I downloaded the final project and it works inside it, i copied the whole script in my project and it brings the error too. Is something related with the project structure or subscenes? Thank you very much, and keep doing this great job!
@TheGenis1234
@TheGenis1234 4 года назад
I've seen my mistake, I've had the Entities package outdated. If someone has the same error try to update the package from the package manager. It probably will crash the sub-scenes, at least it happened to me, but the error above is gone
@GameAcademySchool
@GameAcademySchool 4 года назад
Correct. In some versions of the Entities package, simply involving Run() is enough. In some versions of Entities, you need to add that extra .WithoutBurst() to modify the Entities.ForEach. Find the specific cases under "Supported Features:" docs.unity3d.com/Packages/com.unity.entities@0.10/manual/ecs_entities_foreach.html In this case, it's a method on a Reference type.
@victrolaface
@victrolaface 4 года назад
any thoughts about implementing scriptable objects? confused if they're even relevant or useful for a ecs workflow. noticed a thread here: forum.unity.com/threads/architecture-with-scriptable-objects-and-ecs.559789/ other consideration is "state" and if it's applicable to ecs design. I'm used to finite state machines and wondering if its compatible. ideally I assume ecs' goal is to get rid of state altogether. some folks made a thread about that as well: forum.unity.com/threads/how-to-implement-fsm-in-ecs-architecture.526567/ just curious.
@bradcondran8896
@bradcondran8896 4 года назад
You could easily have an Enemy component, and instead of it being just a tag-component, it has a state data-member. Then you can have your enemy system that processes all your entities with the Enemy component, doing something different depending on the state. Another option would be to use tags and (potentially) different systems for each state, so you'd have Patrolling, Defending, Attacking tags and then one or more systems that operate on entities with these tags. Ex: The Patrolling system checks if the Enemy entity is in proximity to the player entity and if so the Patrolling tag is removed and the Attacking tag is added. I would definitely use an FSM in your bootstrap code to control the overall application. I think I would personally prefer using it in systems as well, over the tag approach, but I'm sure both have their benefits.
@victrolaface
@victrolaface 4 года назад
@@bradcondran8896 thx!
@qin6409
@qin6409 2 года назад
WithAll() doesn't work in Entity0.51 anymore, but it is ok to create 2 Entities jobs.
@behzadbakhti
@behzadbakhti 4 года назад
First of all thanks for your awesome tutorials. and I have a question: What if want get the translation of the targetEntity and change the current object translation, I mean pass the Translation as a "ref" to Foreach? I try that and I got an Error.
@GameAcademySchool
@GameAcademySchool 4 года назад
Behzad Bakhti Entities.ForEach works over all Entities. You wouldn’t try to pass a Translation into it. The ref keyword just gives you read/write access .
@DavidCorsalini
@DavidCorsalini 4 года назад
How would you work around the limitation that you can't use the same Component for the ForEach query and the GetComponentDataFromEntity query, like if I want to set the position of the camera strictly following the player's position.
@GameAcademySchool
@GameAcademySchool 4 года назад
Not sure why that would become issue if you used Tags to identify the Player and Camera.
@polardevs8883
@polardevs8883 4 года назад
It's weird... I'm noticing that my chaser's speed matches mine when its speed value is half. So if my ship's speed is set to 10 then my chaser appears to go just as fast when set to 5... and twice as fast as me when set to 10. I thought I followed the tutorial to a tee but I need to figure out what is going on.
@polardevs8883
@polardevs8883 4 года назад
Ha! The hunch I had was correct. I suspected that an update to the moveData for the chaser was being applied twice. It was being updated by the MoveForwardSystem and the PlayerMovementSystem. I added a WithAll to the PlayerMovementSystem ForEach and it is now working as I would expect :)
@GameAcademySchool
@GameAcademySchool 4 года назад
PolarKC make sure you don’t have a anything applied twice...
@prakyathd5018
@prakyathd5018 3 года назад
How to print message to console when using Unity Tiny?
@CyrilPaulus0
@CyrilPaulus0 4 года назад
Why edit the FaceDirectionSystem ? What we need to do is compute the MoveData component for each chaser and then we can let the FaceDirectionSystem update the chaser rotation. I think it would be clearer to make a "MoveDataFromTargetSystem" that compute for each Chaser the correct MoveData based on the target position. And set this new system to be run before the "FaceDirectionSystem". This way "FaceDirectionSystem" is run on a chaser after the MoveData component is updated with the correct value. This should also be better performance wise as the FaceDirectionSystem is applied in one go instead of two. This also mean that you can directly query all the entities in one go instead of first fetching the player and then the chaser. I think with dots you should try to your best to create systems that directly work on "data" instead of "type". You should not think about "player" or "chaser" but think about the data of those entities that need to be updated.
@GameAcademySchool
@GameAcademySchool 4 года назад
Yes, probably. But understand these are lessons designed to introduce basic workflow. I probably would not even have a "MoveData" Component at all in real usage -- I probably would have ForwardSpeed, Direction, and RotationSpeed as separate Components. Yeah, there's no reason to have PlayerMovementSystem versus just a regular MoveForwardMovementSystem and RotateToTargetSystem that applies to all Entities. It was just there just to show that you COULD do that if you wanted to and show that you could make special behavior for one specific Entity. And to be fair the Player is a special Entity.
@GameAcademySchool
@GameAcademySchool 4 года назад
After looking at this again, hmmm, yeah I totally agree with you, even keeping the MoveData as a component. Looks a re-edit is in order.
@CyrilPaulus0
@CyrilPaulus0 4 года назад
@@GameAcademySchool Thanks for taking it into account ! Keep up the good work. Your tutorials are very well done.
@MusicaPaLarumba
@MusicaPaLarumba 4 года назад
'...And set this new system to be run before the "FaceDirectionSystem"...' how do you do that?
@CyrilPaulus0
@CyrilPaulus0 4 года назад
@@MusicaPaLarumba Game Academy.school explain it in the next tutorial : ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-IuoKWupJ6zo.html
@CollMomo1
@CollMomo1 3 года назад
I dont understand the point of scenes, why not use the convertToEntity, much easier, no ? otherwise, great tutorial!
@xontik
@xontik 4 года назад
How can we help promote this channel ?
@GameAcademySchool
@GameAcademySchool 4 года назад
Benjamin B Ha, I ask myself that pretty much everyday. “Build it and they will come” only works with magic baseball fields.
@MatthewTrecozzi
@MatthewTrecozzi 4 года назад
Should the title be ComponentDataFromEntity?
@GameAcademySchool
@GameAcademySchool 4 года назад
Heh. Yeah.
@AIGameMonster
@AIGameMonster 4 года назад
DOTS Animator? How to do it, Thanks
@GameAcademySchool
@GameAcademySchool 4 года назад
Game Force Wait for Unity to make it easier...
@ildarsharafutdinov300
@ildarsharafutdinov300 4 года назад
Game lacks some animation ;)
@GameAcademySchool
@GameAcademySchool 4 года назад
Yeah, it's just a super-basic mini-game designed to show DOTS concepts. The Animation API for DOTS is still not really there. It can be done but it feels like it's better to wait and see how that develops before trying to add animation stuff.
Далее
DOTS Gameplay: EntityQuery
15:31
Просмотров 7 тыс.
Dear Game Developers, Stop Messing This Up!
22:19
Просмотров 718 тыс.
Flipping Robot vs Heavier And Heavier Objects
00:34
Просмотров 12 млн
Bro think he the MC.. 😂👊🔥
00:20
Просмотров 13 млн
Unity DOTS: C# Job System
19:47
Просмотров 20 тыс.
DOTS Gameplay: Trigger Events
25:02
Просмотров 12 тыс.
Coding Adventure: Solar System
12:12
Просмотров 858 тыс.
Unity DOTS: Components And Systems
18:50
Просмотров 16 тыс.
What are Subscenes in Unity? (Massive Worlds!)
15:51
Просмотров 96 тыс.
4 Godot 4 Devs Make 4 Games in 44 Hours
25:19
Просмотров 526 тыс.
You're not using Godot to its potential
6:12
Просмотров 98 тыс.
Unity DOTS: Conversion Workflow
15:55
Просмотров 22 тыс.
Unity DOTS: System Base
12:47
Просмотров 15 тыс.
Flipping Robot vs Heavier And Heavier Objects
00:34
Просмотров 12 млн