#archived-dots
1 messages · Page 112 of 1
Another reason to use the debugger :^)
Does anyone know what is causing this? I think thats the camera
Changing my Camera "Rendering Path" from "Use Graphics Settings" to "Deferred" got rid of it but now I can't use MSAA. Not sure what that means for me in the long run
If I'm not filtering entities based on data value, and the data itself is small so the size benefit is negligible, is there other benefit in using shared component data instead of the normal?
Check out the notes at the bottom of the docs, may be something of value in there for you; https://docs.unity3d.com/Packages/com.unity.entities@0.6/manual/shared_component_data.html
Yeah I've read that
From my understanding, shared components are good for iterating/filtering because they are grouped together in memory.
But if I'm not making use of that then I guess there's no point?
Asking just in case I overlooked something.
SCD is only useful if you need to group entities in the same chunk for any reason
Gotcha, thanks to both!
All of the ECS tutorials I've seen lately are unstable, none of them even compile 😓
Anybody have some up-to-date tutorials?
NICE, solved it: I needed the hybrid rendering library installed facepalm
the official repo should always be your starting point imo
imo official repo is pretty complicated after rotating cube example. I could suggest 3 tutorials
@celest bone
3rd one is a playlist, you should watch every video about in it imo
Any reason you need ECS to use stuff like NativeList?
Why that's not something from Collections itself?
but NativeList is in Unity.Collections namespace🤔
Yeah but from what i've seen it's an extension created from ECS
I have the latest version of Collections but i don't have NativeList
From docs:
"Note: The Entity Component System (ECS) package extends the Unity.Collections namespace to include other types of NativeContainer:
NativeList - a resizable NativeArray.
NativeHashMap - key and value pairs.
NativeMultiHashMap - multiple values per key.
NativeQueue - a first in, first out (FIFO) queue."
can you give me link to this docs🧐
That's weird
I'm looking at the source and yeah, it's there but for some reason intellisense it's not getting it
Is there a way to prevent gameobject's children converted into entities ? I want to make shooting points in my prefab to indicate where shots will spawn, in my 'master' authoring, i want to get local position of these shooting points and store it to a buffer(or probably in a component) therefore i dont want children to be converted, is this possible ?
@opaque ledge You can put a ConvertToEntity (Stop) MonoBehaviour on the child gameobject. That GameObject and any of it's children will not be converted
apparently Unity Physics joints don't work at all when placed in dots subscene
Thank you
@dull copper try adding ConvertToEntity script😅
oh, it works only when subscene is open😕
I have dots editor here so it handles that automatically
it just seems, I keep finding combinations where things break regardless how I use these
there's always something
of course the physics package as well as all dots things are still in preview
but I'd still would have wished they had done proper ECS integration in the editor instead of this conversion stuff that fights me every step
for example, those child rigidbodies don't get unparented by the conversion if I choose convert and inject GO, only if I use convert and destroy (or use dots subscene with dots editor)
if I want to use convert and inject, I need to flatten the hierarchy and then it simulates things again
then these joints don't work at all in the dots subscene
but it's probably just a case where they didn't take this alternative into account by the time physics package was released
next physics package (which should be out soon) should have joint conversion scripts, so I expect it to work better then as well
by conversion, I mean now that they convert physx joints to unity physics side
(and of course ECS)
i feel your pain 😦 its not fun when you hit these sort of roadblocks.
well, these are not really blocking issues, but it's pain to prototype when you have to find the magic combo that works
anyone tried namespace stuff ? when i add a namespace to my system "UpdateAfter" attribute doesnt work 🤔
also, it doesn't really take that much time to do, it's just frustrating
I also wonder if there's some truly intuitive way to author conversion systems with parent - child relations
now I've just handled the creation of all from parent
but would prefer if I could just handle each separately from their own GO's. I wonder if I could play with monobehaviour script execution order to guarantee that the parents have been created before processing the conversion of the child
i think you can do this with conversion system🤔
you can use UpdateBefore-After with them
you can do that on conversion systems too?
or rather on authoring
or you mean I'd make a system that just runs once at start?
I ask because I've thought about that as alternative, but it feels like a hack
(like about everything I've come up so far regarding dots 😄 )
there is specialized ConversionSystems😅
[GenerateAuthoringComponent], IConvertGameObjectToEntity and GameObjectConversionSystem
yeah, the authoring component is totally useless in my cases, I've been using IConvertGameObjectToEntity now
then GameObjectConversionSystem is the next step for you😁
did that used to exist before this convert to entity setup?
it sounds really familiar
I mean besides it being offered in Convert method
i think it appeared together with IConvertGameObjectToEntity method🤔
I assume to find example for it, I'd need to look into existing conversion scripts for hybrid etc
https://www.youtube.com/watch?v=TdlhTrq1oYk haven't you watched this video?
and they use it in physics samples
I've watched it but I have a terrible memory
will watch again 😄
most unity physics samples I've looked into have been super simple, and more advanced have been quite a mess on GO side like the vehicle one where they do even physics queries on MB's instead of on ECS
not been under impression there's any good examples for ECS side on that part of the repo
you never know, where you can find valuable information🤷♂️
that's true 🙂
yeah, i never could have known using namespaces could break my scripts for example
i am so sad right now
gonna comment them out 😦
I've never had a problem with namespaces, I don't see how it could cause any issues
I think when you are not using namespace, your system's update order is right after BeginSimCommandBuffer, but when you are using one it goes wild, i am adding UpdateBefore BuildPhysics system now, it works properly now
That really doesn't sound right, whatever is causing your issue I seriously doubt it has anything to do with namespaces
Well... when i dont add the namespace it works fine, when i add it doesnt work fine, and only difference i could found is system's update orders.
Oh you're saying when you don't specify the update order it changes your system update order based on which namespace they are in?
yeah i think something like that.
but my problem was they started to update after build physics, so that caused some weird issues, so i have to update before build physics.
you never had that problem ?
I haven't touched dots physics yet. But I'm assuming Unity is using some kind of reflection to iterate over systems when determining the default order, I can imagine namespaces having some influence on that but I don't know enough about how it works
If you've determined 100% that just adding a namespace is changing your behaviour that seems like a bug for sure though
Yeah, i am going to make a forum post soon
i mean it doesnt break the systems it just changes system's default order
@dull copper yeah you can use those updateafter\before attributes on conversion systems too. I have one that goes afternphysics conversion to remove physics velocity from certain entities and another to remove extra rendermeshes. If joints aren't working you're sure the subscene isn't using an injected game object entity for one of the joint connections?
so... vblanco spotted this on UE4 commits: " Adds "Add Entity Component" button to Valkyrie Level Editor and removes access and display of old Actor Components. Part 2"
would be funny if Unreal gets proper ECS in their editor before Unity despite Unity now working years on this :p
tim has been making good progress on his transactional framework
maybe it'll be data oriented vs transactional flavors of ecs? haha
I'd imagine it's a good match for their Gameplay Abilities System they've been pushing for a few years
if it really is a new ECS direction for the engine, I wouldn't be surprised if they release it at the same time as Unity honestly. The work on Chaos and Unity Physics started around the same time, and now Fortnite is already using the former, while latter is still a wip due to the nature of the entire dots ecosystem
https://www.reddit.com/r/unrealengine/comments/ahx3zq/implementing_ecs_pattern_for_movement_logic_5000/ this guy's been working on his own ECS system in UE4 for a while, talks about some of the impedance mismatches inherent in the engine and C++
oh ue4 is totally unsuitable for ecs as it is right now
i did cooler shit http://victor.madtriangles.com/code experiment/2018/03/25/post-ue4-ecs-battle.html
Video Inspired by the new Unity ECS system, i decided to try those same techniques with UE4 and C++ instead of Unity and C# . For my experiment, i used the library EnTT to drive the ECS.
moreso than unity with monobehavior even
its opensourced btw
I was just going to say there's a transform impedance mismatch, couldn't remember where I read about it, looks like it was your article :D
most likely
i did find ways around it btw
moving actors is suuuuuuper slow by default
but
there is some trickery you can do. You can go to the mesh component itself, and set its model transform directly
set matrix, call UpdateBounds, and flag as dirty to the renderthread
do those 3 things, and you can move unreal meshes with extremelly low overhead
if you want Ultimate Level Tryhard, you can use Niagara for rendering. Niagara is their scriptable particle system, you can create a niagara module that reads a CPU array where you have the unit-data
ive seen some guys use that to reach 100k units
Fun fun
I would imagine an official version of ecs in ue4 won't be data oriented though
still would be faster than the current framework anyway
basically anything other than current ue4 framework would be a huge win
current model is a disaster
worse than unity monobehaviors. a LOT worse
Yeah it's a pretty convoluted system
I think they got lost in blueprint land for a few years
well, if it wasn't for the entire package of ue4 I wouldn't want to use the gameframework at all
blueprint was a huge win for them, so I doubt they would abandon it and make the new stuff code based
that is of course, assuming this entity component commit is indicative of an ecs framework...
Oh I don't think they'd abandon it necessarily, but it isn't a codegen system as I understand it, it's essentially a VM
it could easily be some internal term
I think if Unity's visual scripting efforts hook into the DOTS conversion or codegen in a sane way it'll attract the legions of UE4 blueprint designers right away
Yeah
packaging is more important than what is underneath in case of blueprints
I'm just trying to figure out when it makes sense to start building something new in DOTS, and how much of it to build around. ECS and Jobs are easy and most of it's there already, but NetCode/Physics/Animation... is it going to be a nightmare to convert later after 8 months of work?
Picking something like Mirror now is probably going to suck to convert later
I would at least wait for entities 1.0 to be honest. At least that'll bring more stability to other packages as well
right now if you update one, the other ones might lag behind anyway
entities should be 1.0 in 2020.1
in fact, considering how unity time works, you might be better off using monobehavior and use ecs in the background for performance
Yeah seems like conversion is their major focus as far as workflow/ux
My rule of thumb is release + 1 years for using unity systems
it is fun to play around with the new stuff, but most of them require a ton of time to be production ready
Yeah that is the direction I'm heading towards lately.
I just really HATE the OO style of Monobehaviour, everything ends up being a mess of lines
So I'm just attracted to the ECS design pattern, it's cleaner
Tbh ? Right now ECS is fine if you want to go hybrid, there is no way to make everything ECS way anyway, if you just make your most cpu intensive stuff to ECS then it should be fine, something i do in Monobehaviour was taking 30-35 ms at best, in ECS i am doing it in 0.05 ms.
It's a great design pattern.
I think I'll start building my new project with ECS and Jobs, use the conversion scripts, and hold off on the animation/netcode pieces, see where they are in 2020.1
Yeah I think that is what I'll do as well. There is also Entitas but I don't feel like paying for something that is going to be obsolete soon xD
https://github.com/sebas77/Svelto.ECS there's also this which was quite pleasant to try
hrm, I've been having a time getting autocomplete working with ECS, any pro-tips?
What do I give AddJobHandleForProducer if I'm using the new SystemBase?
just a handle of the job calling the command buffer?
and dependencies are automatically handled...?
thanks, CurlyOne!
and the jobs are automatically associated with that Dependency
that i declare before the call to the command buffer
in a given update
Yeah, they are handled automatically, ForEach lambdas at least, both Schedule and Run
This code:cs Entities.ForEach(...).Schedule();
is equivalent to this:cs Dependency = Entities.ForEach(...).Schedule(Dependency);
But if you write ITriggerJob or ICollisionJob you have to manually add it, such:
Dependency = new TriggerJob(simulation, physicworld, Dependency);
That's a nice simplification. Good to know there are exceptions.
For Schedule its like that true, but SystemBase's auto dependency also involves Run, you used to use AlwaysSync attribute if you wanted to use Run to solve dependincies by.. completing every job before system runs. now in SystemBase it automatically handles it
at least from what i can see
well, there's ScheduleParallel now
Dump question but if I run a JobComponentSystem or a SystemBase and run it with .Schedule(), will other Systems run in paralell if they can? I mean if my System is NOT using all cores? Will the next System start if it doesn't depend on the other system?
Hmm interesting PR 🤔
Hmm, so do you friends not use the Unity terrain to craft your levels? What do you friends use for level editing if not terrain?
@formal scaffold as long as your jobs are scheduled in the job system, that will take care of splitting your jobs into threads
But you can specify with SystemBase whether it should be on one thread or multiple thread
And of course also main thread with .Run()
@formal scaffold Schedule() seems to use single thread, ScheduleParallel all needed
(with systembase)
also regarding hybrid renderer v2, seems pretty certain we'll truly see it in action around GDC
I perform Player and Camera rotation in a JobComponentSystem because they all depend on each other. Not sure if it can be done in a SystemBase since I don't have JobHandles 🤔 or maybe I do.
Anyways the Idea is that this System should not run on the main Thread so other stuff can be calculated in the meantime.
Another question, tho no DOTS related. Can I somehow calculate the Rotation of an Entity by using the LocalToWorld component? In my JobComponentSystem I store the result of the rotation in a NativeArray and I don't want to create another one. One for Rotation and the other for LocalToWorld. 🤔
think were gonna get something other than RenderMesh for rendering? ie something for many unique meshes
WHOO! Got my Dots/Omnisharp working.
The issue was extremely stupid:
Managed to find my way to this thread: https://forum.unity.com/threads/visual-studio-code-editor-1-1-4-error-the-referenced-project-does-not-exist.806628/
Which confirmed that it was a bug with Unity's VSCode plugin here: https://issuetracker.unity3d.com/issues/vscode-omnisharp-project-reference-warnings-are-thrown-in-vscode-console-when-using-vscode-1-dot-1-4-1
Following the step to downgrade to vscode 1.1.3 fixed the issue 😅
Just posting here in case anyone else suffers the same fate
yeah Ive been telling people to downgrade to 1.1.3 for over a week now
its a shame its known and isnt fixed yet
<3 me some VS Code, us it in my day job constantly
I'm usually a big Emacs dude but I let reason win out on this one xD
I just burned like 4 hours on that 😢
I was deep into vim and emacs for over a decade, but about a year ago I switched to VSC. It's just better, especially with the extensive modal and binding support
I don't have time to change my tiling wm config in Haskell and patch a kernel module to fix my audio and figure out what broke today with Exchange server support or why my Zoom client isn't working today, all so I can live in an environment that caters the best to a sophisticated zsh/vim/etc ecosystem. Finally threw in the towel
I always tell people: I fully admit it is a hobby more than it is a practical concern xD
Though now-a-days I just drive Emacs on the language servers that VSCode use anyway, so a lot of the back-end is the same
Indeed
Got a question for you ECS fans out there:
In an archetype-based ECS, how does the filtering step actually work?
Like you have a bunch of chunks, each associated with a subset of components
We ask for some subset, and we get back all matching chunks.
What happens to get us all those chunks?
Are all chunks individually queried? Are there data structures somewhere on the heap for making queries quicker?
From my understanding a lot of the point of ECS is to avoid putting anything on the heap at all
Traditionally it is a struct of arrays where a component's "ID" is an index in to a huge array
Yes, but with archetype based ECS, when iterating entities with some combination of components, you iterate every 16kb chunk that has that combination of components
I should say, the archetype strategy to ECS doesn’t necessarily need 16kb chunks but that’s what Unity uses
But anyway, you get effectively an array of chunks and then iterate each chunk individually, doing transforms on the component data
The question is, with a bunch of chunks allocated, each with some combination of “mini” component arrays inside it, how does Unity collect the chunks for iteration?
Is it a matter of going chunk header by chunk header, over the entire set of chunks? Is there some sort of superstructure to make queries faster, or are there maybe external data structures to help cut the cost of jumping chunk to chunk? And if so, what does that look like?
From memory, so may be a bit wrong/outdated:
Every query stores a list of matching archetypes. It is first created when you GetEntityQuery() with a new set of components, and then every time a new archetype is created all queries are looked at and have the list updated if they match. Each archetype knows what chunks contain its data, so at query execution time its just
for chunk in archetype.chunks:
DoStuff(chunk)```
Thing to note is that creating new queries and new archetypes is rare (basically only at init time, and then a couple of times when you combine components in a new way at runtime), so the overhead is really small
Look at the sources of EntityQuery if you want more details/up to date info. The sources are pretty clean and readable.
Check the Preferences->External Tools -> Generate all .csproj files option, it tells Unity to add all the package projects to the VS solution, makes code navigation a lot easier (although the option often doesn't work for some reason, may require a few restarts/.sln regenerations)
Oh dang, I was wondering why some sources were in VS and why some weren’t
I wish someone would just create a github of the entities source. I'm sure Unity would not be pleased with that though
It's all in the Library/PackageCache
idk, I'm ok with just having them on disk
I know, but it's annoying to find them and VS loves to randomly close them on me
I’m guessing that queries don’t often in practice get into the problems of combinatorics at scale?
Like, 2^n-1 queries would be pretty bad
But I’m guessing that doesn’t really come up?
FYI, there appears to be an EntityQueryCache which uses a hash map to cached queries
class EntityQueryCache
{
uint[] m_CacheHashes; // combined hash of QueryComponentBuilder and delegate types
EntityQuery[] m_CachedEntityQueries;```
resolving a query is near free after it's created, and you usually don't create queries at runtime (all the built-in magics cache them)
I guess 2^n-1 component combinations would be pretty bad too now that I think about it
Yeah I was thinking more in memory cost
You mean you want a query for every possible combination of components?
Probably isn’t even close to a problem in practice though I’m guessing
@formal scaffold
SystemBase's jobhandle is "Dependency" property, if you use Entities.ForEach, or Job.WithCode, dependencies are automatically handled, if you use job structs you need to handle dependency manually, such as: Dependency = new MyJob().Schedule(Dependency);
You can use Schedule or ScheduleParallel to run something in worker thread.
You can use "GetComponenetDataFromEntity" and "GetBufferFromEntity" methods in OnUpdate, and read your entity's data in your job. For example:
void OnUpdate(){
var translations = GetComponentDataFromEntity<Translation>();
Entities.ForEach((MyEntityHolderData data)=>
var entityPos = translations[data.entity];
);
}
(Here i am assuming MyEntityHolderData holds an entity field)
If the data you are trying to access is a singleton (meaning that there is only one kind of that component) then you can use "GetSingleton" in your OnUpdate.
If your system only wants very specific entity (such as player or camera), you can use a tag component, add that to entity, and call GetSingletonEntity to get that entity.
If you are making a camera follow a player system, what i do is, since my camera and player are unique entities, meaning that there wont be any other camera and player, i use singleton components to hold player position and rotation, so something like
public struct PlayerInfo : IComponentData{
public LocalToWorld localToWorld;
public Rotation rotation;
}
Then i add this component to my player and create a system that updates this component right after player moves. and if some of my other systems requires player position or rotation such as my camera system i simply use "GetSingleton<PlayerInfo>()" in my OnUpdate.
Unreal is all open source right?
hey hey, quick question here, is using bytes for comparisons the same speed as using booleans in burst, or does it do some burst magic to make booleans faster?
unreal is source available, the term open source has license connotations, best not confuse open source and source available
I belive a boolean is a byte, not a bit, so should be the same, but you have to check the assembly i suppose
okay, thanks!
@spring hare you can calculate the memory cost of the queries by handwaving a bit
Overwatch had something like 30 systems
but their system was a bit more around bigger system. With unity system, 200-500 is where i would say would be the top-end
some lunatic in the Entitas github commented having 2000 queries
and well, the cost of those queries, (lets say on average 1 chunk is included on 50 queries) is low compared to the memory cost of the chunks themselves
one is 50 pointers
other is 16 kb
Is there something like a nice and neat cheat-sheet for dots ecs?
@round summit https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Documentation/cheatsheet.md
@opaque ledge thanks
I only want dots for is new unity physics and its statelessness
Do you think i should just try to create a rigidbody abstraction as a monobehaviour (with collision callbacks, velocity read, addforce() etc.) that creates an entity in the background and updates the GameObject's position based on that entity?
Or is something like that already made?
I tried reimplementing the ParentSystem using SystemBase and Entities.ForEach().. great learning experience
who knows of more material/examples being available on Intrinistics (https://www.youtube.com/watch?v=BpwvXkoFcp8) ?
You can find the instricts themselves here https://docs.unity3d.com/Packages/com.unity.burst@1.3/api/Unity.Burst.Intrinsics.html
but i dont think there is any video or tutorial about it
Hmm..
@vagrant surge thanks, that’s good information to know
Is the a functionality similar to addforce, addtorque, addforceatposition?
If so where can i find it?
I assume these are on a system. If so, what system is that?
Or do everybody implement these stuff into a new system?
@round summit you can look at PhysicsWorldExtensions.cs and ComponentExtensions.cs in physics package
sweet, thanks @warped trail , @opaque ledge
@round summit Another way is to simply add your float3 to the LinearVelocity of a component, that's basically the same as the old physics would do
if you divide the amount by the mass you get a basic variant of AddForce
yeah but there's also addforce at position stuff
i guess i could calculate a torque by cross product n stuff but i'm just going to use the physics extentions since its already there
@round summit that already exists on those helper functions
yeah i saw that
private BuildPhysicsWorld buildPhysicsWorld;
protected override void OnCreate()
{
buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
float deltaTime = Time.DeltaTime;
Entities.WithoutBurst().ForEach((ref Entity entity, ref MyData myData) =>
{
Debug.Log("A"); // this prints
PhysicsWorld physicsWorld = buildPhysicsWorld.PhysicsWorld;
int rigidbodyIndex = physicsWorld.GetRigidBodyIndex(entity);
PhysicsWorldExtensions.ApplyLinearImpulse(physicsWorld, rigidbodyIndex, new float3(100, 100, 0));
}).Run();
return default;
}
What do you think i'm doing wrong here?
I am trying to move rigidbody entity with force with the physics extensions method
so what happens exactly ? does it not affect your entity ? or is there a kind of an error
also imo you should capture PhysicsWorld outside of ForEach, also i think you should not use "ref" on Entity field in ForEach, i am not sure if actually affects but i just never saw anyone using ref on Entity
@opaque ledge But physics world is a struct
If i capture it outside ForEach, i'll only capture its copy at the start of the game?
Also it doesn't let me use "in" for entity
Results in complete syntax error
What happens now is, no change in velocity
OnUpdate runs every frame, so that means if you capture it outside of ForEach it means your jobs will properly use the copy of the physics world.
simpy erase "ref" thats it
you can also enable Burst, you werent able to use Burst because you are accessing a class inside the job, if you catch it outside that means job will only use structs and no access to managed resources therefore you can enable Burst
does it give any errors on console ?
It doesn't let me debug.log with burst. If i remove debug log, no errors with burst
This is what i'm trying now, but still can't see movement
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
PhysicsWorld physicsWorld = buildPhysicsWorld.PhysicsWorld;
Entities.ForEach((Entity entity, ref RigidbodyData rbData) =>
{
int rigidbodyIndex = physicsWorld.GetRigidBodyIndex(entity);
PhysicsWorldExtensions.ApplyLinearImpulse(physicsWorld, rigidbodyIndex, new float3(100, 100, 0));
}).Run();
return default;
}
Moved the physics world outside foreach and removed the "ref" on Entity
Can you check your entity debugger, check if your system is disabled or has a query to run with
Yeah sounds like it.
Let me try your system on my project and see if it works, give me a min
Curl error 56: Receiving data failed with unitytls error code 1048578
I have this error though
In console
prints just once when i hit play
maybe the order in which you update your systems matters?🤔
hmmmm
this extension method changing velocity directly in physics world
i never did anything with Phsyics other than raycasting so i cannot know
maybe if you use this method before build physics world or after step physics world, then you won't getting any results, because your results will be overwritten?🤔
Oh that's right, normally when you do physics stuff you need to do it asynchronyously so it doesn't get overwritten
.Schedule then ?
maybe just apply your impulse through PhysicsVelocity instead of PhysicsWorld?
I'll try now
I think if you use physics world directly you need to call schedule with the physicsWorld.FinalJobHandle (or whatever it's called) then call AddJobHandleForProducer
assigning velocity trough PhysicsVelocity works with same setup without using physicsworld and that extension class
remember there is ComponentExtensions class
Isn't this extension "PhysicsWorldExtensions.ApplyLinearImpulse"
supposed to look at rigidbody data components attached to entity,
get the mass, center of mass, etc
and directly edit the PhysicsVelocity?
Does PhysicsWorld hold any states per rigidbody?
i guess your system has to update between BuildPhysicsWorld and StepPhysicsWorld
and you have you use BuildPhysicsWorld.FinalJobHandle
because you are changing velocity in physics world, but your PhysicsVelocity stays the same.🤔
Boy the physics docs are truly horrible
your system changed velocity in physicsWorld before BuildPhysicsWorld creates new physicsWorld based from ComponentDatas🤔
docs don't include any code examples 😦
I was digging through them trying to find any kind of examples and yeah there's like literally nothing
@warped trail hmm, so a new physics world is created everytime
that would make sense
order of execution matters a lot😅
-
run build physicsworld : create physics world from component datas every frame
-
i need to add force in physics world here
-
run step physics world : updates the physics world
so this is how it is
I guess so. But it is just my intuition😅
when is the data in physics saved back to component datas though?
in step physics would?
maybe this : EndFramePhysicsSystem ?
i think it is saved after export physics world
hm? how do you export a physics world?
@warped trail maybe you were looking for this to sent me, i just got it
how is this export physics world happening though?
oh, i do
[UpdateAfter(typeof(BuildPhysicsWorld))]
[UpdateBefore(typeof(StepPhysicsWorld))]
[UpdateBefore(typeof(ExportPhysicsWorld))]
You can see the source for ExportPhysicsWorld in the physics package
ExportsPhysicsWorld copies everything from internal physics world toy your world
It's a pretty small class
yeah i see
i just need to get the order right
thanks for help everyone
(looks like no karma in this server)
the only thing left for you is to decide how you will make physics framerate independent 😂
I don't think you should be calling .Run on your job if you're doing it that way though
All other physics jobs that touch rigidbodies are going to be running in threads and you'll force them to sync back on the main thread just for your job
I was thinking i'd disable all autoupdates and call the updates in a monobehaviour?
With fixed time intervals?
good luck with that😏
@zenith wyvern I think i won't have any other jobs for rigidbodies 😄
All the internal physics jobs run in threads
What i'm trying to make for now is making a monobehavior abstraction for rigidbody
And sync the transform to a gameobject
With oncollission callbacks, addforce, .velocity and other stuff
I only wanted the stateless Unity.Physics for my networking stuff
And probably main bottleneck of my system is going to be the amount of data to be sent / second
So i can't have too many objects anyway
So i might as well have the monobehaviour simplicity for all my game logic
Thats what i though
You might want to look at hybridcomponent to save you a bit of work, it will auto sync an attached gameobject transform to an entity's transform
Oh, this i never heard of
Like the readme says it's experimental so use at your own risk I guess
As far as I know they work really well though
Well, kind of. The core Entities package is getting pretty far along now, the low level apis are fairly stable. And in this readme it literally says "their use is not recommended"
Which is a bit of scary language
@urban remnant I only recently started using DOTS, if you can tell me what GetEntities<Filter> did, I might be able to point you in the right direction
@bright sentinel
public class PlayerMovementSystem : ComponentSystem
{
private struct Filter
{
public Transform Transform;
public PlayerInput PlayerInput;
public Speed Speed;
}
protected override void OnUpdate()
{
foreach(var v in GetEntities<Filter>)
{
}
}
}
Ah, now you wanna use Entities.ForEach() instead.
https://docs.unity3d.com/Packages/com.unity.entities@0.6/manual/entities_job_foreach.html
It's the same for ComponentSystem
@urban remnant There's also a new SystemBase which just combines the two
Jobs are for multithreading and creating jobs, ComponentSystem will only run on the main thread and no jobs afaik
But with Entities.ForEach, you can also get the Entity for each query. You can then put that into a native array that you use after the ForEach. That's at least one way to get all the entities of a query/filter, but I'm not sure if there's a way to do it more easily
This works kind of
Entities.WithAll<Transform, PlayerInput, Speed>().ForEach((Entity e) =>
{
// do stuff
});
JobComponentSystem got changed to do both but better (can do main thread without garbage alloc and bursted unlike ComponentSystem) so that's basically been the recommended in every case for past two months
0.6 added SystemBase and that seems to be the new recommended in every case
it can do everything the others can but simpler syntax, i imagine the other two might get obsoleted at one point
Yes, that's true. I guess the docs just haven't been updated yet
0.6 added of what?
entities 0.6
Lol mine is 0.1.1
that's the highest for 2019.2 i think
we all on 2019.3+ now boyo
get with the times
also @urban remnant that lambda is fine if you just want to grab the entities with those components
but if you actually want to do stuff with those components you can also put ref Transform x, ref PlayerInput y, ref Speed z instead of Entity e in the ForEach
Things are changing pretty rapidly, but the base seems to be stabilizing somewhat now
and remove the WithAll
damn, still?
2019.3.2 is out now i think
dunno if your issue has been fixed tho
but yea if you're still on 0.1.1 you still gotta use ComponentSystem for main thread and JobComponentSystem for jobs like bman said
So what kind of the most up to date technique for getting entities in system?
So for performance I use Jobs?
But if its playerInput stuff, I probably dont care
most up to date for your case is the foreach docs that bman linked
Pretty much, player input *needs' to be on the main loop though, because you can't access main thread stuff (like using UnityEngine) in jobs
But you can always get the data you need in the thread, store that in a component and then do your stuff in a job with that data
I just mean spawning lots for enemies or bullets like stuff, is good to multithread, but such basic thing as player input and animation
Can easly run on main thread?
animation sounds like something for jobs too
but yea i think if it's really light like changing a float on 1 entity, scheduling a job would prob take longer so could keep that main thread
mkay
On more q
Entities.ForEach((ref Transform Transform, ref PlayerInput PlayerInput, Speed Speed) =>
{
});
Error CS0453 The type 'PlayerInput' must be a non-nullable value type in order to use it as parameter 'T0' in the generic type or method 'EntityQueryBuilder.ForEach<T0>(EntityQueryBuilder.F_ED<T0>)'
public class PlayerInput : MonoBehaviour
{
public float Horizontal;
}
you're gonna wanna use struct and : IComponentData instead of MonoBehaviour
@hollow sorrel and what about Transform. I can't change built in stuff?
hmm they made it so you can add managed refs to entities and just ForEach them all the same as long as it's main thread (but would be less performance than only IComponentData) but i'm not sure if that was already in 0.1
i don't remember what the old way was maybe someone else does
ok
Cmoon
Still NullReferenceException: Object reference not set to an instance of an object on FBX import
Some stupid micro bug beeing aroung for enternity
Still on 0.6
Entities.ForEach((ref Transform Transform) =>
{
});
'Transform' must be a non-nullable value type in order to use it as parameter 'T0' in the generic type or
So I can't reference GameObject Transform in System?
ohyea leave out the ref for managed refs
Mkay
@hollow sorrel did u vote for this https://issuetracker.unity3d.com/issues/nullreferenceexception-is-thrown-when-inspecting-a-fbx-file-with-multiple-clips-and-opening-animation-tab ?
How to reproduce: 1. Open the attached 'project-1215431.zip' project 2. In the Project window select 'MultiClipSingleFile' 3. Observ...
no
As you can see, the fix is in review
Do it 😄
its been around for a while
Yes, but it says that the fix is in review now, so you'll just have to wait 🙂 I guess they already have a fix, but just need to be sure that it works
A short question about ECBs:
Entities which are instantiated by the ECB return an invalid Entity id. This invalid Entity id can not be used in a component to store a reference to the Entity.
var entity = ecb.Instantiate(Prefab);
ecb.AddComponent(ownerEntity, new OwnerData()
{
OwnerEntity = entity
});
Is there any option to do this? Or do i have to use EntityManager directly?
it shouldnt return invalid entity id at all 🤔
assuming ownerEntity exist, that code should work
it should return invalid entity
i believe it does return an invalid id, but its just that if used within the same ECB its fine, because that ECB can link the commands together after it creates the entity.
i mean if it returns invalid id how does add component works from ecb for newly created entities 🤔
i can understand perhaps since entity doesnt actually exist yet it returns invalid id, i dont have an usage case like that but it shouldnt imo 🤔
its invalid because it doesnt exist until the ecb creates it later. they get a negative index from memory, then the index complety changes when the entity is created for real.
it is valid in context of ECB
why the above example doesnt work then
because hes assigning the entity placeholder as the data for a component
~~so,
- entity [-1000] is created by ECB
- add component queued for entity [-1000] with a value of [-1000]
- later that day.... ECB creates an entity [567]
- ECB knows that there is also command for add component, so it adds it to [567]
- now you have entity [567] with a component, that points to [-1000], which doesnt exist~~
i stand corrected, june had it right, and i just tested it too, an entity added inside a component also gets updated by the ECB.
yeah but ecb executes addcomponent AFTER entity is created, shouldnt that be valid ?
aah okay nvm
solution is simple, find another workaround for it😏
I think you can link it the other way lol 🙂
ecb.CreateEntity();
ecb.AddComponent(entity, MyOtherEntity { Value = SomeOtherEntity });
and where do you get this SomeOtherEntity?
dunno I'd imagine you'd have some unique query to get a group of them with some id ¯_(ツ)_/¯
@gusty comet one thing i've done in the past to have a processing step after creation is to put a tag on your prefab, so that the newly instantiated elements can be differentiated from the processed ones.
So for example, your prefab contains components [Whatever] and [Unprocessed] component. You can instantiate stuff, have a query that matches both those tags; do something with the created entities, then use the query again to batch remove component [Unprocessed] which would efficiently copy them into the general population.
thanks for all the answers
@coarse turtle i am also storing a reference of the owner in the created entity (so this works). But i also want to store a reference of the created entity in the owner :D
@mint iron this sounds interesting. Maybe i can mark both owner + created entity and then reference them in another system together. But seems a little bit overkill
Right now i use something like this (so i dont have to use EntityManager directly)
- Create ECB
- Create Entity with ECB
- Store Created Entity + owner in NativeLists
- Playback ECB
- Use NativeLists to reference Created Entity + Owner
Lol
I love that this is the first problem people always run into with ecbs
You can SetComponent or add with the entity inside of it, the post processing step will stitch the right index in. The only thing it doesn't like is going to buffers
Should i learn how to do chunk jobs ? it feels like its overy complicated and only useful for very specific usages, so i am scared 😭
I only learn what I need to
I will learn all.
I will consume all knowledge of these god forsaken manuals.
And then I will share it with others.
Mark my words.
Anyway, how's your day fellas?
😄
well, i am trying to figure out if i should learn chunk jobs and shared components and their usage 🤔
if you have a specific use in my mind for it then why not, but if not then why bother
Well, thats the thing, i am not sure if i will be able to do what i had in my mind with chunk job and shared component
Chunk jobs are the same as foreach except you're working directly on the array of entities/components, rather than working on them one at a time
I will have a gameobject with:
Some monobehaviours and DataComponents
I want to:
"convert to entity and inject the gameobject"
And once i do that i want monobehaviour to have access to these data components and be able to change values with monobehaviour methods.
(I looked at the hybrid components but didn't really understand what they about, i want to have gameobjects in my hierarchy)
.
How would you go about that?
All ecs related things will go into entity, monobehaviours will stay in gameobject
I can make seperate prefabs i gues
I wouldn't, messing with entities from MB is really awkward and makes for horrible code. But if you really want to you need to access the entity manager through World.DefaultGameObjectInjectionWorld
And go from there
Does GameObject-entity conversion happen at run-time or at compile-time?
it depends on whether IConvertGameObjectToEntity is in subscene or not
If not?
i guess after scene load🤔
And if yet?
if in subscene it is serialized to binary file at "save scene" time🤔
What's more efficient?
var dTime = Time.DeltaTime;
And then use the variable. Or directly use
Time.DeltaTime
every time?
Thank you dearly, human mind.
You can't use Time.DeltaTime inside a job so you don't really have a choice, but assigning a property to a local variable is always going to be faster
You cant use... yeah what Sark said 😄
i think you can use it, but you cant use burst 🤔
Okay 😅 finally got rid of my stuttering for camera movement now I gotta clean up 😄
I wanna use burst yeah
@round summit I guess you could also create a "Proxy" System that your MB calls with World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<ProxySystem>(). Create a system-like api in your monobehaviour and have it forward all calls to the proxy system
That ridiculous callchain should give you an indication of why that's not a great idea though, just in terms of code readability
Why everyone avoids component constructors, dare I ask?
It lowers code readability, does it not?
i know some stuff in ecs samples uses component constructors so i guess its not a problem
I heard of an opinion, that Burst handles constructors with great pleasure.
And yet still?..
What a strange tradition.
Since they're value types in most cases a constructor would be useless since it would just be duplicating what you can already do with curly brace initialization
Better to use public properties for sensible defaults like
public struct Speed : IComponentData
{
public int value;
public static implicit operator int(Speed c) => c.value;
public static implicit operator Speed(int v) => new Speed { value = v };
public static Speed Default => new Speed { value = 25 };
}
Has anyone had an issue with intellisense in VS code when using unity? Alot of the functions etc.. get displayed but things like GetComponent dont show up?
I agree with you, Sark. But why would you need a Default in your example up above?
Odd.
i don't like that VSCode stops highlight parameters in lambdas when they are not in one line😕
@indigo delta so I downgraded to 1.1.3 how do I generate csproj ?
It's a checkbox next to the VS Code selection in the settings -> external tools
Then try right-clicking a script in Unity and pick "Open C# project" I think it's called. It's at the bottom
Should generate all relevant bits, and I think it stays in sync
I agree with you, Sark. But why would you need a
Defaultin your example up above?
@frail seal
Because I want entities to have a reasonable default speed and I don't like magic numbers and I don't want to have to go back and change it in multiple places if I decide to change that default value later. What's odd about it?
Usually you would simply do public int value = 25;
Daaaamn i should use that Default thingie as well, i was creating a 'default' value everytime i created that compoment
i am a big noob
You can't define default values on members of a struct.
Even that was allowed i believe Speed.Default would be better because you are explicitly saying so its default, probably personal taste tho
But wait. Then an empty constructor would be a better solution, no?
An empty constructor with value = 25;
What's more readable :
EntityManager.SetComponentData<Speed>(entity, Speed.Default);
EntityManager.SetComponentData<Speed>(entity, new Speed());
i mean there is Entity.Null, so you are explicitly saying thats null 🤔
yeah exactly
I guess in that example, the first option is better.
Consume all the knowledge 👀
If there is a component with an empty argument constructor, and it's data is not set by EntityManager, will it still contain data of it's said default constructor?
there is no default constructor in structs i think, if you do "new Speed()" for example every field in the struct will have default value, since there is only one int field in Speed, it would have 0 as value
@indigo delta thx
Oh yeah that's right, you can't have parameterless constructors in structs anyways
Just found that out.
What a shame.
Perhaps it is like that exactly for the reason of them possibly running their own constructors upon creating struct array.
Seems reasonable enough.
@indigo delta that still didn't work, when I open c# project I get alot of fails Attempted to update project that is not loaded: c:\Desktop\Unity\blahblah\UnityEngine.TestRunner.csproj
@abstract sundial Might need to delete all the project files and reopen from Unity to regenerate them, after the downgrade to 1.1.3
what delete all the csproj files?
Yep. Did you generate them all yourself or customize in any way?
nah, I think I'm just gonna change to using visual studio 2019 tbh
Mmk
Just saying, they were generated for you, so... let it generate them again. Pretty easy step
ok lemme check
same thing, i'm getting this error before the fails, The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.
but I have 4.7.1 on machine
On a Mac?
nope, windows
nah can't be bothered with this, just gonna change to visual studio
😄
Alrighty
works perfectly on that, just used to always using vscode for unity but will get used quickly
From what I can find, looks like this comes up a lot, and the answers are delete files, close vscode and unity, regen files. But best of luck!
thx
So i got something that crashes my editor, i am not sure if its Dots related or not, its related to my movement system, so this is how i set my movement data:
//Crashes if i set to low amount
dstManager.AddComponentData(entity, new CampaignPlayerMovementData { speed = 10, targetPos = new float3(1f,0,0)});
And my movement system:
protected override void OnUpdate()
{
var deltaTime = Time.DeltaTime;
Entities.ForEach((ref Translation translation, ref Rotation rotation, in CampaignPlayerMovementData movementData) => {
var targetPos = movementData.targetPos;
var dist = targetPos - translation.Value;
var normalizedDist = normalize(dist);
var change = normalizedDist * movementData.speed * deltaTime;
if (length(change) > length(dist))
{
//This code crashes editor
//translation.Value = targetPos;
return;
}
translation.Value += change;
rotation.Value = Unity.Mathematics.quaternion.LookRotation(dist, up());
}).Run();
}
i set targetPos of my CampaignPlayerMovementData to get my player where to go on other systems, but i think when distance is pretty low thats when it crashes.
try disabling burst (if it's enabled) and see if there's an exception being thrown
possible you need to either return Dependencies or maybe even Continue
I think it's using SystemBase, introduced in 6.0
Either way, is there anything in the crash log?
no
sometimes it says "isfinite(distancealongview)" just before it crashes, i thought it was camera related but.. camera simply follows the player from a float3 distance
@opaque ledge Have you tried stepping through with a debugger?
See if any values are not what they're supposed to
yeah i will tomorrow, i am about to go to sleep so i will just check if disabling burst helps
actually nvm i will just debug
yeah withoutBurst didnt work
and debugger doesnt stop the editor
maybe it doesnt work on jobs ?
have you tried normilizesafe?🤔
also what does up() call? though it's late and I may be missing something obvious
probably math.up()
hmm yea but then quaternion has fully qualified namespace - which makes me wonder if there are conflict ns issues or something
probably unrelated
yeah math.up(), no i havent tried normalize safe, i will do it tomorrow, i am about to go to bed
what is the difference ?
i am hoping for more than "its safer 🧐 "
😄
if you use "using static Unity.Mathematics.math;" you can't access Unity.Mathematics.quaternion methods😕
as far as im aware you can't normilize very low values, and normilize function will return NaN
normilizesafe cheks if value will return NaN value🤔
ah okay, that makes sense, thats probably it, so camera's position is set to NaN + distance, thats why i am getting that error just before unity crash
Can someone tell me why I would use math.select over a comparison, considering that's exactly what the math.select is?
Nvm, it makes sense when you do it with componentwise selection
Hi guys, im trying to convert MegaCity to HDRP, got an error on ComponentGroup statements, any idea what I should replace that with?
ComponentGroup m_NewVehiclesGroup; ComponentGroup m_AliveVehiclesGroup; ComponentGroup m_SamplesGroup; ComponentGroup m_DeadVehiclesGroup; ComponentGroup m_FlyByGroup;
i think it became EntityQuery
oh ok, i'll give it a try, thanks
also struct StreamSubScenesIn : IJobForEachWithEntity<SceneData> is kicking up a fuss about SceneData, even though im using Unity.Entities......
Technically the mega city is already hdrp 😉
yeah, i mean converting it to work in my HDRP project, I suppose would be more accurate lol
im down to 9 errors, all pertaining to SceneData, Traffic and Concurrent
traffic is the first time i've ever seen Unity.Engine throw up an error for using Traffic.Simulation, so not sure which to eliminate as it requires using the Traffic.Simulation class? so get rid of Unity.Engine?
SceneData is deprecated😅
yeah to what is what I need to know, I cant find any documentation on it......
there is no documentation🤷♂️
😒 k, asking elsewhere.
the only documentation is source code😕
wonder if we'll get some redone megacity this gdc
seems kinda waste if they don't update it to recent DOTS anymore
but then again, it's not like that haven't happened in past 🤔
MegaCity needed some manual changes after it initially released (which im trying to figure out), but after that I believe it updates itself
anyone know where the assembly definition file is located or how to find it? I'm getting Assets\Scripts\Gameplay\Traffic\TrafficSystem.cs(136,109): error CS0619: 'TimeData.deltaTime' is obsolete: 'deltaTime has been renamed to DeltaTime and will be (RemovedAfter 2020-02-20). If you see this message in a user project, remove the UNITY_SKIP_UPDATES_WITH_VALIDATION_SUITE define from the Entities assembly definition file.'
i thought someone mentioned they wanted to add physics to megacity but i couldve dreamt it
they said that, yes
and that they'll keep updating the project
but that's like fps sample all over again 😄
I mean plans change, that's fine, but would be nice if they were more open about it when that happens
i just want more of a roadmap for features and perhaps public repos for the development of the packages 😉
wonder if we will get a new roadmap talk for gdc 😄
Has anyone used that Events ecs system that got posted? Im trying to use it with a SystemBase but getting "can not be called in read mode", I know its something I"m doing wrong but I don't know NativeStreams
tertles one
It looks pretty easy to work with, as far as lines of code go. But I'm new to streams and jobhandles so I don't know if what I"m trying to do is impossible, or I'm just passing the wrong handle in
how to fix this capture without disabling burst/job systgem? https://paste.ofcode.org/p8h9JJZm4kUmQ2kJrB2Npb
well its telling you that you cant use it with burst jobs
whatever worldinfo is, you need to change into a value type, or access on the mainthread
hmm, the Entity system doesnt support bools? so I cant put multiple types of movement code in a system then just activate the appropriate ones from the Data Component script?
how does DOTS play with particle effects? like spawning a dust cloud when a bullet hits the ground
@gusty comet ecs supports bools, not sure whats going on there
@odd ridge only via hybrid for now
unless you make your own particle system
do you know if they will write a particle system for DOTS? in the future?
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Jobs;
using Unity.Transforms;
using Unity.Mathematics;
public class ItemMovementSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
float deltaTime = Time.DeltaTime;
Entities.ForEach((ref Translation translation, ref Rotation rotation, in MovementData movementData) =>
{
// IF SPIN IS CHECKED
if (iSpin == true)
{
// SPIN USING WHAT YOU SET IN THE INSPECTOR
//transform.Rotate(spinx, spiny, spinz);
rotation.Value = math.mul(rotation.Value, quaternion.RotateX(math.radians(movementData.spinx * deltaTime)));
rotation.Value = math.mul(rotation.Value, quaternion.RotateY(math.radians(movementData.spiny * deltaTime)));
rotation.Value = math.mul(rotation.Value, quaternion.RotateZ(math.radians(movementData.spinz * deltaTime)));
}
}).Run();
}
}```
whoa sorry for spam
im getting iSpin does not exist in current context
iSpin does not in fact exist in that context, I assume it's in another class (that you need to qualify the reference with?)
using Unity.Entities;
[GenerateAuthoringComponent]
public struct MovementData : IComponentData
{
public bool iSpin;
public float spinx;
public float spiny;
public float spinz;
public bool randomDirection;
public bool randomSpeed;
}```
right, so you need movementData.iSpin
OOOH, you have to reference the specific script in the IF statement? I thought the system was tied to that script, doh!
yes, your commented call to transform.Rotate() has the same problem
it's normal C#, all the rules still apply
yeah I commented that out, it was the mono version I pasted in, im trying to get used to DOTS instead of mono
you can do weird things with lambda captures, but that's actually also Pretty Normal C#™️
that would have worked in a MonoBehavior since this is pointing to the MonoBehavior
@odd ridge no idea, I hope gdc brings us some juicy stuff but I dont expect it to 🙂
i take it im getting Assets\Systems\Movement\Items\ItemMovementSystem.cs(11,34): error CS0161: 'ItemMovementSystem.OnUpdate(JobHandle)': not all code paths return a value because I need to set a value other than 0? or because I havent added any code to deal with the other bools
Supposedly we're going to get a big Project Tiny update at GDC
actually partially related-- has anyone experimented with hosting VisualEffect components in DOTS? I'm kinda rolling my own strategy for effect pooling
I'll be happy if we get to see a roadmap finally
what do you mean hosting?
@gusty comet slow down a little bit and read the error message again, these aren't DOTS problems. You need to return a JobHandle from that function
im using vfx in dots but just as icky hybrid pooled gameobjects 🙂
^
wondering if there's a way that isn't really bad. I can do some nice things now with SharedComponentData and using the asset as a tag
What the heck, did they come out with another new particle system
yeah there actually was a particle system in one of the first versions of tiny @odd ridge but it got removed I think. I was tempted to try to port the code over but decided its not worth the hassle
I guess I'm hoping there's a nice way to sync GOs that have a VFX component on them with entities
do you why it got removed?
no idea, havent really followed tiny that closely
When they decided they were going to pivot to C# they basically ripped the whole thing apart and started over
Or rather, when they decided they weren't going to have a "pure" entity editor and were instead going to use the same conversion workflow as regular unity
The Tiny Racing demo was the first step in their new direction basically
pivot to c# away from what?
Javascript
they started tine with scripting on typescript
Err yeah, that
i think that was before it was on the package manager though
it's JS essentially
but afaik it was never meant to stay there
it was just there for the initial version
At the time I thought the messaging was that they only pivoted to C# because so many people wanted it
you can still download the package with the particlesystem feature, its all cs(0.16)
er c#
btw
just watched some old ECS talk by Joachim, from 2018
there he said they will be delivering ECS updates I think on weekly basis 😄
i dont think that was ever true 😄
I dunno, it feels that they've slowed down on the update interval
Hey if I had my way they would abandon all other aspects of Unity and only focus on ECS
The fantasy world of a hobbyist
oh I get it, thats expecting an Input.GetKey
if I had my way, conversion workflow would have been burned to ground 😄
well it has it's uses
but still would rather have proper dots support in editor
It sounds like we'll eventually get something close to it, but yeah, it would have been nice if they had kept going in that direction
I didn't like the full dots only mode on tiny... as long as we got hybrid stuff around, both should exist at the same time... the dots mode was kinda all or nothing kinda thing
the easiest way to do this would have been to just have dropdown on the editor that shows you the world based on the dropdown selection, which could be gameobject world/scene or any ecs world
most usable would be if you could just have GO world + one selected ECS world show up in the editor at the same time
i think pure dots editor couldve been maddening for certain cases(especially animation, so many buffers), given how many extra components you need to add in for certain things(not saying conversion is perfect).
Topher has said there are big improvements coming to the entity editor, hopefully it will get a lot nicer
ah, they do have a ton of components now
Right now it is extremely not good
they could still like have higher level components that always show up in editor and rest you could just expand to view
or make them more visible etc
pretty sure the talk was making the entity debugger better
there's been some minor changes to it recently but nothing big
and frankly I'd want stronger connection between the scene editing tools and entity debugger
now it's fairly isolated tool
just being able to edit entity data would be a godsend
Sadly I've seen multiple Unity people respond to that with "why do you need that"
yeah
@bright sentinel also, burst creates only 1 instruct for math.select while if statement creates a bunch, there was a video about instrincts in Unity's youtube channel, you can watch that if you like, using math functions where possible makes your code more friendly to burst
using if's is slow in shader code too, which is why we avoid branching code there as well
its going to be interesting when unreal announces their version of ecs in gdc
wonder if they'll go for conversion or full ecs route 🤔
Anyone knows why this happens ?
like this always happen after 30 mins into play mode
those big oranges are GC Collect and when i profile it, it does it in random systems, it doesnt GC Collect in particular system, its always random
and this is my memory profile
if you are not doing this already, try to profile it in build? 🤔
@opaque ledge look at where the GC memory is allocated, not where it's collected. It's pretty much random when the collection pause happens, but to eliminate them you need to eliminate the allocations that caused them.
6.1 MB allocated per frame, looks fun
You can use the purple/pink blocks in the cpu profiler to see what allocates. Be sure to select the managed allocations option in the dropdown at the top of the profiler.
With this, you can hover over the little blocks and see the full stack that caused the allocation in the timeline view
wonder how many will now just enable incremental GC and forget about things like these 🤔
I hope none 🥺
right now even HDRP allocates 81 bytes yeah frame, it's not always users fault 😄
well besides picking the tech that does it
altho I haven't checked if that happens in actual build or recent 7.2 release
Hmm, is this a deprecated thing?
The tutorial guy was able to to it with "Entity"
This method does accept an "Entity"
public void SetSharedComponentData<T>(Entity entity, T componentData) where T : struct, ISharedComponentData;
Pretty sure Translation is a IComponentData
Translation is not an ISharedComponentData
Do you guys think this is the culprit ?
I see little gc allocs as well but those are little, generally they are from dispose sentinel, which is native container safety thingie i believe ?
Yeah i guess so, my systems are like this http://prntscr.com/r6whyo
every frame
yeah... well.. i will figure it out later on
Alright i figured it out, i was doing RequireSingletonForUpdate on OnUpdate, which increases allocation every frame, i moved them to OnCreate now
disable auto world creation, create your world yourself and World.Update()🤔
Does anyone use archetypes? Trying to find a reason to use them at all. Can you store certain types of archetypes somewhere for creating entities later? How do you store and reuse these things?
EntityArchetype is a struct you can park in your job systems, sure. Creating an entity with a specific archetype up front is more of a performance optimization
rather than copying the same entity data around across a few different archetypes/chunks, you can park it in the correct spot up-front and fill out fields
it's very similar to the difference between using a default struct ctor and changing specific fields and writing a custom constructor directly
It maybe makes finding the appropriate chunk easier i think
If you're constructing a lot of entities it can actually make a noticable performance difference. It saves you from having to make a bunch of structural changes in a row which can be slow if you're doing it a lot.
Okay thanks guys. Just find it confusing because you cant use the same archetype in multiple different scripts since its a struct correct?
structs just mean all the fields move as one unit
it's a big ol blob that gets copied around
okay cool thanks.
look up reference and value types for the long version
Yeah my mind still gets stuck in OOP sometimes :/ tbh just got comfortable with OOP now switching again haha
the real reason most everything is a struct has to do with garbage collection
structs are value types and get copied around/inlined in other structs, classes, whatever that holds them
since they always follow around the object that contains them, there's no need to figure out if other objects have fields that point to them every so often
(i.e. your garbage collection stall)
this can get real weird with structs that to hold on to outside memory, like the NativeArray family
but that's why Dispose() exists and you should use using() wherever you can
the Dark Legacy of C++
Yeah I wish I learned c++ before I started Unity coding so I'de appreciate how much easier this stuff is. Thanks for your help
I wouldn't say it's easier, necessarily-- just that in the C++11 spec the standards committee killed it with move semantics and making ownership visible to the type system. 😄
EntityManager.Instantiate(myGameObjectPrefab);
Is this not supposed to convert all rigidbody, collider info into the entity it's creating?
Created entries have no components attached at all?
For an example of creating an entity from a gameobject
Oh, okay let me try
when using SubScenes is there a best practice for their size? is it better to do one building per subscene or can I do larger scenes and it wont matter
Hi. I'm having problem understanding ECS when it comes to nested objects. For example if I have a character (Entity), that holds a Gun (that also is an Entity?) and the gun has component Color (green, red, yellow, etc.). And then I want the system to work on all Characters that have a gun in green color. How would that work? Does the gun act like like a Entity and Component is same time? Or .. how? 🙂
do an IF check for the specific color inside the system? im a newbie so may not be the best option
Entity is just an index to some table 😅
You can either do what Doom suggested - which is a totally fine way to go - or use SharedComponentData to forcibly separate your entities by chunk. Then you use filtering to only run on entities based on their SCD values. https://docs.unity3d.com/Packages/com.unity.entities@0.6/manual/entities_job_foreach.html#shared-component-filtering
Which is better depends on the use case
yeah do it the other way if possible, I heard IF statements are causing a lot of bottlenecking in systems unless I misread
wouldn't it be better to use different components for different colors, if he wishes to query them separately?🤔
there are different approaches i tried so far, it looks like simply holding the reference to the "character" entity within the "Color" component is a good way, if you just want to read something out. You can access the Character Entity with GetComponentDataFromEntity<TheComponentYouWantToAccess>[characterEntity].
the easiest solution i found so far for writing into "3rd party" components is the EntityCommandBuffer, but it nulls every part of the component you do not set on usage, so the datadesgin needs to be build for that.
if you plan to have a system that does something for all characters with a green gun, i would create a component on the character that holds the reference for the gunEntity, which is easily readout via GetComponentDataFromEntity<GunColor>(gunEntity).color
https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/component_group.html
Using different components is equivalent to using SCD value. SCD makes more sense to me than having a separate component for every single color
anyone got an opinion on SubScene size? keep them as small as possible or?
but i think he asked about ECS in general, not for specific use case🤔
Entities
.ForEach((ref SomeCharacterComponent a, ref Gun gun, ref Color c) =>
{
But I can't do that, as Gun is not an component
What you suggested is a lot more complicated, and imo probably not the right way to approach ECS. That's very much an OOP way of thinking about it
You wouldn't write a query that looks for an entity that contains other entities. Your queries operate on flat entities only
you process the gun totally separate and have it reference the character entity
in the end it really depends on what you want to do and what other dependencys are really needed
I guess you could have a "HasGun" component that gets added to any entity that is holding a gun. Then you can pass in a ComponentDataFromEntity to your job that can access the Gun entity from your base entity
@safe lintel but I want my system to work on all Characters with a GUN that has color component.. so what do i?
couldn't you do IJobChunk for it? again I may be talking out my ass
@urban remnant I would use tags for that
tags?
https://forum.unity.com/threads/complete-game-project-dots-of-the-dead.759323/ try to look at this project🤔
I have just been using cdfe and usually a component that stores the entity of the owner(player or npc) and some bool on firing(say PlayerInput or NPCInput), so the gun system gets the status of firing, if so fires a projectile and does particle effects etc
or at TinyRacing project
I guess you could have a "HasGun" component that gets added to any entity that is holding a gun. Then you can pass in a ComponentDataFromEntity to your job that can access the Gun entity from your base entity > this sounds like plan
imo getting the chunks of another query is overkill for this situation, esp if you are doing chunk within chunk iteration. gets messy
var gunDataFromEntity = GetComponentDataFromEntity<GunData>();
Entities
.ForEach((Entity e, in Inventory inv) =>
{
var gunEntity = inv.gunEntity;
var gunData = gunDataFromEntity[gunEntity];
}).Schedule();
That's more or less what it would have to look like the way you're describing it
can confirm thats a thing
keep in mind doing that is slow-ish on unity ECS
GetComponentDataFromEntity is fairly slow-ish with how unity ecs works
so you should try to minimize this cases
I'm trying to think of a better way to do it but it seems like the right way to go if you want to keep your guns separate from the things holding them
not like you will have 10.000 weapons tho 🤔
dont restrict yourself because of it tho
I mean you just need random access at some point right
its pretty useful
yeah
@zenith wyvern the downside is, that Im requesting all Charterers that have inventories, but no idea if Gun is inside.
Yeah, that's where the if comes in
I wouldn't worry about it unless you're talking about like thousands of these things
yeah even if commenting slow-ish, its still faster than GetComponent on old unity
and only slightly slower than accessing the a cached reference
@vagrant surge whats technically the best alternative if you are going for the most optimal speed?
@urban remnant Remember you can check if an entity == Entity.Null and you can do ComponentDataDataFromEntity.Exists()
Why is a cached reference anywhere near as slow?
@vagrant surge hmm.. and what do I do with weapon entityID ?
@safe lintel only use the linked stuff (random access) when necessary. Thats prety much it
@urban remnant access it when you do things like shoot
@magic frigate while a raw C# reference is significantly faster than unity ECS random access, unity ecs random access will run bursted and multithreaded, so it balances out
@vagrant surge is this like a built in feature, that every Entity has an ID?
for something ive seen, a ecs random access is about the cost of 3-4 random accesses by pointer
Ah. That makes sense
An entity is literally an ID and a version
Entity is an ID 😅
Ahh
the hard part of the entiy access is that you need to search "where" its stored
so you generally have to grab chunk (access 1), then grab archetype (access 2), then find the componentID offset from the archetype (access 3?)
you can still do several hundred thousands of those per frame at 200 fps, so dont bother that much unless you are trying to push entity counts 10.000 +
Somhave I have hard time fallowing this all. I created a thread in forum > https://forum.unity.com/threads/need-some-help-with-understanding-ecs.834814/, if you could post some solutions with code snippets I would greatly appreciate it. In mean while will try to get my head around this on my own 🙂
just look at working samples like DOTS of the Dead or TinyRacing example🤔
Tiny racing is actually a crazy good demo
its super easy to understand because the entire thing is built from small systems with 1 foreach or two
Where can I get it?
Pinned links in this channel
it's pinned in this channel: Project Tiny Sample
this is DotsOfTheDead https://forum.unity.com/threads/complete-game-project-dots-of-the-dead.759323/
ehh.. ok
Looks like a powerwasher
erm, what did they replace Time.DeltaTime with?
It still exists?
warning CS0618: 'TimeData.time' is obsolete: 'time has been replaced by ElapsedTime
so i replaced and it didn't work....weird
I'm not sure about TimeData, but you can still access Time
float deltaTime = Time.ElapsedTime; ?
var deltaTime = (float)Time.ElapsedTime;🧐
oooh I thought (float) was supposed to be the actual float name 😂
So my fps in built game drops from like 150 -> 30 in around 5 minutes without doing anything. Anyone got any tips how I can find what is affecting it? Using DOTS NetCode, Physics ..
try the profiler
you should be able to narrow down whats causing the bottleneck, just open the profiler and start recording, then play until the FPS drops
then check in the profiler what caused the spike, it should at least put you on the right path
the Entity Debugger could also help, not familiar with it yet though
@mystic mountain Did you also check in a build vs in editor? Editor usually has a lot of overhead
yeah, editor I don't get over 15 fps xD
I would hunt down and eliminate those bottlenecks, if you dont do it as you go it can cause massive problems later on with the workload required to hunt it all down
I don't really know how I should interpet the profiler though, I see I have a system which takes takes up a decent amount of computation, this https://pastebin.com/RRLvgALz. It looks like it's mostly idle though ...
to be honest I havent gotten into it, theres some YouTube tutorials that show how to hunt the stuff down, check those, I dont want to give you bad information considering my level of knowledge
When doing performance optimization, the profiler is really your best tool
Learning to use that is vital
Is the ForEach inside a JobComponentSystem bursted by default?
yes
why the hell is float targetHeight = Mathf.Sin(Time.ElapsedTime * floatSpeed); giving me error CS0103: The name 'floatSpeed' does not exist in the current context....
... is this in a Entities.ForEach lambda?
yea
did you declare it within the parent scope of the lambda?
you mean here?
Entities.ForEach((ref Translation translation, ref Rotation rotation, in MovementData movementData) =>
within the OnUpdate basically.
oops you mean protected override JobHandle OnUpdate(JobHandle inputDeps)
Yes, you need to declare it within that scope afaik
ah, so get the value, then use the value, instead of pointing straight to it
Does the new unity physics count to the dots channel or the physics channel?
I'd say it works as both - ppl ask dots physics based questions here
Are there any known issues about raycasting and colliders havent found anything on the net yet
oh I'm not sure I have barely touched the Unity Physics package but someone else here might know more lol
okey thank you though
not sure about colliders but there is little bit setup you have to do for raycasting
let me find the forum topic for you
Im able to do the raycast but there is just some confusing stuff happening
such as ?
hitting a collider but not registering
do you have phsyics shape in your entity ?
Tried physics shape and the normal box collider
how do you know that you are hitting it if it is not registering?🤔
Possible to undefine UNITY_EDITOR in editor? ._.
probably its filtering then
both raycast and your entity needs to want to collide with each other
Let me try to record a short vid
please post your script as well
Are you also converting the cube into an entity with a PhysicsBody and PhysicsShape?
You mean by converting attaching the PhysicsShape right?
No I mean converting it to an entity
add a ConvertToEntity script
Yea i have them as convert to entity
ConvertAndDestroy
I dont have a PhysicsBody but i think i tested it with one attached.It didnt change the behaviour
I'm a bit unsure why that's happening. What are your LiveLink settings? It's in the DOTS menu up top
Live conversion in Edit mode and SceneView: Editing State
Try setting it to Game State instead of Edit state
Same behaviour
Try setting the bevel radius up a bit? 🤷♂️
Do you also get the same behavior if you move the cube somewhere else?
Oh, I think I know what it is
When you invoke your Raycast method, you're supplying it with ray.direction * 100
But the actual physics raycast doesn't take thee direction, it takes the endpoint
So you need to give it ray.origin + ray.direction * 100 instead of just ray.direction * 100
So Raycast(ray.origin, ray.direction * 100) beecomes Raycast(ray.origin, ray.origin + ray.direction * 100)
Oh.... Wow thanks for the sanity check that fixed it.
Is there a reason that it doesnt take in the direction like the old raycast did?
Probably some performance stuff, not sure though
But I'm fairly certain the old one had overloads for both a direction and an endpoint
also note you cant (yet) ignore self hits if your raycasting from an entity that has its own collider
Well if you configure the filter correctly it'll be fine
does NativeSetThreadIndex work when nested or does it have to be in the outermost container for a job to inject a value?
What is the size limit for ecs component?
There are new netcode and transport packages now
@twin raven the entity has to fit in a 16kB chunk, so in theory you can have just slightly under 16kB component
needless to say that's probably not the best idea
Thanks. I have a NativeMultiHashMap that is created in the beginning of the frame that multiple jobs need through out the frame. I don't have an idea how I would access that from the jobs without ugly code and dependency hell.
But if I got it right, NativeMultiHashMap can't go to ComponentData. I just wish I could access it readonly in Entities.ForEach
@twin raven You could use a dynamic buffer for this
They're array-like structures of components, where you can define what info the structure contains
Of course you wouldn't get the nice benefits of the hashmap with key/value pairs though
Which might be a problem of course
The NativeMultiHashMap is kind of a look up table for entities based on spatial hash.
You can just expose the hashmap as a public field on the system that prepares it, and then GetSystem<InitHashmapSystem>().MyHashmap whenever you need it
Oh ya lmao, why didn't I think of that
(cache the GetSystem() call in OnCreate)
Oh right, will that make the dependencies automatically so update order is right? Or do I need to use [UpdateAfter] etc attributes?
@worldly pulsar Does OnCreate run after all systems have been created?
@bright sentinel no, sorry, in OnCreate you should use GetOrCreateSystem()
Ah right gotcha
@twin raven I think you still need to manage dependencies, but you can just run the system that needs to run first in an early system group
And that should be fine
## [Netcode 0.1.0-preview.6] - 2020-02-24
### New features
* Added integration with UnityPhysics, including the lag compensation from DotsSample. To use it you must have the UnityPhysics added to your project.
### Changes
* Unity Transport has been upgraded to 0.3.0 which required some API changes - see "Upgrade guide".
* All `FunctionPointer` instances are cached in statics to reduce the number of calls to compile.
* The helper method RpcExecutor.ExecuteCreateRequestComponent returns the entity it creates.
* Added an interface to NetworkStreamReceiveSystem which is used when creating the driver. It is possible to set NetworkStreamReceiveSystem.s_DriverConstructor to a custom instance during bootstrapping to create drivers in a custom way.
* Removed World.Active workaround since it has been deprecated for a while and is causing problems with conversion at runtime.
* Slightly improved performance by ensuring that all jobs that can be Burst compiled are
* Ghost types are now selected based on the guid of the ghosts prefab asset instead of the archetype. This makes it possible to have multiple different ghosts with the same archetype. If a ghost is not a valid prefab you will get an error during conversion.
### Fixes
* Fixed an issue where ghost prefabs created from GameObject instances were processed by all systems.
* The code gen now only writes files if they are modified.
* Disposing a client or server world will now unregister it from the tick system to prevent errors.
* Take the latency of command age updates into account when calculating time scale to get more stable inputs with high ping.
Or after BeginSimulationEntityCommandBufferSystem
@dull copper Where'd you get that? 😄
from new netcode package changelog
🤔
the website version is always behind
they ship the changelog along with the actual package
Ah, I see, thanks
the changelog is also in MD format, so it's easier to use it if one pastes parts of it here as discord can do markdown formatting 🙂
considering it's never going to be supported by the netcode package out of the box, you should not
@dull copper wym, its already supported
they handle connections for u
like what else support
you need
i wonder if it can handle more connections than Mirror
and with less ping
i checked dots game exported to webgl to my webhost and it took only 10-15% gpu
while my object based game took like 30% gpu
so making game in dots would be cool..
like i could spawn MOREREMOMOMROEMROERE objects and still have low gpu and cpu usage and nice fps
but then need to get this netcode thing working
You already have a game designed that requires that many connections and that many objects? That kind of networking in a game is usually reserved for projects will funding and staff... if you are just doing this as a hobbyist - you might want to back up and rethink that?
I can't recommend against that strongly enough, but if you are determined to do that - go for it.
nothing better in cv than mmorpg with 100 players
@gusty mulch ye thats what everyone says but i disagree
where are you going to get those 100 players though?
you could even make multiplayer game in a day (though not an mmo(RPG)) and the complexity depends mainly on gameplay and not on making it all networked
cost of acquisition is expensive
@gusty mulch i will get them manually
i have about 50 visitors to my site daily by now
all human and unique
Can I ignore hickups in my profiler caused by the Editor Loop? I made a third person Camera and I notice that sometimes the Editor Loop takes 50ms and when that happens everything in my game seems to teleport, almost stutter. Moving all my camera movement stuff into Fixed Update didn't help that either. I followed the following thread and tried the CustomBootstrap. https://forum.unity.com/threads/unity-physics-runs-at-diffrent-speeds-depending-on-editor-game-window-size-and-if-its-a-build.804171/#post-5455503
But as stated, doing so just increased or didn't change anything.
I guess a general question is, should I keep player movement stuff in Update? I don't use physics and I don't know if I will use it in the future.
You sound determined. Best of luck.
y thnks
@formal scaffold - there might be a late update like in normal unity you can move you're camera logic too, as generally you want to do camera tracking/movement after everything else has updated and animated, but before rendering
Physics doesn't run at a different rate. Not going to read that post but that part is definitely wrong. How many times its runs per update will vary based on fps... but the fixed timing is the fixed timing.
Typically the best practice is do your game logic in the fixed, and interpolate the results of your simulation in Update().... same as what PhysX does
@untold night The strange thing is that I have to update my camera FIRST and then Move or Rotate my objects. Otherwise I see constant stuttering. I don't know why that is but it works.
wierd
maybe you're getting the translation/rotations from the previous frame if that's the case? I know they're working on implementing proper fixed update for SimulationGroup in the near future, I don't think it's dropped yet
oh, this is DOTS related... can't speak to what that mess has going on
bleeding edge hell imo
I grab the Rotation of my CameraTarget(Entity with Translation, Rotation and LocalToWorld) in OnUpdate and change it based on Input.
I can change my camera Rotation and Position before or after that within the same OnUpdate. One stutters, the other one doesn't
Debug.log on those indicates everything is firing in the expected order?
Yeah changing the order within my system changed the order in which stuff is executed. Which makes senese.
As I see it is that if I move my Object first and then the camera the camera will record that change as a jump(stutter) before the camera get's updated.
But that could be said for the other way around aswell, so I don't understand. Took me a week of hard thinking with no answer. Maybe someone smarter than me understands this 😅
GuyS shoUlD i reMakE my MmoRpG in NeTcoDe
If you like a challenge... go for it.
@formal scaffold Hard to say without the full context but all I can suggest is to look at the order of your systems in the entity debugger and try to think about what's actually happening in each step as the systems update. Sometimes you might find you need to do things that might seem non-obvious, like moving update code to happen before spawning code
Try to avoid just shuffling the update order around randomly and hoping it works, think about what's happening at each step and figure out how it needs to be ordered to get the results you want
oh is SystemBase the replacement for both JobComponentSystem and ComponentSystem now?
yes
re: NetCode and MMORPGs above, can you guys elaborate on what specifically the shortcomings of the NetCode package are?
I'm new to game server programming but well versed in concurrency and server architecture. Seems to me like many of the issues with concurrency could be solved by localizing workloads based on chunks + providing steams for several LODs
The concepts behind netcode are sound, its just that DOTS for the expected future makes what used to be basic programming tasks crushingly difficult. If the bugs finally all get cleaned up, the API stabilized, and the ugliness of the DOTS code can get tucked away out of site of the average user... it will be great.