#archived-dots
1 messages ยท Page 106 of 1
From the sounds of it it's many months away before it will be integrated with dots
yep, but that shouldn't really matter when it comes down to it
I would keep an eye on Project Tiny to see how they handle UI
you just use the old ones and make due with simple bridging
Don't look at megacity
also don't look at project tiny either ๐
that thing keeps making even more u-turns than DOTS
did you look at the fantastic hello cube and what not in the samples
yeah i took a look to hello cube ๐
and the physics examples in the same repo
thats pretty basic tho
The UI isn't going to make a particularly big perf impact unless you royally screw something up, so just do it the old way and query any relevant entities from mono-land. As a bonus that should make it easy to transition to their ECS versions when that time comes.
If you mean learning general ECS concepts in terms of a full game there's not much out there from Unity
well the physics examples are really not DOTS samples
aye but you only need basic tools when you learn ecs
they mainly interacts Unity Physics through monobehaviours there
that combined with playing around and learning in the framework
and read the DOD book!
I wish they actually had DOTS samples for physics there
that DOD book is so boring ๐ญ
Well, here goes nothing: time to upgrade my ECS sandbox project from Entities and hybrid renderer 0.1.1 to 0.5.0 and 0.3.2, respectively.
that dod book was one of the lighter book and whitepapers I've read lol
damn ๐
Those things are crazy dry if you're not used to them, though. They'll fricking desiccate you if you're not careful
yeah but i mean it kinda feels like.. it explains the foundation of how should data orianted system should be implemented such like Unity's ECS, i.. dont know how it will help me understand stuff on higher level instead lower level
Yeah I have a hard time reading it too, I'm not good at pure technical reading
when you get a bit further along it talks about things like "existence based processing"
and the section on "dont use ifs"
both of these apply to ecs a lot
But what if...!
gasps He said the word ๐
yeah i will check it out thanks, i read the database section of it(first section) and it was.. boring and it generally told how things work instead of how can i get advantage of it
but in time i will read it
you could skip ahead if it gets dry like that
the database section helps understand how ecs is structuring your chunks and selecting / sorting them
So i was wondering, how you guys use sharedcomponentdata, systemdata and jobs for chunks ? I have hard time understanding their advantage, in a world of tag components it seems shared component data is useless since it sits on a chunk(right ?)
SCD just lets you group related components, whether you want to force them into certain chunks or in my case I wanted to have a single point of access to a NativeArray based on it's position in the world
The problem is they are really awkward to use and you can't use them directly inside jobs
you can
and the downsides are that it fragments your chunks causing you to use more memory and less per chunk
but doesnt SCD sits on a archetype ? how will you be able to use it if you put a tag component ? Like i am using tag components to drive simple AI, how can i utilize SCD in cases like that
I had to use them to pull off a complex system before dynamic buffers came out
Maybe it's changed, when I was doing blockworld you definitely could not use a SCD inside a bursted job
let me check if that job is bursted
ah well shit
deleted that system a long time ago
cant remember the exact name to pull it out of the repo
@opaque ledge https://docs.unity3d.com/Packages/com.unity.entities@0.5/manual/shared_component_data.html If you're curious about it
Huh, just 8(4 pairs) deprecation warnings about World.Active in the sandbox project. And two of those is from a conversion utility I made...
Time to brush up on the conversion workflow
yep
Nevermind, two nullrefs and a burst error about function pointer when trying to enter play mode
...this will be incremental

Sorry to break up the flow guys but is there a way to do a "method" in a burst job? I am trying to not copy paste the same code over and over to do the same output
do you use something like:
{
//do jerb
});
if (otherComponent.boolValue)
{
jerb.Run();
}```
static function
or just a member function of the job
in a lambda you would likely need to convert it to a job struct at the moment to have member functions
Examples:
struct SomeJob : IJob{
public void Execute(/*...*/);
Method(1);
HelperClass.StaticMethod(2);
}
//member function
void Method(int arg){
//...
}
}
public static class HelperClass{
//Static method
public static void StaticMethod(int arg){
//...
}
}
yep that looks good
Alright, so the way the sandbox project is set up, it had a gameobject, which it converted. From that it grabbed a RenderMesh as a shared component, to use with a predefined archetype...
Looking at the samples, I feel like the more appropriate way would be to just make a ConvertGameObjectToEntity prefab and conversionSystem.GetPrimaryEntity(Prefab).
If I understand correctly, this will convert it behind the scenes at compile time, so only once, and I can use the normal 'entity prefab' method to create variants of it?
Is this correct?
@low tangle when i asked about bridging ECS and Monobehaviour you mentioned system data, can you give me an example so i can learn from that and implement my bridge ?
if it isnt secret or anything ofc ๐
@low tangle and @tawdry tree Thanks!
well, theres nothing really secret about it, AddComponentObject on a entity with any mono compnent
this is for keeping track of a linked gameobject so you can destroy it when a entity is deleted
some older systems work the other way around and the monobehavour link manages the entity and delete it when they are destroyed
@low tangle Anything on my Q?
yeah thats correct
it wont convert behind the scenes though
it would have to be in a subscene
what you will do in this case is have a convert to entity on it, which does it at runtime on the first frame
its async but its important to know when it happens
it will just give you the prefab entity you want that you can then instantiate
you could also do it on a gameobject in resources / ref'd somehow and run the converter directly
var ent = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, new GameObjectConversionSettings {DestinationWorld = World.DefaultGameObjectInjectionWorld })
I already added the convert to entity script, and it shows up as an entity in the debugger (and visibly). I really just want a reference I can clone, somehow, and looking at that old code of mine.... Oof, old ECs code is hacky!
just fat names
personally I just do this above when I was creating my prefab entitys
start of the system, grab the prefab go, convert it to a entity, add a 'Prefab' component on it so its inert
then instantiate away
Active part of old code:
var protoEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(proto, World.Active);
var result = World.Active.EntityManager.GetSharedComponentData<RenderMesh>(protoEntity);
Object.Destroy(proto);
World.Active.EntityManager.DestroyEntity(protoEntity);
That's from my "EcsUtilities" helper class, and the method takes the name of a gameobject and returns a rendermesh from it
ah yeah, just add the prefab component and keep the source entity around
It doesn't like World.Active, though, and also this is in a static helper class - ideally the system does this
World.DefaultGameObjectInjectionWorld
they renamed it so people dont get it confused with the ComponentSystem.ActiveWorld or however it goes world ref
Know what IDeclareReferencedPrefabs does? The docs are not very helpful...
Yeah, the deprecation warning suggests to use that
its used by the normal conversion system for linking up the declared extra gameobjects to convert
yep
What's the name and namespace of the prefab component?
Oh, it's literally just Prefabin Unity.Entities.... I feel silly now
Entities.WithAll<SomeIBufferElementData>().ForEach((Translation2D _trans, Entity _e)=>{
DynamicBuffer<SomeIBufferElementData> buffer = EntityManager.GetBuffer<SomeIBufferElementData>(_e);
//buffer.Length can be 0
})
How do I use Entities.ForEach with DynamicBuffers? Shouldn't it not run if the entities don't have any elements?
Oh I just realized that I can use the dynamicbuffer in the inline function
Entities.ForEach((DynamicBuffer<ActiveTarget> _targets, Translation2D _trans, Entity _e) => {...
I guess I just check the size and remove the dynamicbuffer if it is not needed
I think this is called Rubber duck debugging ๐
so for Convert and Inject GO to work, I can't use dots subscene, so I'm again back in the starting point with no entity conversion preview ๐
it's such a small thing but it would be awesome if it would just work
โ
Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=1bO1FdEThnU
Let's implement Pathfinding in Unity DOTS, we're going to write everything in a Data Oriented way (Structs) in order to benefit from massive performance!
A* Pathfinding in Unity
ht...
this is literally insane
this changes everything
0.1ms is pretty high for that single grid (didn't watch more than a second)
thats likely just the job startup cost + tiny bit of work
in the comments though he makes a good point, that's a unoptimized dots solution vrs a the same in oop. so even if you are not that 'good' at dots it will still be faster.
he had 700ms on regular monobehaviours, which is totally weird comparison as that example was totally unoptimized
yeah that was intentional
lazy case vrs lazy case
instead of splitting hairs on the best possible oop version
which really just ends up being a microcosm of memory management and its totally opaque
I dont like wasting time writing defensive code (at least in games)
Is unity making some sort of dots pathfinding? Or are they extending navmesh?
Not that I've heard of. Seems like there's plenty of other important stuff they want to finish first
dev in the forums posted that they are starting it this year so i expect it wont be available for some time
This post seems promising for navmesh in DOTS: https://forum.unity.com/threads/navmeshquery-in-a-ijobparallelfor-impossible.632008/#post-5418927
Says he will likely replace this with whatever Unity comes out with eventually.
I believe you cant acess Unity API methods in job structs you need to get them in component system and send it to job, so something like
float delta time = Time.deltaTime;
var job = new MyJobs{time=deltaTime}
return job.schedule(this, inputDependicies);
Dont forget to make a public float field in your job struct
ooh thanks Olento
did they release new burst ?
ah i see, getting debug.log will help ๐
## [Entities 0.5.1] - 2020-01-28
### Fixed
* Constructor-related exceptions thrown during `World.CreateSystem` will now included the inner exception details.
* Fixed an issue where `BlobAssetReference` types was not guaranteed to be 8-byte aligned on all platforms which could result in failing to read Blob data in components correctly on 32-bit platforms.
* Fixed issue in MinMaxAABB Equals() comparing Min to itself rather than other.
* `Entities.ForEach` now properly treats `in` parameters of `DynamicBuffer` type as read-only
* Fixed potential crash caused by a leaked job after an exception is thrown during a call to `IJobChunk.Schedule`.
* `DefaultWorldInitialization.GetAllSystems` now returns `IReadOnlyList<Type>` instead of `List<Type>`
* `DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups` now takes `IEnumerable<Type>` instead of `List<Type>`
### Changed
* Updated dependencies for this package.```
oh just fixes then
rest of the package updates (jobs, collections, hybrid rendering) are just dependency updates
so yeah, just a hotfix apparently
i probably should look into blob assets
Same here, still haven't touched them
Huh, did they not fix the singleton bug?
Hopefully they just didn't mention it
what is the singleton bug
In 0.5 GetSingleton causes a singleton to be spawned every frame apparently
i had a singleton bug where it keep querying it every frame, so it would query 1000 times
ah yeah, that doesnt happen to me anymore
it.. was fixed when new burst was released for some weird reason
hybrid got a update too
Just dependency update it looks like
man I dont know if I can do this minor update
never know if its going to break with il2cpp
Do you guys think there will be new stuff added ? seems like most of the foundation is already implemented, i feel like they will release fixes from now on
Definitely. Apparently there's a big update coming for Hybrid Renderer in particular
it aint the last either
And I'm looking forward to expanded API on Foreach
i mean, i am talking about entities package itself
rendering will be the longest ecs package imo
anyone using visual scripting ?
oh you know, i had a question about that, what is the difference between doing Entities.ForEach and IJobxx structs ?
The ForEach literally generates the IJob code
so it doesnt matter then ?
JobForEach<T1, T2>
i mean no difference
it does matter
It matters because the ForEach is way more readable
it saves you time
And yeah, easier to write
idk, i generally use IJobxx, it makes it more readable for me and more maintainable
accessible
but thats only me i guess ๐
you shouldn't shy away from a tool for the sake of it
but I typically do all jobs in one yeah
only my main thread stuff in lambdas
can you do double query in ForEach ?
nah you cant
and 100% no in a job
jobs cant run other jobs
you could ofc create a raw job and get all the up front chunks and do all the iteration yourself
but if you need it that bad, you really need to stop and rethink your logic
nope, i use 1st job to get i want and use the results in 2nd job, so no nesting
thats the correct way to do it
list, array, hash
whatever makes sense
updating all the packages now and crossing my fingers
๐ค๐ป
which brings me to a point, when you layout jobs in sequential order, like Job1 depends on input dependincies, Job2 depends on Job1, Job3 depends on Job2 etc.. will this system run if lets say Job3 or Job2 has 0 entities to process ?
gl ๐ ๐ค
isnt that kind of a waste
no
think of it this way
if you call .complete what happens to a job
runs till its done right?
put one that goes before the other, it will do the first then the second
all the way up to n
you jobs are all getting called .complete by the scheduling system
I doubt you need to worry about the overheard of a job whose query has no entities running in the middle of a chain
the job structure under will basically early exit since there are no chunks to iterate on
Yeah but shouldnt underlying system know that all of the jobs that depends each other wont be able to run so it shouldnt let system updaate ?
the job itself describes the conditions to run, not the job before it
i mean same goes with GetSingleton, system runs because i am retrieving it but my job has 0 entities so it wont update
I'm not sure...but again, don't worry about it. Until you actually see a performance problem just write your code so it's easy to understand.
Worrying about the overhead of an empty query is almost definitely a premature optimization
yeah i understand, its just annoying, and makes me think my system is running even tho it shouldnt run at the time
IJob = none
IJobParallelFor = 1-n with m numbers per thread/job
IJobChunk = will run a thread/job per chunk that matches the query archtype
IJobForEach = a jobchunk that runs a function on each entity within that chunk
ah you know i was going to ask about that
(such a surprise right ๐ )
so i have my 1st job retrieving some entities and write to a native array, and my 2nd job is IJobParallelFor and simply calculates stuff for each of these entities
But the thing is i cannot know how many entities i have got because i cannot use native list in 1st job since it cannot be written in parallel after its' length
so i cannot give the proper container size to IJobParallelFor and i.. simply give like 100 or smth even tho i have 20 entities to process
any advices ?
Why can't you use a NativeList in the first job?
because its parellely writing, if my list has 5 items, 6th iteration wont be able to do list[5] = value, so it access to it as a native array and not really a list
and if i initialize some items in this list to contain all of those entities, since i dont know how many entities there will be, i will simply initialize arbitary number of items meaning i will still not know how many entities i processed
It sounds like you might need https://docs.unity3d.com/Packages/com.unity.jobs@0.2/api/Unity.Jobs.IJobParallelForDefer.html
There's not really good documentation for it yet, let me write up a small example
jobs 0.2.3 version ๐ ๐
ah wait, nvm, i actually dont know what is the most recent version of jobs
i confused it with burst, so i was surprised lol
and thanks
ah i see, so there is a second method to calculate size which we can override ?
i will try to implement one when i am on my pc
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var ints = new NativeList<int>(Allocator.TempJob);
inputDeps = new IntJob
{
ints = ints
}.Schedule(inputDeps);
inputDeps = new Reader
{
deferredList = ints.AsDeferredJobArray()
}.Schedule(ints, 32);
return inputDeps;
}
struct IntJob : IJob
{
public NativeList<int> ints;
public void Execute()
{
for (int i = 0; i < 500; ++i)
ints.Add(i);
}
}
struct Reader : IJobParallelForDefer
{
public NativeArray<int> deferredList;
public void Execute(int index)
{
int val = deferredList[index];
}
}
Not tested but that should be pretty much right
ah i see, so it just calculates how many items in there on its own, thanks
how to fix this error ?
what is the error
i cant see ECS graph
I haven't messed with the visual scripting thing at all sorry, you might try asking in the thread for it on the forum
i already did
it says on the unity console that your scripts cant be compiled because there are some errors, you need to fix those issues first
i think unity isnt simply compiling the visual scripting package
yes i cant understand the error
if you can take a screen shot of those errors maybe we can help
All I can suggest is to make sure you're using the latest unity version (2019.3.06f) and try deleting your library folder and restarting unity
that actually looks like its not been updated for entites 4+
which is where the Time change came from
go to your package's folder edit the line it talks about
if its in the package cache you will need to move it to the package folder
yeah its in the cache
move it
yes
now go in there and fix the time errors
your gonna need to figure this out yourself
btw, in some ecs codes i see inject attribute inside job structs, is that still a thing ? if so what does it do exacttly and how can i use it
i am stuck at this now
How do I debug while using the burst compiler?
I get Burst Error: Loading a managed string literal is not supported
more detailed - I'd like to debug during a Job
yeah it isnt supported yet, i heard UnityEngine.Debug.Log will be supported on next burst version
simply remove burstcompile attribute and call Debug.Log i believe
I'm not sure where the BurstCompile attribute is added because it goes back to JobHandle override which is something UNity did
(checking the DOTS sample)
"For strings, we hope to bring basic support for them for the 1.3 timeframe in the case of Debug.Log and also with NativeString."
(1.3 burst)
Unity never promised it'll make it tho
so we'll see
I'd assume you'd also need 2020.1 if you want to be able to use that within jobs
(like you need for debug draws on jobs)
BurstCompile attribute is added to job struct, you need to remove that
I ctrl + F'ed the entire solution for "struct Job" and only found struct JobHandle and it doesn't have a BurstCompile attribute
search BurstCompile then ?
i'll get all though - going through all of them will take too long
or if query is built with ForEach, there could be .WithBurst() as well
the ForEach uses .Run()
nah, its like Entities.WithBurst().ForEach(()=>).Run()
should be something like that
you only need to disable it on the job you're trying to debug
do you know what you want to debug
Entities
.ForEach((ref Ability.EnabledAbility activeAbility, ref Ability.AbilityStateActive stateActive, ref Settings settings, ref PredictedState predictedState) =>
{
updateJob.Execute(ref activeAbility, ref stateActive, ref settings, ref predictedState);
}).Run();
@opaque ledge
@hollow sorrel how do I do that?
and you get the error when you put a Debug.Log here ?
oh if your lambda is in a jobcomponentsystem i think it enables burst by default
need to add .WithoutBurst
there's a function inside the Execute method that debug.log
Entities.WithoutBurst. then?
.foreach(fsdjkgjksdg).withoutburst().run()
yeah
you can also just disable burst from the editor menu for viewing logs in editor
Entities
.ForEach((ref Ability.EnabledAbility activeAbility, ref Ability.AbilityStateActive stateActive, ref Settings settings, ref PredictedState predictedState) =>
{
updateJob.Execute(ref activeAbility, ref stateActive, ref settings, ref predictedState);
}).WithoutBurst().Run();
this than?
@amber flicker that would be easier - where can I find this?
yup Jobs->Burst->Enable Compilation
Just for clarification on the entire burst thing - that won't break any code or anything , right? It'll just make everything load slower? yeah?
that's the idea
Let's see how it goes then. Only needs to finish compiling
so I''ll see ya lads in 2022
Anyone else having compile issues after updating to latest entities package?
Library\PackageCache\com.unity.entities@0.5.1-preview.11\Unity.Entities.PerformanceTests\SharedComponentPerformanceTests.cs(37,46): error CS0246: The type or namespace name 'SampleGroupDefinition' could not be found (are you missing a using directive or an assembly reference?)
I did have an issue where the collections update that was needed, wasn't listed in the dependecies
Did you also update HybridRenderer package ?
yes, I'm on 7.1.8 there
and updating Performance testing API didn't help either
(to 2.0.6)
Collections and Jobs + Burst updated too
Fixed one compile issue in Netcode, but these "you're missing an assembly ref" is not as easy to track down
well, apperantly samplegroupdefinition lives in test framework
maybe try to install/update that ?
thanks, that's a start, knowing where it comes from
hopefully they'll release a Netcode version soon that fixes the IReadOnlyList issue. Silly to redo it every time I restart Unity
I'm trying to parent through code, and visually the objects are close to eachother, but logically it seems they are not?
Translation usually means local space, but in this case it seems it is showing world space for some reason? Have I missed some part of parenting?
i have never tried it but i believe there is a component to handle parent/child relationship
This is my code rn
// Add parent, set position
EntityManager.AddComponentData(entity, new Parent() {Value = parentEntity});
EntityManager.AddComponentData(entity, new LocalToParent() {Value = float4x4.identity});
EntityManager.SetComponentData(entity, new Translation() { Value = math.mul(ltw.Value, new float4(characterTeleportData.teleportPosition, 1)).xyz});
EntityManager.SetComponentData(entity, new Rotation() { Value = math.mul(characterTeleportData.teleportRotation, ltw.Rotation)});
But it is interesting with linked entity group, I have parented other things manually, but they seem to show up in the linked entity group, but not the character
https://unity.com/releases/2019-3/dots-sample
Access denied ๐ฌ
Seems my problem was related in what systemgroup it was run.
Can you not use PostUpdateCommands.RemoveComponent() in Entities 0.5?
I have a component system running with a query, but I remove 1 of the tags from the entity at the end of the update
But in the Entity Debugger, the system is still running on all entities at 3.25ms, but it doesn't show the entities that are being affected?
And in the Chunk Utilization, the entities are still showing that tag that should've been removed
Nevermind, wasn't running it properly
Ignore everything I said
I've no idea why the groups matter though, I'm changing from GhostPredictionSystemGroup => ClientAndServerSimulationSystemGroup..
(edit) I might just be stupid I realize...
Yep, I just hadn't parented on the client, so visually it was wrong ...
How come the BuildPhysicsWorld update time constantly increases, even if the game is idle?
It started out at 0.1ms but over time reached 10.9ms
(Still unfamiliar with ECS, so trying to learn as much as I can)
This is my BuildPhysicsWorld, is it supposed to add Physics Step every frame?
There are some bugs ongoing with current entities package. There is an update now (0.5.1) but the changelog isn't updated, so don't know if it's fixed now...
For me it is, maybe hit refresh packages below
Yeah I did
Hm
I'm using 2019.3.0f6
Nvm
Found it
Had to drop down Entities
That fixed it
There is a small symbol on the right side of the packages indicating there is a newer version
๐
How can I make a Job Component System run only once?
Enabled = false;
Thanks
How can I destroy an entity inside IJobForEachWithEntity<T>, in a JobCompSystem
With the use of a EntityCommandBuffer.ToConcurrent
Yeah I got that
Though don't forget to add the jobhandle to the barrier!
private EndSimulationEntityCommandBufferSystem endSimCommandBufferSystem;
[BurstCompile]
private struct JobTest : IJobForEachWithEntity<MyData>
{
public EntityCommandBuffer.Concurrent CommandBuffer;
public void Execute(Entity entity, int index, ref MyData data)
{
if (data.OnFloor)
{
CommandBuffer.DestroyEntity(index, entity);
}
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
JobTest job = new JobTest
{
CommandBuffer = endSimCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
};
JobHandle jobHandle = job.Schedule(this, inputDeps);
endSimCommandBufferSystem.AddJobHandleForProducer(jobHandle);
return jobHandle;
}
What bit am I missing?
What errors do you get?
you need jobHandle.Complete() I think
Oh null ref on JobTest job = new JobTest
You need endSimCommandBufferSystem = World.GetOrCreateSystem<EndSimulationblahblahblah inside OnCreate
hrhr
You didn't see that ๐ ๐
Yeah I didn't see and just assumed I was messing up the JobForEach instead
And now go and use Entities.ForEach ๐
Instead of the job
How come?
Is there a way to change the layer of an entity at runtime? To have it be culled by the camera for example
@vale nymph Hm, you mean the layer on the RenderMesh? This is a ISCD, so you should not change it. You could disable the whole entity, but exclude only from rendering does not work with the default systems... as far as i know
@silver dragon Sorry for constantly questions, but if I do ForEach, where do I assign the commandBuffer?
private EntityCommandBuffer.Concurrent CommandBuffer;
private EndSimulationEntityCommandBufferSystem endSimCommandBufferSystem;
protected override void OnCreate()
{
endSimCommandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
CommandBuffer = endSimCommandBufferSystem.CreateCommandBuffer().ToConcurrent();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var job = Entities.ForEach((Entity entity, ref MyData data) =>
{
if (data.OnFloor)
{
CommandBuffer.DestroyEntity(entity.Index, entity);
}
}).Schedule(inputDeps);
endSimCommandBufferSystem.AddJobHandleForProducer(job);
return job;
}
Thanks
@silver dragon Thanks for the info. I'll try with disabling the entity ๐
Is the dots editor just extra stuff or does it replace the gameobject workflow?
@stable fog dots editor package basically gives you two things today:
- entity conversion live preview on DOTS subscene objects
- option to add conversion script on nonsubscene objects from the inspectors top area
afaik it doesn't actually change the workflow itself other than giving that mentioned shortcut
nods
well, I dunno if you'd need the conversion scripts on DOTS subscene without it (?), with the dots editor, you definitely don't need the extra scripts there
is there ever going to be a pure dots workflow
The messaging seems to be that Conversion workflow is how it's going to be from here on out
for now, yes
heh, I don't understand it
but they didn't say they totally canned the dots editor
it's just not worked towards atm
I have what is kinda a conversion workflow, but I have a custom editor in my Visual Templates examples for making Entities
I personally expected to have full dots editor by now
its not really a conversion workflow thouhg, you're not creating intermediate objects
They have been pretty clear that the end goal is to have pure entities at runtime
it wasnt particularly hard to do either
We're a long way from that but that is what they're working toward
though it does depend on 2020.1 features, specifically SerializedReference
i think someone else will probably have built a pure dots editor before unity does
Seems pretty likely, I wouldn't want to be tasked with trying to keep up with all the API changes
I almost have a pure dots editor
but you still have to have a GameObject to host all the Entity archetypes
and lol, it looks broken atm...
entity selection someone already figured out https://github.com/JonasDeM/EntitySelection/
entity hierarchy shouldn't be too hard to make since entity debugger basically already has that
and i think someone also made a prototype of entity inspector that lets you edit values
oh thats way more useful than what I have
I can just make and define entities in the inspector
without using monobehaviors
well, without intermediate monobehaviors
yea
I think a big problem right now is there's no good general purpose solution for rendering entities
ran into a bug with iterating over serialized properties
oo i saw that, looks good
But I guess we can expect hybrid to get better so there's no harm in using it
I only developed it as an example/test for my uielements lib
It seems like the existing conversion workflow does exactly what you're doing there
With [GenerateAuthoringComponent]
Unless I'm missing something
in the conversion work flow don't you have to create monobehaviors to represent your componentdata?
GenerateAuthoringComponent does it automatically
But you are restricted to one per file which is pretty annoying
generate authoring data automatically creates your ComponentData?
It creates a monobehaviour version of your existing componentdata
ah
yes
With fully editable fields in the inspector
yeah, in a sense I suppose
but for buffer types you have to implement your own authoring
But you still need a monobehaviour
Yours has a nice benefit of being synced at runtime I guess
and if someone consumed this project,t hey'd have to create none
just put [GenerateAuthoringData] on your IComponent and drag it to your gameobject
That's possible to do with conversion workflow but very annoying
eh, well its not necessarily synced at runtime
i think it's weird they decided to codegen seperate monobehaviours for conversion, what twiner does seems a much better solution
codegen isn't free
its more that this is a archetype manager with default settings
so the idea was you pick "prefabs" from the manager
and instantiate them
there is very likely problems, it not like a completely thought out project, it was more just a test of my VisualTemplating system
I think they are working on making it less restrictive, so you could have multiple per file and hopefully let it work with types other than IComponentData
multiple componentData per file?
I don't understand why you'd want that tbh
it just creates a situation where you have to eventually deal with a weird organization issue and start breaking apart your files
I usually have one per file, but I can see a case for wanting to group related components
thats called a folder/namespace :p
i tend to put multiple components in one file too
navigating folder tree is more work than scrolling a file in vs
usually don't even have to scroll if your components are small
Ctrl+, type name of class/struct/whatever, enter
Assuming you're using Visual studio that is
but I'd hope whatever IDE you're using has such a feature
What's an efficient way to get all entities in a given radius
If I have 20k entities for example
And I just want to get all the entities that are say 1uu around it
I'd say typically - in a general sense, building a data structure for regions (like octal trees) helps with this - usually used in broad phases of physics frameworks ๐ค
Imo: Lvl1: ForEach() check distance, Lvl2: Physics SphereCast (I assume there is such a thing, not played with Physics yet), Lvl3: Spatial data structures, Lvl4: Check Unity physics source, Lvl5:....
what does memory layout look like with dynamicbuffers? it always allocates as much in the component as internalcapacity is set to, right? like if you set it to 8 but it only has 2, there will just be 6 empty spots in memory per component
that's my understanding, yup
makes sense
I think there's only the latter
I dont suppose anyone knows how you use the new input system in DOTS?
I'm using these in start running which is what I was doing in a mono behaviour csharp inputAction = new PlayerInputActions(); inputAction.PlayerControls.Move.performed += ctx => movementInput = ctx.ReadValue<Vector2>();
but it doesnt seem to work
i haven't used it but that looks like you're trying to assign a delegate event
prob better to read inputs in a system at the start of a frame and fill an input component
I see so that way wont likely work in dots, thanks
Is it possible to do subtractive components as expressions in the ForEach lambda?
To have a Component System run on Entities that have 'a b c' components and explicitly not 'd'
Because if I have an entity that has 'a b c d', this system will still run on it, right? as it still meets the abc requirements?
yeah, you can use .WithAll .WithAny .WithNone in your ForEach lambda
so in this case you'd have WithAll(a, b, c) and WithNone(d)
@civic bay there is the thing called Write groups
altho i don't even think you need the WithAll, it's implicit by the lambda params
At Unite Los Angeles, the Unity sample project Megacity demonstrated the powerful capabilities of our new Data-Oriented Technology Stack (DOTS) and provided many
or you can use an EntityQuery reference and pass it into the Job.ForEach lambdas
Will the ForEach only get entities that match the EntityQuery exactly though?
@civic bay 9.30 the time Mike starts to talk about Write Groups, i think that exactly what you want๐ค
Thanks!
@pliant pike ```public class PlayerInputSystem : JobComponentSystem
{
private PlayerControlsActions controls;
private float2 inputMove;
private float2 inputLook;
private bool inputFire;
protected override void OnCreate()
{
controls = new PlayerControlsActions();
controls.Enable();
controls.Player.Move.performed += ctx => inputMove = ctx.ReadValue<Vector2>();
controls.Player.Look.performed += ctx => inputLook = ctx.ReadValue<Vector2>();
controls.Player.Fire.performed += ctx => inputFire = true;
controls.Player.Fire.canceled += ctx => inputFire = false;
}
protected override void OnDestroy()
{
controls.Disable();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var move = inputMove;
var look = inputLook;
bool jump = controls.Player.Jump.triggered;
//bool fire = controls.Player.Fire.triggered;
bool fire = inputFire;
var job = Entities.ForEach((ref PlayerInput input) =>
{
input.moveInput = move;
input.jumpInput = jump;
input.lookInput = look;
input.fireInput = fire;
}).Schedule(inputDeps);
return job;
}
}```
not sure if this is the "proper" way to do it but it seems to be workign for me for now.
that looks what you'd expect to have there now
(like, it looks like the proper way to do it for the time being)
then the component
public struct PlayerInput : IComponentData
{
[HideInInspector] public float2 moveInput;
[HideInInspector] public float2 lookInput;
[HideInInspector] public bool jumpInput;
[HideInInspector] public bool fireInput;
}```
I see using componentdata is a much better way of using them, that's awesome, thanks @velvet oxide
So apperantly i cant get random number
i do var random = new Random(5), and then call random.nextint(0,20), it always returns 0
I'm curious though, why use GenerateAuthoringComponent and then HideInInspector?
Just personal preference. I mostly just use IComponents to hold data and the ones I dont want showing up in the inspector I hide
new Random(5)
```gives you random with a seed set, so you will always get same sequence from it
@pliant pike
i mean i tried other values, lilke 1-4-52-42 etc, they all give 0 and i am using this in a job, all of them gives me 0
i dont understand how am i suppose to use it
random.InitState() ?
I always use Random.Range whenever I want something random
Oh, I miss mentioned
nah its still the same, random.Initstate() didnt work
i am trying to use random in Mathematics.Random not UnityEngine.Random Calabi
Sorry, no idea then
you still need a range though surely? otherwise you have an infinite possible numbers
@opaque ledge If it's giving you the same value it means you're passing the same seed. Google how random number generators work with seeds and you will understand
its not just giving the same value, it always gives me 0 even when init with different numbers
You're telling me if you do
Random rng = new Random(1);
NextInt(0,20);
rng = new Random(2);
NextInt(0,20);
Gives the same number?
first int is always 0๐ค
So i did something like this:
if((uint)Time.ElapsedTime > 0 ) random = new Random((uint)Time.ElapsedTime);
else random = new Random(1);```
And i send random to my IJob, and i am taking random like this:
var randomNumber = random.NextInt(0, 20);
UnityEngine.Debug.Log(randomNumber);
always gives me 0
Not sure then, I don't see what you would be doing wrong from what you posted. If you try the code I actually posted above you'll see it should return different values
first code works on jobcomponentsystem btw
@zenith wyvern your code return 0 as first value, no matter the seed
The first call to NextInt(0,20) would always return 0?
yes
Well there you go then, I didn't know that
but im not sure that it supposed to be that way๐ค
@zenith wyvern tried your code on a jobcomponent system, both gives 0 for me
Try calling NextInt(0,20) immediately after you seed it but before you pass it in then
@opaque ledge before the job, just create some native array and populate it with random numbers
and than use jobIndex as index to that array
ok so i put Sark's code to a monobehaviour still both 0
or something like jobIndex % yourArrayWithRandoms.length
It doesn't seem right that the first call would always return 0 but I don't know enough about it
Seeding an RNG and using once then discarding is definitely not the right way to use it anyways
i just did
UnityEngine.Debug.Log(rng.NextInt(0, 20));
UnityEngine.Debug.Log(rng.NextInt(0, 20));
UnityEngine.Debug.Log(rng.NextInt(0, 20));
UnityEngine.Debug.Log(rng.NextInt(0, 20));``` and it gave me 0, 0, 12, 1 every update ๐
You should search the forums to see how other people have been using RNG in jobs
hmm, let me see
bigger seed gives different first value
yeah, i tried like 56127 and it gives me 5 now but it still doesnt chance even tho i only created Random on OnCreate method and simply use NextInt on my job
Once it leave scope you would be losing it's state. That's why someone suggested you generate the numbers in a NativeList and pass that instead
There are other strategies too, like I said you should look it up on the forums
wait so sending my Random to jobs doesnt work ?
i am using it like this:
var thirdJobHandle = new CreateTradeShipJob()
{
commandBuffer = commandbuffer,
comparisions = ownedComparisions,
positions = positions,
random = rng
}.Schedule(secondJobHandle);```
i think the usual is to randomize the seed of the random that you're passing into the job
at which point you might as well create the random value outside the job unless you need multiple in the job
@opaque ledge As druid said Random is a value type.
i dont know the range tho, i can only know my maximum range inside 3rd job
you can use %
create native array of random nubmers and pass it to your job
yourArrayWithRandoms[jobIndex % yourArrayWithRandoms.length]
should work๐ค
wow okay, yeah calling NextInt works on system OnUpdate but not when i call it inside job
i... dont understand ๐ญ
same seed = same output๐
yeah but i am not changing the seed inside OnUpdate either, but it does give me different numbers
I'd like to point out that Random is pseudorandom, so similar seeds (especially close to 0, but not exclusively) tend to give similar numbers
If you want more variation, multiply the input with some semi-high number (usually a prime)
Random on my system is copied by value to job
yes๐
so when i call NextInt, it doesnt affect my original random, it affects the copy
so my Random Struct doesnt actually know i called him
dayuuum
my mind is blown right now
Oh, that issue. If you're using the Unity random (which is a struct, and thus value) and not System.Random (which is a class, and thus reference), you would usually just create it in a job, and seed it using some output from outside plus something unique to the job iterator (index, for IJobParallelFor)
As long as no burst is involved, could potentially force by value, but that would be horribly thread-unsafe
Simple solution is pass a NativeArray<Random> of size one. Get the random, do NextInt, and assign it back to the array
Yeah, i never worked with structs before, i simply never needed to, i just have to get used to it
yeah i will just make persistent nativearray just for that random and simply pass that to jobs
I cant seem to get the above code to work, I have to use [alwaysupdatesystem] to even get it to run and then no inputs are being applied to the entity/ component
I've checked it is reading the inputs, but its like the job Entities.foreach isn't running
try to make it like in the UnityPhysicsSamples
yeah i might do that thanks
entities 0.5.1 is out, seems to fix the issue with singletons (and also my own problem with burst not running in the editor)
nevermind it is working
Hello, how do I use DOTS Transforms correctly? Do you have tutorials for me? I do not know which component is the right one (Child, Parent)
the site is difficult to understand
and this is the video how everything works in details https://www.gdcvault.com/play/1026171/Connecting-the-DOTS-The-Unity
At Unite Los Angeles, the Unity sample project Megacity demonstrated the powerful capabilities of our new Data-Oriented Technology Stack (DOTS) and provided many
yeah I wouldn't bother trying to read all that to be honest
@stuck hatch Use transforms for what? What are you trying to achieve?
I know you need a localtoworld component
I want to add a child and remove a child, like old unity transform.setParent and remove child
I am not sure how to do that (leave it to someone else), but would like to point out that it might not be 'correct' under the ECS model.
Though as with all best practice kinda things - if it works, it works, and you can always improve on it later. You sound like you're still learning (aren't we all?), so I wouldn't care too much about that.
@pliant pike well its the best source for understanding how the transform system works, its not gonna make sense if you skim read it but it details in depth what the interactions are. just read Section 1 & 2 slowly
in the video Mike Acton explains everything๐
ok i go through the page
I know I just couldn't understand much of it to be honest maybe a few parts
well not saying i understood things on the first go, & I still refer back to it ๐
I think that is where I learnt about scale and non uniform scale so maybe it is useful
but i wish all the dots packages had documentation like that, like physics docs is pretty simplistic in comparison
I feel like the physics needs a cheat sheet or something
these are the common ways physics is used and these are the ways you can do it in dots physics
woot! I just got something moving with physics at least
I have a spawn point that is a child game obj that gets converted to entity. I have a gun entity that references the child entity. I'm trying to get bullets to spawn from the child's position. Anybody know how to do this with Unity.Mathematics? It's something like transform.TransformPoint() I think.
why would you need maths library for it?
you just get the position of the child surely
LocalToParent of the child and LocalToWorld of the parent?
@pliant pike getting the Translation.Value of the child does not change while the gun is moving
well then maybe their is something wrong with the parent child system as the child should move with the parent automatically if its set up correctly
It doesn't work the same in ecs as it does with regular transforms
@left oak how do I combine those?
I mean the simplest way I would do it without using all the parent child function, is to save the gun translation into an entity component and then get it directly from that
I thought about storing a float3 on the gun for the spawn point offset but I think that still doesn't work if the gun is a child of another entity
I think I just need the equivalent of Transform.TransformPoint in Unity.Mathematics.
all you really need to do is tag it as a gun and if it exists in the scene and has all the correct components, you can get them with the entityquery or singleton, foreach etc
but transformPoint is simple matrix multiplication isn't it?
Well I think so but saying it's simple doesn't tell me how to do it. Ha. The picture I posted had how I was trying to do it but it's still kind of offset weird.
Maybe I shouldn't make the gun a child of the character. That's probably wrong in ecs.
you have to otherwise it would not move with the player though
can you not just get the child's LocalToWorld.Position ?
I can see how it would be difficult you cant use the editor to position the gun spawn point
@safe lintel yes you can ๐คฆโโ๏ธ
That fixed it. Thanks for the help guys
Somehow I didnt know that it had a Position property. I thought you had the manipulate the matrix value somehow.
Thanks. Yeah my matrix math skills are not very strong. Haha
math.mul(Parents_LocalToWorld, point) is equivalent to Transform.TransformPoint
point has to be float4 with w=1 if it is position, and w= 0 if it is direction
if i'm not mistaken๐ค
that should work out iirc been a while since I had to do any of this manually lol
from ML-Agents roadmap: Packages - We will be releasing a preview Unity package for ML-Agents that will be available in the Unity package manager. We hope this will resolve many production and implementation issues with our Unity developers. Our plan is to first release this package for object-oriented (Monobehavior) in March. We plan to release a package for ECS in 2020.
link: https://github.com/Unity-Technologies/ml-agents/issues/3263
yep ๐
Do you need to do anything specific to include SubScenes into builds?
build with the new build pipeline
I see..
Does it mixmatch between ProjectSettings and that or is it fully isolated? Like define symbols etc
i am not sure tbh
I'd assume the player settings defines etc get included
but yeah, you def need to use the new build setup for subscenes or they just get omitted on builds
(or at least something goes missing)
Uff, hmm can I build for x86 through that?
would assume so, there isn't a setting?
I bet it's that "Standalone Windows"
instead of "Standalone Windows 64"
Hmm, was that I was trying, but still got error, maybe I was reading it wrong
Yep, read it wrong x)
"Editor's active Build Target needed to be switched. Please wait for switch to complete and then build again."
so I guess you wait for it process the change first
Nono, I was doing the Standalone Windows and it complained net bindings was 64x and I built for 86x, was just the other way around.
Hmm, I still get failed loads of entity scenes...
Maybe it is because I create them through instantiation...
It's currently not possible to access the UnsafeList contained by NativeList, I have a need for that or otherwise have to roll out my own version of a native list for perf benefits. Do you know if this is a topic or going to be changed soon?
idk what i'm doing wrong, but i can't get subscenes to work at all, all scenes added on new build pipeline. game objects with the convert script work fine. my streaming assets folder in the build is 4.5gb. but nothing loads
wonder if it's still some code stripping issue
but I dunno why it would only affect subscenes
What today is a best way to sync destroying entity and gameobject? How u do it?
might try upgrading the project, on 0f1 atm
@frosty siren you can try using companion gameobjects, I think destroying either destroys the other but i havent actually tested that part of it, its also not recommended for anything but experimenting so that on top of dots being preview is kinda not too confidence inspiring
Am i correct in thinking there will be no PhysX DOTs/ECS support? So for advanced physics one needs to look to Havok? My challenge is the network replay functionality of Unity Physics is desirable but not super excited about its stateless physics (although I understand replay somewhat depends on reversing the state).
@safe lintel what is companion gameobject? managed componentData?
theres a demo of it in the samples repo
like wireframe gizmo or something similar, that scene should explain better than i can but it kinda links a gameobject to an entity
yeah pretty much @valid haven though i believe physx is open source now so you could make your own port of it to dots if youre feeling ambitious
lol as fun as all that math sounds, that sounds like a project in of itself ๐
Any thoughts on how to deal with Havok's stateful system and achieve good multiplayer fps projectile accuracy (e.g. network replay like accuracy).
Also I noticed havok's licensing is per seat, I assume only developers involved in the physics coding would need a seat?
If I have literally zero experience doing anything network related would the dots shooter sample be a reasonable place to start learning?
I would say so, theres a decent unity video on on it, looks pretty straight forward.
Dive deep into the networked future of Unity using DOTS. Hear how we made the DOTS Sample a networked game, and what we learned on the way.
Speaker:
Tim Johansson - Unity
Learn more about the Data-Oriented Tech Stack (DOTS): https://on.unity.com/2lraugz
I wasnt sure if it's at a good place yet for beginners, I know they said they're working I higher level layers down the road
honestly compared to the old net solution it looked simpler.
just getting into it myself tho, so shrug.
This is probably a very simple question.
I have a simple IJobParallelFor job that reads the right values, but when I write to it, the entities values don't change.
I converted it to a IJobChunk as in the HelloCube example and it works fine.
Can someone tell me how to achieve this in a IJobParallelFor?
https://pastebin.com/sBvzu2Hd
https://pastebin.com/Zm9QHVGK
I suspect it's just the way I create the NativeArray
the native array is a copy
not the actual values
you will need to apply the data back afterwards
"When used with the Unity C# Job System, a NativeContainer allows a job to access data shared with the main thread rather than working with a copy."
https://docs.unity3d.com/Manual/JobSystemNativeContainer.html
@low tangle This says otherwise ๐ค
_voxelGroup.ToComponentDataArray<Voxel>(Allocator.TempJob);
this line creates a job to go and find all voxels, and copy them into a destination nativearray
it is a copy end of story
Any idea how to get the values then?
jobforeach instead
unity supports voxels natively? ๐
@ebon ember You could use entityQuery.CopyFromComponentDataArray to write the changed values back to the original entities
@zenith wyvern Ah! I was just looking for that!
@valid haven It's a component I created
i c ๐
I wonder how many people are trying to make voxel games in ECS now, hahah
I've seen at least 4 including myself
what engine are they using?
I am trying to figure out how best to create ECS/DOTs powered game with mineable asteroids
I meant in Unity with the ECS framework specifically
I mean which voxel solution they using. Custom? or one of the assets on the store.
Custom
Creating a good voxel solution is pretty much an entire project in itself is it not?
After all these years Unity is finally pushing for performance first so it makes sense people would try to jump in. And I'm including myself in that of course
And yeah, that's what I mean. I've seen a few other people talk about making their own framework for an open world voxel game
Hopefully one of you make it an asset so others can use it as well ๐
It was always possible of course but with dots and ecs it creates some new interesting opportunities
Mine is open source. It's dead ended right now though, I'll get back to it at some point
What are your design goals for it?
Basically to make a lame minecraft clone, just to see if I can
i c. I am looking for something that can replicate Space Engineers like roids, procedural roid clusters with interesting shapes, and non-blocky deformations as they are mined.
As far as I know most people achieve that with marching cubes. I've never tried that, I'm happy enough with plain old blocks
yup, havent found a reasonably priced marching cubes implementation, let alone one focused on dots/ecs with navmesh support.
Anyone use visual scripting ecs ?
Does getting a component with the EntityManager force a sync point? Or only if you try to write to the component?
id love to know the answer to that myself
But not entityManager.GetComponentData(entity) right?
get wont
you can always profile and check yourself
you will see these two on the main thread
this is a monobehavour that creates a few entites
how can i create a world and init those systems into that world and stop that world so my systems will be stopped as well ?
the way you update that world is directly controlled
so you will have to update it yourself, if you dont want it to update you just dont update
Anyone know the correct way of adding subscenes dynamically, i.e. instantiating them into scene? (still only 1)
I tried by having it as a prefab, but it doesn't seem to work when I build.
So, how can i make a world UI(Gameobject) follow my entity ?
Should i be using the AddComponentObject ? i never tried to work with it but if that is the correct direction then i will
is there any alternatives to it or ?
do you want to sync transforms between entity and some game object?
yeah, perhaps even getting some data from that entity to set my UI text
Have you looked at physics samples? There is EntitySender EntityTracker scripts
CopyToTransform
CopyFrom
AddComponentObject the transform
To the same entity that has a Copy and a translation
@opaque ledge
i will check those, thanks
Also for AddComponentObject
After you do that, you can literally just put the monobehavior into the foreach lambda
No ref or in
It's really easy to do ecs on monos that way
Just make sure it's no burst and Run since those are main thread
But how can i get the entity that particular monobehaviour is attached to ?
i guess i have to manually set that, i should probably have a public Entity field on my Mono, and when i create an entity i should set that Entity to that Mono ?
So something like:
var entity = commandBuffer.CreateEntity();
var mono = commandBuffer.AddComponentObject(entity, typeof(MyMonoBehaviour));
mono.entity = entity;```
would that be the way to go ? @low tangle
Also, should i be asking Unity.Physics question here or to #โ๏ธโphysics ?
I notice that the new blog post from 2019.3 says that they've upgraded physx, wherein another article explains that physx is now threadsafe to use with jobs?
has anyone tested this?
there's like 25 bugfixes for burst on 2020.1.0a21 fix list (between a20 and a21)
whats the correct way to use getsingleton, I get an error when the singleton does not exist so I have to use HasSingleton but then the variable I cannot initialise it to null
PlayerInput bakedbeens = null;
if (HasSingleton<PlayerInput>())
{
bakedbeens = GetSingleton<PlayerInput>();
}
else```
I cant do that it doesn't work but I need to do something like that, if I use it in that then the variable is out of scope for the job
private PlayerInput playInput;
if (HasSingleton<PlayerInput>())
{
playInput = GetSingleton<PlayerInput>();
Debug.Log("The input value is " + playInput.moveInput);
}
else
{
return;
}```
that seems to work in Onupdate
You could try RequireSingletonForUpdate<T>() so the system only updates when you have said singleton - keep in mind that if you have another entity query - and you use RequireForUpdate(entityQuery) they're not combined as the rule for the system to update
oh yeah I forgot about that thanks, I might change it anyway instead of constantly getting singleton see if I can use an event type system
Is it possible to check if a singleton (ComponentData) exists? GetSingleton and GetSingletonEntity throw exceptions if it does not exist.
Can just build a query and do query.CalculateEntityCount() > 0, but I wanted to know if there was a quicker way
like above HasSingleton<MyComponentDataSingleton>()
Why is Voxel marked as read/write?
JobHandle myJob = Entities.ForEach((ref LocalToWorld transform, in Voxel voxel)
Isn't it supposed to be read only with "in"?
@safe lintel ah thanks, didn't notice someone had already asked about that
Hey guys!
Just a quick question... is ComponentSystem etc. usage allowed 'inside' asmdef's?
I mean, I have some code that I would like to put inside non-main dll, but then... the ComponentSystem is not running, even with [AlwaysUpdateSystem].
yes it's allowed - I write component systems in asmdefs
Weeeelp... Then I messed up something, thanks ๐
Ok, now it's working. Compiler probably got a stroke.
Do you guys think there will be a Dictionary/HashMap implementation like Buffers with IBufferElementData?
that would be the unsafe datastructures
that's coming no idea when
but you would be able to put them into component datas as the only thing stopping native containers from getting into component data structs are the safety checks
So you think, they will work on using native containers in components?
yea - that's what I remember reading here from Topher (unity staff) when mentioning fixed lists
fixed lists are already useable in componts, arent' they?
yes
nice, so i am looking forward to a FixedDictionary ๐
there's also flohm's unsafe collections: https://github.com/fholm/UnsafeCollections/tree/master/UnsafeCollections/Assets/UnsafeCollections/Collections
thx, going to look into it. Do you use it?
just his unsafe hash set
this was merged to SRP master today https://github.com/Unity-Technologies/ScriptableRenderPipeline/pull/5661
What does that mean?
if i'm understanding correctly, material properties with DOTS will soon work with the URP
oh nice, lets gooo! ๐
heck yeah ๐
Also I know people have been having a lot of horrible render errors in URP with Hybrid, I imagine this will address that
Is it possible to use ProfilerMarker with Burst somehow? I get
Burst error BC1033: Loading a managed string literal is not supported
hello guys,
i made massive navmesh zombies by using animation instancing method ... but based on my profiler the update func. of my zombies script take much cpu ...
so, have to used ECS? [convert zombies to ECS] which is hard :
or is it possible to using Unity Jobs with Burst compiler to optimizing just this script?
Assuming the navmesh is the part taking the majority of time, afaik there's no way to speed that up using DOTS other than writing your own pathfinding solution (which is doable but depends on if it's something you want/need to tackle).
@silver dragon yes, take a look at this https://gist.github.com/jeffvella/9420be274fc90945554b6b0cff4a5d8c
as for that URP PR, I think it's going to address some of the dots instancing issues but wouldn't expect it to magically fix everything ๐
it's nice to see they are working on it tho
thx @mint iron, i really forgot to add it as a local var to my Lambda Job. At least code runs now, though the result is empty. Have to play around a bit more with the preformance framework...
Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters) (at <a3d417b16c80486ca3272865b9417295>:0)
Unity.Jobs.IJobExtensions.Schedule[T] (T jobData, Unity.Jobs.JobHandle dependsOn) (at <a3d417b16c80486ca3272865b9417295>:0)
PickupCollisionSystem.OnUpdate (Unity.Jobs.JobHandle inputDependencies) (at Assets/_Prot/Scripts/ECS/Collisions/PickupCollisionSystem.cs:143)
Unity.Entities.JobComponentSystem.InternalUpdate () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/JobComponentSystem.cs:125)```
I'm not doing things in the right order, and I'm not sure what the right order is.
I have a NativeArray<PickupData> which contains info for all Pickups in the current world. Every frame, I'm checking which of those is near the player and constructing a NativeList<PickupData> which is a much more manageable size for calculations and the shader.
When I pick up a PickupData, I'm deleting it by remaking the NativeArray with a length 1 shorter than before and adding all entries except the one that's been identified to be picked up.
After picking up, I get the error above where the NativeContainer has been deallocated (I've made a new one and reallocated it) but apparently this has happened at the wrong time.
Do I need to jobify the deletion step and make that a dependency of the other jobs so the scheduler knows it has to wait for that deletion/reallocation before trying to access the NativeArray again?
@wary anchor Maybe use a NativeQueue instead of rebuild a NativeArray would be easier ?
wouldn't I get the same issue if the length of the array changes when a job is already schedules? I'll give it a try anyway
I would show some code but I am currently in the middle of rewriting a section of it so the deletion step is a Job ๐
Thanks for the suggestions guys!
Try to use .Dispose(JobHandle), so it disposes after job is finished (just a guess)
Thanks @pseudo epoch and @silver dragon - NativeList works a treat for this with the RemoveAtSwapBack() method
๐
How do dynamic buffers handle empty indexes, like from RemoveAt?
Same as a managed list I believe, but it uses memcopy to move everything around so it should be pretty fast even if removing from a low index
int elemSize = UnsafeUtility.SizeOf<T>();
byte* basePtr = BufferHeader.GetElementPointer(m_Buffer);
UnsafeUtility.MemMove(basePtr + index * elemSize, basePtr + (index + count) * elemSize, (long)elemSize * (Length - count - index));
m_Buffer->Length -= count;
thank you for the detailed response ๐
new dots tiny and dots runtime packages
anything important?
## [DOTS Runtime 0.2.0] - 2020-01-21
* Full codegen support for Jobs API```
```md
## [Tiny 0.21.0] - 2020-01-21
* Added Tiny Animation features
* Added volume changes affect audio
* Added pan to audio
## [Tiny Rendering 0.21.0] - 2020-01-21
* Add support for cascade shadow maps (1 csm directional light, fixed to four cascades). Refer to the CascadeShadowmappedLight component for more information.
* Add support for spot light inner angle.
* Fix culling under non-uniform scale when CompositeScale is used
* Update package dependencies```
so, additions here and there
Dang, I was hoping to see the runtime mesh api for Tiny
I guess 2D is coming early February, fingers crossed it will come then
i dont understand why, but 2020.1a21 is lightyears faster playing in editor than 19.3, my (dots)game's loop seems like 2x the speed(2-3ms vs 4-6)
same options on both enabled for DOTS?
was that script debugging toggle in the corner that defaults to being off introduced in 2020 or is it in 2019.3?
i looked for it briefly in 19.3 and didnt see it there or in preferences
same options but i didnt check the script debugging, lemme see
Then it could be that script debugging is the difference. There is a setting in the editor preferences in versions that didn't have the nice button, and I think it's been on by default
still way faster
since the new lambdas are code gen'd the query is actually populated before OnCreate
so you can do conditional query updates by using that
wish there was just a simple .RequireQueryForUpdate() option instead
I wouldn't need a OnCreate most of the time since I usually just put a primary and secondary query up there
Can I create an entity completely with code and then instantiate a bunch of them?
of course @lusty otter
Thanks
I'm making a user scriptable game, and all elements are scripted by the user including textures and what not.
It doesn't make sense to make a pretty much empty prefab to instantiate, or is that still recommended for some reason?
Not sure what you mean @lusty otter. If you want to create an existing entity from code you can use EntityManager.Instantiate to create a copy or create from an EntityArchetype
//Something like:
var entity = entityManager.CreateEntity();
entityManager.AddComponent(/* as you want/need */);
//Repeat as necessary, possibly setting component data
//Later:
entityManager.Instantiate(existingPRefabEntity); //clones entity
Hmm okay, I'll look into this further, thanks!
do you guys think i should make a entity query for processing singleton data or just get the singleton data and send it to IJob and process them there?
Hah, I was literally just thinking about this. The problem with running it as a ForEach is it forces you to use parallel-safe containers (or pass them as-read-only, or disable the safety system) inside the job, even though you're only working on a single entity.
The problem with doing an Job.WithCode is you no longer have an implicit query, so your system will run all the time.
My gut feeling is the latter makes more sense, then you have to explicitly create a query and use RequireForUpdate like June was showing earlier.
If anyone has a more sensible/readable way to do this I'd love to hear it
So this operation will not be parallelized? It's just a pure data-in data-out function?
Does it need to be a job? Why? Because that sounds like a good case for simply running it on the system. I suppose you can parallelize it with other things as a job, but you could just do a conditional in a system if you don't need it to run always.
In my case most of the time I want to make structural changes so I wouldn't want to run it on the main thread since it would force a sync point
But that's a good point if you don't need to make structural changes
hmm, that GCHandle trick to run managed code in the job system doesn't seem to work if your manage code also touches a NativeArray
any ideas?
ping me if you know
Hey everyone! I am setting up DOTs in my existing project, and the following error appears when I enter play mode:
~\Library\PackageCache\com.unity.entities@0.5.1-preview.11\Unity.Entities\Types\TypeManager.cs(431,13): error: Cannot find the field `TypeInfos` required for supporting TypeManager intrinsics in burst at Unity.Entities.TypeManager.GetTypeInfo(int typeIndex)
Any ideas on how to fix this?
hmm, did you update burst ?
Burst is version 1.1.2, I just grabbed Burst, Entities, DOTS Editor, Unity Physics, and made sure they were all up to date.
Wait a minute..
Why does it say up to date when 1.2.1 is released...
@lyric spoke Are you using 2019.3.06f?
Yes
I haven't, going to see if using the actually latest version of Burst fixes this first though
Unexpected exception Burst.Options.OptionException: Unexpected arguments: `--is-for-function-pointer --managed-function-pointer=0x000002001B8CE270` at Burst.Compiler.IL.Jit.JitCompilerService.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job) [0x0012a] in <3179d4839c86430ca331f2949f40ede5>:0
Fek
@zenith wyvern That seems to have fixed the issue! Thank you!
Now I just need to figure out why my shader graph incinerated itself...
A question, what is the difference between JobComponentSystem and ComponentSystem classes ? also, when doing job stuff, .Schedule runs the job on worker threads, .Run runs on main thread right ? on what circumstances i should use one over othe ?
Hello :D
I've updated entities package to 0.5.1 and now World.DefaultGameObjectInjectionWorld is null. Shouldn't Play Mode create one by default? Any suggestion to fix this?
@fickle sapphire Is an error relating to Burst appearing when entering play mode?
@lyric spoke Yeaph! Here we go:
Library/PackageCache/com.unity.entities@0.5.1-preview.11/Unity.Entities/Types/TypeManager.cs(431,13): error: Cannot find the field TypeInfos required for supporting TypeManager intrinsics in burst
at Unity.Entities.TypeManager.GetTypeInfo(int typeIndex)
@opaque ledge JobComponesys is multithreaded and ComponentSystem is single threaded, its mostly supposed to be used settings things up and testing
Alright: Go to the package manager, Burst, Show Versions, and make sure to select 1.2.1. After that installs, exit Unity, delete the Library folder in your project's folder, and once that completes, relaunch Unity.
That should fix it
Just fixed that not even an hour ago XD
@lyric spoke you're a lifesaver. That did the trick ๐๐ค
๐
@opaque ledge You basically shouldn't be using ComponentSystem at this point. See this thread: https://forum.unity.com/threads/garbage-for-every-onupdate-when-using-ecs.806895/
Just make sure to always put [AlwaysSynchronizeSystem] and return default if your JobComponentSystem will only be running on the main thread
ah okay, thank you, i thought component system always run on main thread so i was using it to read input manager and move my player
It does, but JobComponentSystem will as well if you do all your ForEach with .Run instead of .Schedule. Check out the offical pong tutorial for a good example https://www.youtube.com/watch?v=a9AUXNFBWt4
In this workshop style video we walk through an example project created by Unity Evangelist Mike Geig on how to script a Pong style game using Unity's Data Oriented Tech Stack (DOTS) including the Entity Component System (ECS). This video covers the latest syntax in Unity 201...
ForEach is equal to job structs right ? or do you mean ForEach lambda ?
I wasnt aware of that, I'm a bit behind on the updates it changes so fast, thanks Sark
I'm talking about the ForEach construct where you pass in a lambda. Watch the video, he explains clearly how and why you run code on the main thread inside JobComponentSystem
What is the proper way to handle things like cameras in DOTs?
I have a system that I want to use to move the player, but the player has the camera attached to them. It deletes the camera when the entity is created.
I'm guessing you want the camera to move with the player, the best way is to just update its position with the player
I did it with a Componentsystem but now I'm trying to figure out how to do it with a JobComponentsystem
you could just pass the camera straight into the Entities.foreach in a ComponentSystem but I'm curious how you pass it into a job ๐ค
I've tried and I'm thinking its probably best not to try doing it with a job at all
yeah, i'll pass the transforms components of my camera entity so i can manipulate it in space, but i've not tried manipulating the camera component within a job
I just get an error that says have to use run() and withoutburst() for objects passed by reference
and even when I do I just get tons of errors, so doesn't work and even if it did without Burst it wouldn't be any faster than just running in Onupdate I'm guessing
are you using an entity conversion of the camera, or just references to the gameobject?
I couldn't convert the camera to an entity
yeah, but you can still get Translation, Rotation, and LocalToWorld from a conversion
which, if all you
need is to move the camera
I just ended up with a black screen for the camera
I think you need to keep the gameobject of the camera
you can't convert and destroy
and you need a CopyTransformToGameObject... I think
this all might've changed
just add convert&inject to the camera, it should preserve it
ok I'll try them thanks
I've been away from dots for so long I'm basically having to learn it all over again now ๐
that might happen again with every major iteration step for DOTS :>
basic question but is there a way of assigning a instantiated entity in a job to a local public variable in jobcompsys?
well, you certainly can't do it from the command buffer within the job you instantiated it from
yeah I know I'm just going to need it always its a player character
I've created them in onstartrunning
Right, but why not just query and get it
I'd have to query it in update and wouldn't that be a bit of unnecessary overhead?
Not really
It's a n of 1
I've got networking systems where I go and grab my 1000 players at the start of the systems update
It's not even noticable in performance
You should design systems to go and get the minimum data they need with minimal indirection
and that's just constantly running?
Yes
My whole update loop for entities and monobehaviors is about 1.5ms total
Rest is rendering and nothing else
if (EntityManager.Exists(GetSingletonEntity<PlayerTag>())) return;```
is that a good way?
That works, or you can create the query and . CalculateEntityCount() == 1
oh yeah, thanks
If you create an explicit query then your system already wont run unless the player exists right?
Oh right, but you could pass the query to RequireForUpdate to override other ones
Correct
Guess it depends if your system only depends on the player though
This is why you want to keep your systems small and single responsibility
Entityquery works with component tags right?
actually thinking about it I should probably just use Getsingleton()
Singleton's can only have one component on them
I just need the entity currently
Then that will work
I always forget you have to first check their is singleton, doh!
Hi all. How do you build a project with the latest DOTS packages?
I'm trying to build for Windows (Mono or il2cpp) and getting the following error:
IL2CPP error for type 'Unity.Properties.CodeGeneratedPropertyBagRegistry.System_ObjectPropertyBag' in assembly 'C:\Projects\SpaceShips\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll'
Additional information: Invalid method 'System.Void Unity.Properties.PropertyBag`1<System.Object>::Accept(TContainer&,TVisitor&,Unity.Properties.ChangeTracker&)' found in vtable for 'Unity.Properties.CodeGeneratedPropertyBagRegistry.System_ObjectPropertyBag'
I'm just using File > build settings but I've seen talk about platform.**** packages, do I need one of those?
ok strike that above csharp if (EntityManager.Exists(GetSingletonEntity<PlayerTag>())) return; it does not work, you have to use HasSingleton<>()
why wouldn't you just always have a PlayerTag and just GetSingletonEntity<PlayerTag>()?
Atleast, if you're going the singleton route anyway
bong rip
yeah I did
Hello guys, I am currently experimenting with Unity DOTS and I realized recently that my burst compiler seems to be only active the 2nd time I launch my jobs after going into playmode. I am using Unity Mathematics simple noise function in one of my job and the execution of this job takes about 15s when I launch it for the first time but then only 1.5s the next times. Did anyone had similar issue or know how to solve this ? I'm currently using Unity 2019.3f6 and the latest version of DOTS packages
Set CompileSynchronously to true to make sure that the method will not be compiled asynchronously
In general, you should use asynchronous compilation.
I think that's exactly what I am looking for, thank you very much I will try that!
yeah, one of the dots guys said on the forum they will fix up synchronous compile times
they are sequential instead of being done in jobs like the async ones
option #3
but it will slow startup time until they get that update done
Thanks for the info but adding the burst attribute "did the job" for me since only one of my job was really a problem
yeah for your case since it was just one
my game runs like shit for like a full minute if I dont run sync on everything
devs are working on it though
I see I will probably get to this point later haha