#archived-dots
1 messages · Page 186 of 1
Fixed means that it has a max capacity
Ah, that won’t work either.
I'm not really sure if what I'm trying to do is possible. But having some sort of array in a component should be possible, I haven't used Entities before so.
Dynamic buffers are very much dynamic, though
If I may ask, what's the specific use case here? Because it might be that you should reframe th e way you're trying to solve it
I'm trying to find a way to store data for a neural network. I'd need at least one array of Neuron structs stored somewhere on the Entity.
I attempted this, though this gives an error when trying to do Entities.ForEach. ```CSharp
using Unity.Entities;
public struct NeuronData : IBufferElementData {
public float value;
}
[GenerateAuthoringComponent]
public struct NeuralNetworkData : IComponentData {
public DynamicBuffer<NeuronData> inputNeurons;
public DynamicBuffer<NeuronData> hiddenNeurons;
public DynamicBuffer<NeuronData> outputNeurons;
}```
dynamicbuffers are basically a component themselves stored on the entity, can't store them in a different component
Yeah, that's what I realized. I'm trying to find different way of doing it.
what's wrong with that though?
Gives an error when doing Entities.ForEach.
NeuralNetworkData used in NativeArray<NeuralNetworkData> must be unmanaged (contain no managed types) and cannot itself be a native container type.
i meant what's wrong with storing a dynamicbuffer on the entity instead of component
it's just different syntax
I'm not sure what you mean, Quite new to Entities so.
oh i read it as you didn't want to use them because it's on entities
you're getting an error because you're adding it the wrong way
hodhandr posted a link to the doc page of dynamicbuffers, shows example how to create and add one
Well I'm using the Authoring Component to create one so that should be fine; and I'm adding one by doing this
protected override void OnCreate() {
Entities.ForEach((ref NeuralNetworkData neuralNetworkData) => {
neuralNetworkData.inputNeurons.Add(new NeuronData());
}).Run();
}
Oh wait, it's this part that's crashing it. I'm guessing I'm supposed to read it in a different way.
protected override void OnUpdate() {
Entities.ForEach((ref NeuralNetworkData neuralNetworkData) => {
Debug.Log(neuralNetworkData.inputNeurons.Length);
}).Run();
}
FYI, when you do .Run() the code will not be run in paralell
If you're still using it as an ICD and not a proepr dynBuffer, that would probably be why it fails
I know, that was intentional in this case, I wanted to see if running it in parallel was somehow causing it.
I'm not sure what you mean by ICD
IComponentData
You can make an autoring class to plop onto GameObjects(GOs) that can do whatever you need to the entity, BTW.
https://docs.unity3d.com/Packages/com.unity.entities@0.16/manual/gp_overview.html#gameobject-conversion
That said, IBufferElementData supports [GenerateAuthoringComponent], though with some limitations.
You'd need different types to be able to add multiple buffers, though.
That said, I don't think ECS is the pattern to squeeze a neural network into - as long as you have a sane amount of things with neurons, I'd suggest moving the networks themselves outside the entities. You could still access the data from a system, and/or run the code in jobs.
With ECS you generally want systems to be pretty small and relatively simple, and neural networks are likely to fail on both counts.
Hmm. I'm not sure how you would store neural network data outside of the ECS system whilst still using that data in ECS. And do you mean you would call a separate class for neural network within the Entities.ForEach or?
I'm guessing you mean each entity with a network having some sort of ID and then using that ID in some place that stores the networks or something like that.
is it possible remove Component derived from one interface like this
or any another way but with same result
Sadly I can't seem to find many resources into learning DOTS and how to do certain things.
hello guys, maybe someone can help me, i have a healthbar, and i wanne disable the whole healthbar with his childs if health 100 and only show them if health is < 100, my problem is that
disable only works on the parent not on the childs of the healtbar
what is the best solution to hide and show the healtbar entity ?
this is my healthbar
and at the moment only the healtbarcontainer get dissabled
@red marsh the rendering doesn't preserve the hierarchy - you have to manually find disable the children
@half jay I don't think so but I could be wrong
okay should i set a refference then to the childs in healthbarcontainer
i mean in HealthbarComponent
ref the childs
yes - either you can store a reference to the exact children you want to disable or you can write a general-purpose recursive method that checks for e.g. a Children buffer and iterates over them
Disable should work if they're in a linkedentitygroup I think
Turn your hierarchy into a prefab
problem is that the Healthbar is also a Child of a other entity
so the linkedentitygroup if in parent already
oh good to know @zenith wyvern
@amber flicker my code doesn't work. It requare register generic type, but it doesn't work too. I show it for example what I want to achieve.
I believe those methods will only accept concrete types
@tawdry tree Hey I hope you don't mind me pinging you but I'm wondering what you meant by moving the networks outside of the entities, do you mean like creating a neural network class and each entity has some sort of ID corresponding to a neural network in some list? That's what I got from what you meant but you might have thought of something else.
Something like that. I only know the basics of neural networks, but it from what I know it's a bit too heavy for, and conflicts with the ECS model.
You can use them side-by-side, but trying to force neural networks to work inside the ECS model seems a bit iffy. Specifically on the data side - again, you can still use both systems and jobs, but the data seems a bit too complicated and "big"?
Hello, just to confirm what I understood, if I use external job dependencies, I cannot use the simple Dependency field of a SystemBase. I have to do Dependency = Job.Schedule(externalDep); and the schedule will not take into consideration just the external dependency but also the current Dependency. Is this correct?
@tawdry tree Gotcha, I can try and make something like that but I'm really uncertain on how I would get it to work. I'll give it a shot though. I have made a neural network with GameObjects (using Jobs and Burst) before and I wanted to try and use ECS as well since it's way more performant and I would like to simulate more networks at once.
@odd cipher If you're already using bursted, parallel jobs, you won't get that much more perf from ECS, and it seems like it would be a lot more work
@scarlet inlet There are methods to combne dependencies, so if you want to be certain, consider using that
Yeah hm, I should probably just stick to Burst and Jobs. I haven't gotten my neural networks to work with ParallelJobs yet but I want to get that working.
And well, I'm running a new job every single frame for each 'creature' that has a neural network. Which is not great but I'm not too certain how to make that better.
@tawdry tree combining the Dependency field before scheduling the job may be a better strategy you mean, so I can use just the normal Dependency
@scarlet inlet
Dependency = JobHandle.CombineDependencies(Dependency, externalDependency);
//When you use Dependency, you need to both set it and use in signature - you can't do either or
Dependency = Entities.ForEach(/*...code here...*/)
.Schedule(Dependency);
Not 100% sure, but seem to recall having weird errors if I didn't manually set Dependency with my final jobhandle.
I do remember I had to do Dependency = [...] -and- .Schedule(Dependency), though. Either or led to issues
yes once you do the combine you don't need to use Dependency in the schedule
weird
I will test
Dependency is actually per world, not per system like the interface suggests
when I change the Dependency in a System I am changing the global/world one
how can I trigger a system to do an update right now?
@odd cipher one job per neural net execution makes a lot of sense
im assuming they are relatively expensive, no?
@odd ridge If you can get a reference, yes. It's a complicated topic, though
Not at the moment, I'm trying to get it to work in parallel right now so I can't see how performant they are at the moment.
get them running in parallel-for (over multiple creatures) first, its the easiest way to parallelize them, and very performant
doing a parallel for per creature creates many more jobs and many more sync points, which can throttle perf significantly
one thing you may want to try is to make them completely separate from the ecs and from... everything
the idea is that they become background tasks
and then you read their data the next frame
so in your AI logic, you first start by reading/syncing the jobs launched last frame, then you prepare the new jobs, and then launch those
this way it has 0 syncs and the jobs for your AIs will nicely fill the "gaps" other jobs create
to do that you dont need the ecs at all. launching the jobs from a monobehavior will work completely right
Makes sense, I'll try and get the stuff you've mentioned here to work but it'll take some time.
my issue is I want to set a custom timestep to my system, but I want the initial system update to happen immediately instead of waiting for the timestep.
I would need on attribute such as [UpdateOnStart]
I found a solution with a hack for now
hey @vagrant surge I need an advice
It's a couple of hours I am trying to understand if I can do this in UECS
public static JobHandle TickUECSSveltoGroups(World UECSWorld, JobHandle externalDependency)
{
UECSWorld.GetExistingSystem<SubmissionEntitiesSystemGroup>().Update();
UECSWorld.GetExistingSystem<SyncSveltoToUECSGroup>().Update();
UECSWorld.Update();
UECSWorld.GetExistingSystem<SyncUECSToSveltoGroup>().Update();
}
the introduction of 3 topmost group and the world update is OK, but I am not sure how to pass the externalDependency to the world
if there is a way to do so, as Dependency is only available inside Systems
I mean sure I can go back to the JobComponentSystem, but even in that case, how do I pass the dependency through a group?
My current understanding is that dependencies are anyway world related, so my brain would like to find the dependency through the world, but this is not how it is
yes but Dependency is really stored by the world EntityManager, isn't it?
yeah ok but the the jobhandle is of course reigstered in the EntityManager dependency list
in this way it can organize the dependencies according the component used in the systems
what I am trying to understand first is that my initial impression is that there was a Dependency (jobhandle) per system
but in reliaty if you see the set method of Dependency, you will see that eventually the jobhandle is registered in the entity manager
so I wonder if eventually it's just one combined jobhandle for the whole Entity Manager
I have no idea how it works internally, it sounds like you're trying to reverse engineer how ECS figured out how to handle system dependencies based on the components it accesses
no not really, but if it's true that the Dependency is eventually a big combined handle for the whole EntityManager, I was wondering if I can access it from the World
I mean technically is there, but the methods are private/internal
I have no idea about any final job handle that it all gets combined into
Sounds like you know a lot about it
Dependency in a given system is based on the system group and UpdateAfter/UpdateBefore, among others from what I understand
I am not 100% sure so maybe someone who knows better can confirm or not, but to me eventually it seems all registered in the entitymanager of the world
maybe I am reading it wrong, tbh it's not siome
internal void AfterOnUpdate()
{
AfterUpdateVersioning();
var depMgr = m_DependencyManager;
// If outputJob says no relevant jobs were scheduled,
// then no need to batch them up or register them.
// This is a big optimization if we only Run methods on main thread...
var outputJob = m_JobHandle;
if (((JobHandleData*)&outputJob)->jobGroup != null)
{
JobHandle.ScheduleBatchedJobs();
m_JobHandle = depMgr->AddDependency(m_JobDependencyForReadingSystems.Ptr,
m_JobDependencyForReadingSystems.Length, m_JobDependencyForWritingSystems.Ptr,
m_JobDependencyForWritingSystems.Length, outputJob);
}
}
which is called by SystemBase
I have the feeling that in the past I already found out that Dependency actually ignores combined external dependencies that are not component related
It does, that's why you need to pass around jobhandles if you use any kind of nativecontainer in your jobs
What is it about the code you posted that makes you think it's all being combined into one dependency?
It looks to me like it's just the system managing it's own dependencies
m_DependencyManager comes from EntityManager, which must know the other systems dependnecies in order to update your handle correctly right?
but anyway we can scratch everything about my reasoning, because I cannot use Dependency for what we just said
I need my own dependency handling, I actually did all this reasoning and totally forgot
update: I have been told that it's not entirely true that Dependency ignores external dependencies, but it applies them only when UECS components are written/read. So it's not safe if external containers are used
This is about the Job System; since my neural network jobs are running every frame, and the creature that has the neural network can die after reaching 0 energy, that neural network job will break. I'm not sure how you would prevent this.
Hi, is there a thread-safe version of NativeQueue<T> ?
@odd cipher doesnt matter
your AI jobs are "isolated" from the game
so at the end of the job, once it finishes, its only then when you actually apply the results
just check if the unit is still alive at that point
that doesn't really work since the job tries to change/read data that doesn't exist anymore.
I'm not sure what you mean. The job takes in all the neurons and changes their values. If the creature dies during the job those neurons will be gone and the job will break.
a job in unity needs to "own" its data, of sorts. So you have to copy the neurons into the job
I suppose that could work yeah, I'm not exactly sure how you would copy them to the job since it's a struct and it should already be copied unless I'm mistaken.
if it copies, deleting the orignal one wont be a problem
Exactly, I'm not sure why it isn't copying then
This is how the Job initialization looks like
runNetworkJob = new RunNetworkJob() { inputNeurons = inputNeurons, hiddenNeurons = hiddenNeurons, outputNeurons = outputNeurons, synapses = synapses, connections = connections, outputs = new NativeArray<float>(outputNeurons.Length, Allocator.TempJob) };
runNetworkJobHandle = runNetworkJob.Schedule(hiddenNeurons.Length + outputNeurons.Length, 128);
}
[BurstCompile]
struct RunNetworkJob : IJobParallelFor {
[NativeDisableParallelForRestriction] public NativeList<Neuron> inputNeurons, hiddenNeurons, outputNeurons;
[NativeDisableParallelForRestriction] public NativeList<Synapse> synapses;
[NativeDisableParallelForRestriction] public NativeMultiHashMap<Guid, KeyValuePair<int, int>> connections;
[NativeDisableParallelForRestriction] public NativeArray<float> outputs;
can we fill a native array somehow kinda that? blabla = {1, 2, 3, 4, 5} ?
ok, not so important, but is there a way to define some kind of array (regular datatypes) that can be accessed from all methods of a Struct (not only Execute) for a job?
I really do not want to need to write the same 5 lines of code over and over again, as this nonsense!
And there is no way to add a method within the Execute of a Job and outside of the Job (but in the same struct) it can not access a NativeArray created in Execute. And when I define a private NativeArray in the struct to be used for Job and subfunctions it says that the NativeArray is not defined!
So I now do it like this (but also feels not right), within the Job call:
GenerateVertex(0, 1, cornerIndices, cornerDensities, cornerNormals);
although normally (0, 1) would suffice and the rest could be the same all over the struct
Is it safe to actually start using ECS for development, or is it really not ready to go?
ok, not so important, but is there a way to define some kind of array (regular datatypes) that can be accessed from all methods of a Struct (not only Execute) for a job?
@steady blaze
You can access static readonly managed arrays from burst and jobs
@solar spire LOL. Alright that's the most blunt "Nah fam" I've read in a long time.
It's very much something you don't recommend to anyone unless they're excited to get into trouble 😄
Fair fair.
Shame honestly. I played around with it and when shit clicks it feels good.
It's definitely a pattern I'd like to use in projects.
Do you know of any solid ECS Libraries that would be good to use?
Luckily I have Odin so that basically gives me inspector support or whatever 😩
no strings attached to sir
I've heard people in this channel say good things about Entitas
It's my understanding the paid version has extra features. I've never used it myself
@rancid shell Please don't post memes/reaction gifs.
@glacial bolt My bad. To be fair though that was a picture on the Entitas Github on their overview page.
Is Entitas strictly Unity is or it general use?
@rancid shell the paid version uses a better codegen
that gives less trouble
the ecs itself is the same
Less trouble how exactly?
the codegen in default entitas uses normal C# reflection, so your code has to compile
I went on their Discord and found that someone has made a variant called "Entitas Redux"
this gives some trouble when you want to rename components, for example
the codegen is the biggest issue on the open source entitas
yes, for a real project
How do you like it if so?
a lot, it works super well
the codegen was an issue tho
it makes it fairly hard to refactor things, like if you want to rename components or remove members of components
specially the removal is the biggest problem
This "Entitas Redux" seems to use a different code gen named "Genesis"
havent used that
i see it seems to use a different codegen and thats it
i wonder if it runs into the same issues
If you happen to figure it out, do you mind pinging me? Ngl some of this backend is a bit beyond me. I was just looking for an easy to use ECS Library 😛
the biggest problem with the entitas default codegen is that it breaks if you try to rename a member
so you rename or delete a member of a component
and then the code doesnt compile because the codegen-d code still uses said member
and because it doesnt compile the codegen cant use reflection to run
Even just deleting a member?
yes
Yeesh thats frustrating
you can "fix" by going into the codegen-d code, and deleteing the couple lines where it uses the member you just deleted
then you can safely re-run
in a way, the open source (or that redux version) is more like a trial
due to the fairly crappy codegen
as far as i know the money also gets you some support which can be useful
The code gen aspect of it is really strange honestly
Did you use the gen or did you just say fuck it and do it all yourself?
i used
in my case i just dealt with the occasional warts were the generator crapped itself
as i said, going into the codegen-d code and fixing it, then rebuilding
hmm
Is there a way to check for specific component types?
I'm seeing only by index
what you mean?
Like if I create an entity and give it something like a Position component. Can I then check if it has one and return the component?
Something equivalent to GetComponent and TryGetComponent in unity.
entity.hasPosition()
not popping up unfortunately
I am noticing a property though that returns a bool as to whether or not the entity has some Component I created
thats interesting
god thats strange
grab one of the samples and just check how it works
looking at the entitas wiki, what the fuck has happened? its a graveyard
a lot of the articles are missing
big sad
Alright well it doesnt take too long to change the values for the code gen
like you delete 3 lines per member
but is it 90$ annoying is the real question 🤔
I'm not having the entities/contexts appear as gameobjects during play mode
odd
doesn't entitas have a discord
not saying you can't post here, i think here is a good place for ecs talk
just mean it might be easier to get support
ye mb
So, is there a way to make jobs not use a direct 'reference' to a nativelist, the problem is that my creatures die and then that list gets removed and thus the job breaks because its reference is broken. (Specifically a IJobParallelFor job)
you could either copy it, or store it outside of the creatures themselves
in some sort of manager that only deletes it if the jobs end and the creature dies
isnt there a refcount system in Dots?
if this was cpp i would use a shared_ptr here
So, is there a way to make jobs not use a direct 'reference' to a nativelist, the problem is that my creatures die and then that list gets removed and thus the job breaks because its reference is broken. (Specifically a IJobParallelFor job)
@odd cipher
What do you mean the list gets "removed"?
well since the creature dies the neural network inside of it gets removed and then the job can't find the data it needs so it breaks
then dont delete instantly, and wait a frame to delete it
@odd cipher make any data that need to be manually destroyed by a system to be a ISystemStateComponentData
I do not use ECS at the moment @rancid geode
ISystemStateComponentData needs to be manually removed from an Entity, thus a perfect way to hold an "right-before-dead" state
well, that does complicates things a little bit, as without knowing how you are using it, it becomes hard to tell how you can manage it
@zenith wyvern thx, already do that, but does not help for my problem, as the content gets created inside the job.
it should be 3 arrays (int, float and float3), each the size of 8 and it should be accessible from the Job, but also from helper methods, as i do not really want to write the same 5 lines of code over and over again.
Seems there is no way to either: A.) Have private/protected NativeArrays within the Job Struct, that can be accessed by the whole struct, not only Execute. B.) Have sub-methods within the Execute of Job, as they can only access the Data created/defined in Execute and not the public NativeContainers that get passed to the Job.
So for now I did it like this:
1.) Define 3 NativeArrays within Execute - then pass in the 2 values and 3 NativeArrays to the helper method. But don't know if they get copied then or just referenced.
The safety system shouldn't be allowing you to dispose a list while a job is running
Are you disabling safety checks on your list?
If "[NativeDisableParallelForRestriction]" does that then yes.
though as vblanco recommended I moved the part where I destroy the creature to LateUpdate and that fixed it.
So that's one problem fixed atleast
@steady blaze If the content gets created in the job then yeah the only way to get it out is to copy it into native containers that you pass into the job
not needed outside the job-struct, but 12 times within one iteration, so want to have the 5 lines code that would be needed 12 times in a sub-method for the job. but it cannot access all the data needed (the job can), so the data needs to be passed over as parameter in addition to the regular 2 paramters.
so instead of: int GenerateVertex(int ci1, int ci2) I now have: int GenerateVertex(int ci1, int ci2, NativeArray<int> cornerIndices, NativeArray<float> cornerDensities, NativeArray<float3> cornerNormals)
I mean it sounds like you're doing the right thing, if I'm understanding right. If the content is created in the job it would make sense you would need to pass it around to any other static function that uses that content
it is a function within the same struct, as it also needs access to the public NativeContainers - just wonder why you can't have private stuff for the whole struct and if GenerateVertex always gets a copy of the 3 corner arrays or reference
i did paste a bit simplified version (with vertex caches for shared vertices): https://pastebin.com/62NibKHY
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
If you're passing a native array as an argument to a function, it's not a copy. A native container is a wrapper around a pointer. Unless you're explicitly calling NativeArray.Copy, there is no copying.
ah, ok - then should be ok I guess
@zenith wyvern are there refcounted versions? or a way to do a refcount
Not that I know of
that sucks
when you are dealing with multithreading its very common to need them
what if you have 1 job that creates an array, then 3 other jobs that read it, and you want to delete once those 3 jobs finish
without explicitly adding another job to clear the array with the 3 jobs as dependencies
Well the only way to get the array from the first job is to pass it in, so it can't "create" the array, but it would populate it. Then you would combine them all into one job handle at the end and do array.Dispose(jobHandle)
Not much better than having an extra job but that's how you have to do it
thats beyond jank
I've never messed with multithreading outside of Unity's jobs so I wouldn't know if it's any better or worse
I remember messing with shared pointers in C++ and it was...interesting. Not much different than native containers I guess
I find the multithreading on Unity jobs cool enough to not need to worry about the multithreading itself (as there is safety checks everywhere and, most of the times, clear error messages)
but... it is too much boilerplate as-is currently (only the Jobs part), it kind of relies on the Entities package to be "nice to use" currently
hopefully they will make jobs be as nice to use outside ecs someday
I don't know, I wouldn't mind a lot less boilerplate in ECS too, hahah
I've been wondering this for a while but, is it safe to sched a job inside a c# async method?
I don't know much about the async await stuff. It would only be safe if it's running on the main thread
The safety system will stop you if you try to schedule a job inside a job, I imagine it will just do Bad Things if you try to schedule a job from a non-unity-job thread
Stupid question, but why doesn't this work? https://pastebin.com/fTj62ZN5
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
It doesn't set the values of CirclePosition to 5.
So what is the nativearray pointing to in this instance?
It creates a copy of the entity's components in their current state. But the components are just plain structs, they're not actually pointing to anything.
Oh. Uh, I thought NativeArray indexes were all pointers. Got lots to learn. Thanks
They are, but because of how ECS works you can't create a direct pointer to an entity's component.
The entity itself is the pointer
I've been wondering this for a while but, is it safe to sched a job inside a c# async method?
@deft stump I've been using it without issues, just ensure that it is currently on the main thread before scheduling a job as Sark pointed out.
Hey so I'm trying to make a copy function of a class that returns a new class of the same type with the same variables but sending a nativelist to that new class still makes it so one change to it affects all the classes. How would I get around this?
you copy the native list into a new native list?
@odd cipher I think you need to use destination.copyFrom(source), something like that
possibly
yea or UnsafeUtility.MemCpy(dst, src, size)
sending the native list from one class to another will just copy the pointer so it's still pointing to the same content
yes, you need to generate a copy somehow
You can pass in the source array to the constructor of the destination
hm yeah, otherclass.myList.CopyFrom(myList.ToArray()); works
probably not the most efficient but it works
though, I also need to copy a nativemultihashmap which doesn't have such function.
So the memory layout for components needs to be known at compile time for it to be blittable. Does this mean I can't use lists or arrays without a declared size?
Yeah, it's an amortized operation. "Dynamic arrays".
So does that mean I can use NativeLists?
not directly in components, you will probably get a runtime error due to a safety check which makes that structure not blittable
Not sure what you're asking. Use NativeLists for what?
Yup, that's what I'm thinking.
there's DynamicBuffers you can use
@zenith wyvern as a property in my dots component.
Oh, okay. No, you can't. Like Psuong said dynamic buffers let you attach a resizable array to an entity
Or you can use unsafe containers but there's some gotchas
They get put on the heap if they expand beyond their initial capacity
Yup, okay. Makes sense.
Which you specify in an attribute on the dynamic buffer struct
Thanks guys. I'll try that out. Time to get back to my actual job. Fun times with microservices
Unity Physics promises to be deterministic. Can anyone confirm this or is this a baseless claim maid by unity?
Promises have futures
anyone knows how to get this working with a NativeQueue instead of Queue ?
https://pastebin.com/wSPUCuZY
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
well for starters a nativequeue must be created with an allocator of your choosing ie
_queue = new NativeQueue<T>(Allocator.Persistent);
hm, I guess instead of going the more elegant way of implementing a NativeCircularBuffer it would be easier to directly use NativeQueue in the Job and do the adding manually - something like this:
if (queue.Count == size)
{
queue.Dequeue();
queue.Enqueue(obj);
}
else
queue.Enqueue(obj);
sadly the UnsafeRingQueue does not support Peek and Clear
Ah, simpler, instead of cBuffer.Add(nextObject) it should be enough to write:
if (cBuffer.Count == size) cBuffer.Dequeue();
cBuffer.Enqueue(nextObject);```
I found out how to set T to be non-reference type and to pass over the Allocator, but about implementing all the dispose and allocation stuff right I have no idea and seems to be complicated
Ok, strange - have to forget it and use NativeList again, as NativeQueue does not seem to work with Burst
Sure it does I think you just can't create it inside a job
If I remember right. But NativeQueue is pretty slow I think, it's meant for writing in parallel from different jobs
ah, ok i see. anyway does seem to improve noticable. now tried with regular queue instead of list for the single-threaded version and with List the meshing-time is a little above 1.1 sec for size 100^3 and with Queue as CircularBuffer it is a little below 1.1 sec
So guess nothing to worry anymore. Only interesting maybe how to create a NativeContainer with additional functions just for curiosity and possible future use cases
and maybe Queue is also wrong type as it does not have a fixed size
although it's said the queue-version is faster … hmm
what i just think is a little time consuming: I do buffer.RemoveAt(0); at every iteration, so also for cubes that do not need to be drawn.
possible solution was to have a counter increased at empty space and then for next cube with surface do removeRange(0, counter) - but that got confused with the clear every row. could try again and set to 0 when clearing.
to me it sounds much faster to just increase integer value, instead of re-ordering a list.
does anyone know what exactly causes this issue?
it seems to be directing to the way I "copy" a NativeMultiHashMap.
NativeKeyValueArrays<Guid, KeyValuePair<int, int>> a = connections.GetKeyValueArrays(Allocator.Temp);
for (int i = 0; i < a.Keys.Length; i++) {
var valueEnumarator = connections.GetValuesForKey(a.Keys[i]);;
while (valueEnumarator.MoveNext()) {
n.connections.Add(a.Keys[i], valueEnumarator.Current);
}
}
a.Dispose();
try changing the allocator from a .Temp to a TempJob
temp allocs try to keep it on the stack which is limited in size, I usually default to tempjobs for all temp structures
@odd cipher
That seems to have fixed it, thanks.
@low tangle Well hm, I'm still getting this error occasionally. It's not consistent.
It's not erroring out at the allocating part though, but where you add to the collection
Could it be possible connections and n.connections are the same thing?
And since you're not using the Values part of the NativeKeyValueArrays why not use GetKeyArray instead of GetKeyValueArrays?
connections and n.connections can't be the same, its a new instance of the same class. And yeah that does shorten a bit but I don't imagine it would fix it
Have you checked how large these NativeHashMap's are?
well they can't be the same size, n.connections should be 0, connections can be any amount
if the n.connections hashmap is created with Temp or something, it might overflow it's size as well
no, it's created like this in the class
public NativeMultiHashMap<Guid, KeyValuePair<int, int>> connections = new NativeMultiHashMap<Guid, KeyValuePair<int, int>>(0, Allocator.Persistent);
Why not instantiate it at the right length right away?
If you keep running into this, it might be worth printing out the size of connections as well
as you mentioned it can be "any" size
which might be pretty high
Alright, I debugged it and checked the log after it crashed, it seems something very bad is happening as the connections list reached 65541 in size right before it crashed which it shouldn't have and I doubt that was caused by any of my other code.
the whole merging nativehashmap bit looks a bit off, is this a single thread job running after other jobs?
I haven't had to do that in awhile so its likely just me being unfimilar with it
I'm trying to create a Copy function for my class and it should return the same but.. a copy. So I have to copy that NativeMultiHashMap somehow.
Well, I'm not using ECS, just Jobs and Burst. And yes it's on the main thread
I wonder if the internal buckets of the hashmap are linear, might be able to memcpy them like I do with native arrays a lot
I'm on my linux machine at the moment, but I'll switch to windows and probe native hashmap in a sec if your still stuck
Hm, seems like it is quite different, if you assign a NativeContainer within a Job or outside. inside only Temp seems to work (wonder if problems occour, when it takes longer than 1 frame) and outside it has to be at least TempJob
yeah theres a warning on temp/vrs tempjob
its where the memory is being allociated from within unity's engine runtime
temp is likely thread local storage and temp job is more general from any thread malloc like
Yeah hm, you lost me there
its alright, not something you need to worry about
alright this should do the trick for a componentwise clone
the nativehashmap iterator works in jobs, but I'm not sure about the tuple for unique keys
can't remember how I made sure I didn't do duplicate keys before
the way the multi hash map returns values when iterating, returns a key:value pair for each bucket value, so if you have 0:1 0:2 0:3 all in the 0 key bucket, the key array* will return 3 copies of the key
@odd cipher
Alright, I'll try it out, Give me a minute
It seems like that fixed it, I'll run the game for a bit longer though to make sure.
ok yeah I'm very positive that it worked, thank you!
welp. here I go again, I got the error again and I'm guessing it's caused by my code at this point (though I don't see any way that could happen with my code). It reached 176832 in the array before it crashed. which shouldn't be possible.
glad it worked for you
just slowly work though why its adding / removing, log it if you can. make it clear how large the arrays will become. if you have any signal structuring (bools, value checks) verify their actually changing with asserts or logs
so i fixed an issue in new unity physics that really ruined my experience. anywhere i can make a push request or something? i didn't test the fix for regressions or anything like that tho (because i can't)
and it's more of a hack
Best you can do is make a bug report through unity then post about it in the physics forum with the id
i posted about it in the physics forum https://forum.unity.com/threads/how-do-i-properly-apply-angular-impulses-to-physics-bodies.992802/#post-6533669, do i just report the bug and paste the bug tracker id?
I would say so yeah. You could try pinging one of the physics people if you really want
On the forums that is
I would put the id in the title even. Make a new thread if you can't edit the titles
Hi all, sorry If im not asking on the proper channel, i want to ask you what I'm missing about importing BurtsCompile
I do not think so, how can I check about assembly definition? @coarse turtle
Well usually you would be creating it (right click in Project -> Assembly Definition)
so if you havent done that - does the code still compile in Unity? 🤔
or does it provide an error
the code does not complie because of that, its giving me this error
I just open the project and import the assets
Hmm - i assume you have the Burst package in your package manager
alright yeah install it and see if it compiles
yes, it compiles now, thanks! @coarse turtle
Can someone tell me why this code throws errors in the Burst compiler?
[AlwaysSynchronizeSystem]
public class InputSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
NativeArray<KeyCode> _keys = new NativeArray<KeyCode>(new KeyCode[] { KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D }, Allocator.Temp);
Entities.ForEach((ref InputData inputData) =>
{
NativeArray<Direction> directions = new NativeArray<Direction>(_keys.Where(key => Input.GetKey(key)).Select(key => new InputDirection(key).DirectionMapping()).Where(direction => direction != null).Select(direction => (Direction)direction).ToArray(), Allocator.Persistent);
inputData.directions.Clear();
inputData.directions.AddRange(directions);
}).Run();
return default;
}
}
Specifically I get these errors:
You can't use Linq in burst
Direction is an enum btw.
It returns tons of managed objects
waaaat~
I can't use it anywhere in burst or just in JobComponentSystems and the like?
Just in burst
Oh so I can move that code into its own object.
So inside the foreach
Hmm, let me try moving the code out then.
Yes if you populate the array outside the foreach and pass it in that's fine
Also for the record you should be using SystemBase now, it's a better replacement for JobComponentSystem
For instance you don't need [AlwaysSynchronizeSystem] of you're using SystemBase, it does that on it's own
Hey all, any good resources for how to implement hybrid DOTS architecture? I tried pure DOTS a while ago and found it clunky (no strings or bools cus they aren't blittable, etc) but am very interested in learning / adopting it.
No really. There's lots of resources on pure dots stuff, Project Tiny has lots of good examples. Sadly hybrid stuff doesn't have a lot of good examples
Ack, that's too bad! I'll give project tiny a look.
Huh, lots of weird rules to enforce memory layout guarantees.
@zenith wyvern So I tried moving the code into its own object, declaring it before the foreach loop, but now it's saying I can't call reference types from inside the entities.forEach loop:
public class InputSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Foo foo = new Foo();
Entities.ForEach((ref InputData inputData) =>
{
NativeArray<Direction> directions = new NativeArray<Direction>(foo.Directions(), Allocator.Temp);
inputData.directions.Clear();
inputData.directions.AddRange(directions);
}).Run();
return default;
}
}
public class Foo
{
private readonly KeyCode[] _keys = new KeyCode[] { KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D };
public Direction[] Directions()
{
return _keys.Where(key => Input.GetKey(key)).Select(key => new InputDirection(key).DirectionMapping()).Where(direction => direction != null).Select(direction => (Direction)direction).ToArray();
}
}
Yeah you can't have any managed objects inside burst at all, unless you're doing pointer stuff. So you're trying to create an instance of a reference type with new Foo which is not allowed. Burst can only access managed arrays if they are static and readonly
So anything to do with managed stuff has to happen entirely outside the foreach, you build your burst-friendly data, then pass it in
Is how it's generally meant to go
How do people write games in DOTS then? I was going for the approach of writing testable objects that do all the logic and on the data itself. I assume people are still using classes and other non-primtives when writing Unity games.
Oh, you create all that data ahead of time in the nice format Burst wants
Before the for loop
Well people made games without OOP long before unity adopted ECS, right? You just have to try to get into an DOD mindset
You are going OOP, ECS is DOD
Like I mentioned earlier if you want some decent examples of "full" working prototypes check out the Project Tiny samples
this is the best read I had on the subject: https://www.dataorienteddesign.com/dodbook/ (I bought the kindle version, but I heard that the online version if very enough to get the point)
Data-Oriented Design
They are actually pretty well written and easy to understand
Although they're a bit weird since Project Tiny can't use any UnityEngine stuff, which obviously is not a normal restriction
is DOD different from Domain Driven Design?
You know what, that's probably for the better. Project Tiny looks good.
never heard about DDD until now to be honest
I'm not sure what Domain Driven Design is but it sounds different. DoD basically just means completely separating your data from the stuff that operates on it
DDD reminds me of Scott Wlaschin for some reason
He's that F# shill, smart dude in general.
I see, Reading up on DoD. I think there are actually pretty compatible. DDD encourages modeling your domain in intuitive ways while DoD encourages keeping behaviour separate from the model.
Yeah i was introduced to DDD from F# & functional programming
It's also meant to put an emphasis on thinking about your data in the same your computer does, instead of OOP where you model things in terms of humans
for performance reasons?
DDD is basically "use algebraic data types to model the domain". DOD is "fuck the world, you design your program around data.
I don't know if that's the main reason but it sure helps
I find it helps avoid spaghetti hell a lot more than OOP does. But that's down to each person I'm sure
totally agree
it is all about getting used to it
be aware that you need to clear you brain from all the OOP stuff you were taught about before
probably the hardest part haha
i think it is well going outside your comfort zone. i am a big fan of trying out different paradigms to see how your brain breaks.
been wanting to do some haskell for a while 🙂
Addind to this conversation on not doing OOP in DOD.
This vid helped me write better dots code
code::dive conference 2014 - Nokia Wrocław
http://codedive.pl/
this is my fav talk about DoD https://www.youtube.com/watch?v=yy8jQgmhbAU
http://CppCon.org
—
Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2018
—
For decades C++ developers have built software around OOP concepts that ultimately failed us - we didn’t see the promises of code r...
he uses DoD to optimize parts of the web renderer for Coherent UI
ok i submitted the bug about unity physics, hope i did everything correctly
why do fixed step simulation component group systems not execute every fixed step?
Thanks for the videos, will have to watch those later.
I am trying to improve the architecture which I am using to write in dots..
For instance, before using oop with a bunch of enemies, updating them in a controller I would use something like:
fixed update:
update rotation();
apply rotation();
updateMotorThrottle();
UpdatePosition();
ApplyPosition();
UpdateAnimator();
and now in ECS it is very similar but instead using systems for each step piece. The only part that is uneasy is that there is no master hierarchy where each step is listed in succession like there was in oop, so it feels very manual trying to place them all in the correct order. I know it will do the same calculations, I just feel like there is room for error for me because I can mess up the order. Is there a good way to organize these systems? I use groups, but still make mistakes with order if I add or edit something. Is there a good way to think about this sequence? or structure it differently
there's [UpdateAfter(typeof(yourSyste))] and also UpdateBefore
yeah that's what I use, in each class
but would rather call each manually in a manager as kind of an overview, but i feel like that is kind of against the point of it
You can still get an overview doing it how you're doing it by looking in the entitymanager. It shows the update order of your systems
Okay, yeah I see that too. Maybe it's just retraining my brain, just wanted to make sure I wasn't approaching it ineffectively
I'm not really a fan of the UpdateBefore/UpdateAfter stuff either. But it works I guess
yeah same, seems like there should be a tool to view all in a group and drag the order. Obviously it's in beta so can't complain too much
Is there an equivalent to scriptable objects for entities?
BlobAssets
There's no sane way to convert SO's to blobassets though. It's all very manual and bad
ok cool i'll research on those, don't really know much about them
yeah i want to move away from SO because they are random in memory anyways right
You should still use ScriptableObjects for editor representation, just convert them to blob assets or entity representations when you need to use them in, similiar to how you convert prefabs/gameobjects to entities
Okay, I kind of do that still
Hi, is sending events to specific systems a good idea?
For something like that you should consider an "event entity" first. If it's something that's going to happen once or more per frame then you should consider direct messages or some kind of event system
yeah there is a esclation of complexity you should follow
one of the main blockers to using ECS to make the whole game will be rendering and audio
those will require a hybrid approach or fully do it your self setup. the hybrid renderer is getting there, but audio is very much isolated in its own. pick your battles wisely, and dont forget you can always still use the entire normal unity gameobjects and components, there is no issues with getting data in out of ecs worlds
Wym by direct messages?
Like subscribing to an event or just directly calling a function in another system
I mean it directly couples your systems which is bad. But sometimes it's the right way to go
Why is it bad to couple systems?
The same reason it's bad to have public member variables in a class. Just basic good practice stuff
Oh
Is it a good idea then to say, have a public system function that modifies an entity's component data?
Only if it's static and doesn't touch any mutable static data
Rip
@low tangle speaking of escalating complexity, have you given animation a try?
Hey, is it possible to serialize an Entity? 🧐
yep, managed to get the two bone ik to do what I wanted, but that was when I was assessing porting to it
the complexity in that main job chain for setting up the data per frame was just too much
that and the skeleton structure was a bit weird, can't remember how though
I've gotta do a lot of skeletal retargeting within my game, so that part needs to be a solved system. so trying to port to the new animation system was a non starter
but I wanted to try and feel out the what if
i think i just figured out how to get rootmotion data for the purposes of physics velocity without it enacting on the translation, but man its a lot to process along with dataflowgraph stuff
for real
did you see the rigremap example in regards to skeletal remapping?
in the meantime I've been porting more stuff over to animation jobs which was pretty painless so far
nah I'm super out of date on examples
haven't touched it for maybe 4 months
well i think technically these examples are from that era(found refs in the docs that refer to 0.5) but it has an example that looks topical to the retargeting
gotcha
I've already ruled it off the shelf for this game, but maybe in a side project
huh just noticed RequiresEntityConversion is obsolete now
probably best to use 2020.1 and up for dots
and yes its still in development @gusty comet
has anybody else been experiencing the problem where networkid entities aren't being spawned for players joining?
havent touched networking sorry
all good
the problem started after i overrode the bootstrap code with my own
its the same as it was but for some reason it just doesn't want to make the entities
So generally in ECS, can components hold reference to other Entities/Components?
you can have a property of type Entity in a component to reference another entity
with that entity, you can then access its components the usual way
Hi, is there a way to clone worlds?
How would you make a system to be able to click on Entities?
@green path EntityManager.MoveEntitiesFrom (EDIT: actually that doesn't copy systems.... so I'm not sure)
@odd cipher define a component with some location data and add it to the entity. Define a system that checks for mouse clicks, then ray traces from the center of the screen to results from the query for your location data.
Hm Alright, but for the location couldn't I just use Translation and compare it?
translation is a component on an entity. yes
you'd probably also need some size though too. an infinitely small point will be very hard to click on @odd cipher
Yeah I had that problem earlier with a previous attempt. I'm not sure how to do that though.
you could use a sphere collider, then a physics ray trace
or a mesh collider if it already has some other physical shape
You mean using the Physics package or?
Maybe just comparing distance between 2 vectors ?
First one is the mouse click, other one from the Transform
@karmic basin Tried doing that but the result isn't very consistent.
This is how I tried doing it csharp protected override void OnUpdate() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, 10000)) { Entities.ForEach((Entity entity, ref Translation translation) => { if (Vector3.Distance(hit.point, translation.Value) <= 1) { Debug.Log("Hello!"); } }); } } }
the result isn't very consistent due to that '1' and increasing it really any further makes it possible for it to select the wrong thing.
It doesn't seem like the best way to do it and I do need some sort of collider so I guess I should start with that?
Yeah I downloaded it just 10 minutes ago, I'll have to learn it :P
Hello folks! I recently learned about the existence of ECS and DOTS. But migrating my long time OOP mindset is going to be quite a time consuming task. Could someone recommend me some material on the subject besides Unity documentation?
@lusty dirge this might be up your alley - recent presentation from a small tech conference (Handmade Seattle): https://docs.google.com/presentation/d/1YAIcjRIuyjNaMcn9ep_H8rNNkAfqPlVVUH9QZ7hr7Io/edit#slide=id.p1
Oh thanks a lot!
https://www.youtube.com/watch?v=yy8jQgmhbAU also another nice talk from 2018
http://CppCon.org
—
Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2018
—
For decades C++ developers have built software around OOP concepts that ultimately failed us - we didn’t see the promises of code r...
i also have an unorthodox idea
try to program in Rust
turns out that if you try anything remotely OOP in rust you will cry tears of blood
not only does inheritance straight up not exist, but pointery data structures and objects pointing to objects is near impossible to get the compiler to approve it
learning rust helped me on the dod mindset, as its basically what does work best in Rust
yea I agree with the rust part - also their error messages are really nice and show you where it's a problem
Anyone able to help me make sense of this error? UnityPlayer.dll caused an Access Violation (0xc0000005) in module UnityPlayer.dll at 0023:61cd63dd.
Log: https://hastebin.com/isewibuzok.yaml
I'm working with the Unity Job System and think that may be a culprit,
I'm using a custom bootstrap for my netcode worlds
are you able to get the networkid entities to spawn
for some reason when clients connect to my unity isn't creating their networkid entities
Huh, that sounds really weird. Does your server actually listen for connections?
Do you call something like this when you create your server world?
var network = s_ServerWorld.GetExistingSystem<NetworkStreamReceiveSystem>();
var endPoint = NetworkEndPoint.LoopbackIpv4;
network.Listen( endPoint );
How would you enable UI / call a script through a ComponentSystem?
@odd cipher you'd need to run GameObject.Find or something simillar from OnStartRunning() then when you want to just call gameobject.SetActive(true); when you want to
but you'll need to disable burst for it though
@north bay i've definitely got code that does it
i'll try adding some debug statements
I'm trying to run the FindObjectOfType function but it doesn't seem to be working and the gameobject it returns is null.
are you running it from OnCreate() or OnStartRunning()?
@north bay that gets run to move to the game scene
the methods for client only join etc are simmilar
OnStartRunning. I'm not sure what the difference between the two are.
simmilar to Start() and Awake()
try switching to a Find() or tag based find
@north bay this is ConnectLocal()
That did not work either.
hmm
Looks like this ```csharp
CreatureViewerUI creatureViewerUI;
protected override void OnStartRunning() {
creatureViewerUI = GameObject.Find("Creature Viewer").GetComponent<CreatureViewerUI>();
}
it's used later in OnUpdate.
That line does give and error stating that it did not find that GameObject and yes, it's the right name.
ok
this is some simmilar code that works for me
you could try using a singleton in a monobehaviour and getting the reference from that
fyi: Yes 0.17 release should happen in the next ~3 weeks.
so have a static CreatureViewerUI inside CreatureViewerUI
and set that in the monobehaviour's Awake()
I just realized I had the gameobject disabled this whole time, though enabling it and changing it to use a singleton worked. Thank you.
lol, happens to the best of us
Mhm, sadly I have not been able to get the Raycast to work great, it sort of works but it's not precise at all. I'm not sure if you know anything about it.
BuildPhysicsWorld buildPhysicsWorld = World.DefaultGameObjectInjectionWorld.GetExistingSystem<BuildPhysicsWorld>();
CollisionWorld collisionWorld = buildPhysicsWorld.PhysicsWorld.CollisionWorld;
UnityEngine.Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastInput raycastInput = new RaycastInput() {
Start = ray.origin, End = ray.direction * 1000, Filter = new CollisionFilter() { BelongsTo = ~0u, CollidesWith = ~0u, GroupIndex = 0, }
};
Unity.Physics.RaycastHit raycastHit = new Unity.Physics.RaycastHit();
if (collisionWorld.CastRay(raycastInput, out raycastHit)) {
Entity hitEntity = buildPhysicsWorld.PhysicsWorld.Bodies[raycastHit.RigidBodyIndex].Entity;
CreatureViewerUI.instance.ShowEntity(hitEntity);
}```
I'm guessing the problem might be caused by the camera being able to move.
In this case, no I'm not using Jobs.
are you moving the camera before or after the raycast
it might be raycasting from the old position
camera movement is based upon the players input.
yes but does the raycast happen before or after the camera actually gets moved
I'm not sure.
just look at the code order
Though the problem still happens when the camera is still so I don't think that is the cause
@shy pilot If you'd like i can send you the custom bootstrap that i use, but it also includes some project specific stuff. I don't know what's breaks your connection flow so maybe some reference could help you figure it out.
otherwise you can add an [UpdateAfter()] to the system
yeah, that'd be great, i might tinker with my one for a couple of minutes though, i think i might know what's up
I tried to cut it down, that should be the core of it https://hastebin.com/uyapifihen.csharp
thanks :)
i'm beginning to suspect other things
some of the entities that are spawned from foreaches on networkidcomponents are there
does the client see the networkids for other players? I feel like i should know that by now 😆
I'm sorry, what do you mean with the client's entity?
so in the client world there are two networkidcomponents right?
one for the server and one for the client?
No the client only has one NetworkIdComponent which contains his information
The server has one for each connection
Are there any other ECS Libraries you guys suggest using while Unity's ECS remains in development?
not that i know of, unity ecs is designed to eventually take over from the traditional oop/go workflow
at least that's my understanding
designing an alternate system like this requires a lot of low level access that only unity's staff could achieve
though i might be wrong
Exitgames games made an ecs for unity, but that's more of a game engine itself.
Its fine, thanks for the help anyway
Still, it would be great if anyone can provide a way to clone worlds
clone entire worlds? hmm
do you want to create 2 clone worlds from the start, or you want to make a copy of a world mid game?
there is no out of the box solution as far as I know. I would just manually do the copying by doing a query in my first world, and creating new components with copied values from the first world's components
Hmmm
am I the only one that is so slow to recompile script changes? 1 line change takes about 15 seconds, and then it's another ~10 seconds to get into play mode.
In 2020.2 beta it's a little better but recompile still slows down once I get a lot of scripts. Enter play mode is instant because I use the enter play mode editor option
you can speed up the play mode bit
under project settings > editor,
that makes the play mode bit instant for me most times
but not the building part
It's important to note that you need to write code to reset all your static variables if they could impact the game if they persisted
using assembly definitions can help too
and in earlier versions of Unity there are lots of other things that can break
UI gets screwed for me on 2019.4
@compact robin there's entitymanager.copyentitiesfrom, you use that with the entitymanager of the other world
Oh wow thanks a bunch I will try it out
Btw, do you think they would retain their entity ids?
not sure but would think not
since those id's could already be taken
if you're asking because you're using Entity references in your components, that'd prob be fine, i think unity remaps those when copying
But if I clone to a new blank world, it shouldn't be the case. Guess I will have to find out lol, thanks again
Hey anyone able to help with the Raycast problem I had yesterday? scroll up a bit and you'll find it.
At a glance, code is looking good. Can you show a screenshot of your scene view where you try to click to select your object ? Maybe something wrong with your setup or the collider ?
the collider seems fine to me, this gameobject gets converted when instantiated as a prefab.
@karmic basin
Yeah so I assume you see a Physics Shape component in the entity debugger afer the conversion
Man I dont know I might have missed something
You set your Filters to 1 and I assume too thats the case by default with your Physics Shape component
isTrigger should be false
I'm out of ideas at this point
I'd say try to debug log some values or debug draw the ray, just to make sure
I'll try and use Gizmos to draw it, I'm not sure how but I'll try.
Debug.DrawRay()
@karmic basin The raycast is hitting the entity correctly but it seems to go undetected.
I think I cant help you more than that 😦
If it's the Unity dots physics package you might want to check that the collision flags/bitmasks match
I'm not sure how those work.
Usually the PhysicsCategoryNames (a scriptable object in your project) lets you define some names for your bitmask
so in the PhysicsShape/PhysicsBody (I can't remember which one from the top of my head) component you'll see an option that says BelongsTo and CollidesWith
Yeah that's the filters, I assumed it would be set to Everything by default because its converted from GameObjects
the raycast's collision filters flag should try to collide with the CollidesWith bitmask of your other physics shapes
and yeah I can't remember if it does Everything by default also
neither do I. Would have to open Unity and try myself at this point
If everything is setup correctly only thing I think of is Systems order is incorrect (might be executed too soon, before the physics world is computed)
Hm, well the recast does get triggered occasionally but it's definitely not correct. When clicking directly on it nothing happens and occasionally when clicking slightly outside of it it gets triggered.
@odd cipher Have you tried adding the PhysicsDebugDisplay component to the object with the PhysicsShape/Body component?
I have not, what does it do? @gusty comet
@odd cipher visualizes collision events and colliders: https://docs.unity3d.com/2020.1/Documentation/Manual/PhysicsDebugVisualization.html
Oh that’s very useful, I’ll try it out as soon as I can, in about 10 minutes or so
@gusty comet Well here is how it looks, and the raycast is hitting this area but nothing happens.
Or well, in some cases it gets triggered and in others it doesn't.
So Ive been very depressed and not working on this game for the last 2 months.
I think Im starting to warm to the idea of working on it again. I think when I do Im going to jump into player controls player movement, etc.
So, my question is, for traditional player control stuff, does one typically just work in game objects instead of dots?
You don't need to bother with gameobjects, but you can't do your input polling inside a job or inside burst. You just need get get your input on the main thread and pass it into your jobs as needed
yeah that makes sense. and the camera, I imagine you cant change the camera's position in a job, right?
or can you
well you can make a job and then copy that info back on the mainthread to the camera but unless you are doing something crazy expensive its easier to just mainthread the camera's position. its just one entity
@odd cipher did you make sure to remove the default collider components on the primitives? If you have, e.g., a capsule collider AND a physics shape, it will screw everything up
Nope, same deal. Right now there's no ECS version of the camera. But they have it set up so if you convert your camera to an entity you can access it via non-bursted .Run jobs at least
also @tight blade theres an example of using the inputsystem in an ecs system to get your input without gameobjects, its actually in the physics samples
youre telling me the physics samples has usefully current code?
The physics samples are still lagging a little behind. Better than it used to be though
it always has, some of the examples are a little contrived but its always been very useful
I dont know, in the past, I've spent more time trying to make an example work that used an outdated abstraction than when I just started by looking up the stuff in the decompiler cache
@tight blade I do not have those. By the way, if it matters, the ground the entities are on is also an entity.
well, that was my shot in the dark to help. Heres another shot in the dark: you said it occasionally triggered when clicking slightly outside the bounds. Is it possible that the trigger is occurring when only the outermost collider is hit by the ray (i.e. the ray does not hit any of the inner collider shapes, just the outer one)
I dont have a solution for you if that is the case, but I'm curious about the answer to your problem and want to narrow it down lol
@zenith wyvern are .Run jobs on the main thread?
Yup. So once your camera is attached to an entity you can do
Entities.WithoutBurst().ForEach((Camera cam)=>
{
cam.transform.position = float3.zero;
}.Run()
@tight blade Well, I feel like that would be findable in the code for the raycast but I can't see anything that is wrong. ```csharp
BuildPhysicsWorld buildPhysicsWorld = World.DefaultGameObjectInjectionWorld.GetExistingSystem<BuildPhysicsWorld>();
CollisionWorld collisionWorld = buildPhysicsWorld.PhysicsWorld.CollisionWorld;
UnityEngine.Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
raycastInput = new RaycastInput() {
Start = ray.origin,
End = ray.direction * 1000,
Filter = new CollisionFilter() {
BelongsTo = ~0u,
CollidesWith = ~0u,
GroupIndex = 0,
}
};
Unity.Physics.RaycastHit raycastHit = new Unity.Physics.RaycastHit();
if (collisionWorld.CastRay(raycastInput, out raycastHit)) {
Entity hitEntity = buildPhysicsWorld.PhysicsWorld.Bodies[raycastHit.RigidBodyIndex].Entity;
if (World.DefaultGameObjectInjectionWorld.EntityManager.HasComponent<NeuralNetworkInfoData>(hitEntity))
CreatureViewerUI.instance.ShowEntity(hitEntity);
}
Im a data scientist by trade, I tend to try to poke the running application to see if my hypothesis is supported before I try and find an answer in the implementation
Ah, fair enough. Give me a minute
From what I can tell after a bit of testing, it's just very inconsistent. The result changes depending on camera position and so on
@zenith wyvern so would it be equally effective to just have the system run entirely in the onUpdate with no job?
does putting it in a .withoutBurst().Run() actually buy me anything?
@tight blade besides allowing you to access managed types, sometimes the cost of scheduling outweighs the actual cost of the work being done. i get more fps in my game disabling jobs than running with jobs
does it even schedule anything when you do .withoutBurst.Run?
the work that you .withoutburst.run is not scheduled, it runs immediately
well, thats good at least, but still it seems like theres no point doing that when you have a single entity that cant be operated on in a job
probably just move the camera directly in the system update
what?
Im just saying this doesn't seem worth it:
Entities.WithoutBurst().ForEach((Camera cam)=>
{
cam.transform.position = float3.zero;
}.Run()
compared to what exactly?
ill probably just have a static reference to the entity and just do
override public void onUpdate():
this.cam.transform.position = float3.zero;
so how are you finding that camera entity then? seems like you are just kinda fighting what exists to make your life easier
yeah, thats a reasonable point. the primary point of my asking was just to see if there was something else which I didnt realize the Entities api was giving me
Hi... does anybody know what the "proper" way is to have animated entities that work with the DOTS netcode? I've tried:
- Using com.unity.animations. From what I've heard, this is is the early stages of development and not recommended for use unless you're explicitly testing it.
- Using a GameObject with ConvertToEntity set to "ConvertAndInjectGameObject." AFAICT netcode can't create ghosts that rely on ConvertAndInjectGameObject.
- Using a GameObject with an Animator and a component with IConvertGameObjectToEntity that calls conversionSystem.AddHybridComponent on that animator. This doesn't seem to work, for reasons that I don't fully understand and haven't debugged yet.
Is there a recommended approach that I'm missing? Thanks!
Re #3, it looks like it does hit the code that would trigger the animation on the companion game object, but that doesn't result in the entities rendered using the HybridRenderer actually animating.
Is there a way makeForEach run on average once per 100ms per entity? Example: Run ai for 1000 bots every 100ms at 100 fps. ForEach will process 10 bots (different) per frame.
Actually I a want it every n physics steps, not frames.
😄
@sand dome I'm not aware of such thing. you would have to use queries and do the logic yourself
@candid verge the dots shooter sample might give more insight, which uses unity animation. if you add the dataflowgraph package explicitly it has samples that imo are key to trying to understand how unity animation works, ive barely scratched the surface but i havent touched netcode
Thanks for the suggestion, I'll take a look.
Are you referring to the FPS sample or the DOTS sample? The former hasn't been updated in 2 years and the latter 7 months, so I'm not sure how current the examples there will be.
should post on the forums if you have any more specific questions about unity.animation. i only know one other person on this discord who is also trying to figure out animation 😆 you might get more eyes there
kk, will do.
latter, welcome to the wonderful world of dots animation(you will need to analyze the current samples in context with the dotssample)
if you see in the animation changelog around 0.5 a number of systems and stuff got name changes, that will probably be the biggest hinderance to understanding whats what
is there a concise example of accessing a MonoBehaviour from DOTS and DOTS from a MonoBehaviour?
Yo, is it a MUST to call Job.Complete() if I do not care about the completion state of a job?
@compact robin it's a must to not call Job.Complete() if you want maximum performance ^^
Why?
It just ensures that jobs are complete, no?
The job*
And in fact, it creates a sync point I think
@odd ridge
no, it stalls the main thread until the job is done
no it doesn't create sync point
sync points happen when you don't call job.complete(), you don't need a sync point if you run code synchronously
a sync point is when there's a change in one or more entities, which would invalidate all the data the previous scheduled jobs are holding if it happens.
So they need to complete those jobs before the change happens.
@compact robin what kind of job do you have that you don't care about the completion state?
generally at one point or another you want to sync that data back to main thread
You mean it doesn't auto complete?
Because Jobs will have its IsCompleted value set to true
Once its done, no?
Do I have to call Complete() if such is true?
yes. to properly close the job.
if (Job.IsCompleted)
{
Job.Complete();
//ret of your code
}
afaik, IsComplete check if the job is finished but it doesn't close it.
So your native containers are still being "used".
So calling Complete should close it properly so you can do stuff with the nativecontainers
What if I'm not using native containers? @deft stump
@compact robin job.Complete is for when you need the job to be completed right now, it is not needed to be called unless you need the job to be completed at a specific point of your code
Yeah my job is a fire and forget one
then you don't need to call Complete at all on it
Nice, thanks for the info
just run and, well, forget
So your native containers are still being "used".
Is that true?
If I don't call complete() ?
Say if IsCompleted is true
But I didn't call Complete()
you can see Complete as "PriotizeThisAndDontMoveToNextLineUntilIsCompleteIsTrue"
yeah, basically that
Nice then
So it won't lock the NativeContainer
If I don't Complete() it right
Despite the job being already complete
no, the NativeContainer will be locked while the job is running, when the job finishes the NativeContainer will be unlocked
if you need to re-use the native container (which would be a persistent one), then yes, you will need to either Complete or check for IsComplete before re-using the container
but the Safety Check should help you to know if that is the case
Ah that's nice
So Imma assume it auto unlocks the container when the job is done
Without me having to call complete
I just wanna avoid the extra function invocation
Which takes time
correct
I have a queue, which checks to see if a job is complete, if it is, I dequeue it
Else it requeues the job
Instead of forcing it to complete right now
Thanks for the help :>
Thanks to Scorr as well
i dindu nuffin but sure i'll take credit
Any news on new packages? It's been nearly 2 months since the last one with little news 😅
Jaochim said on the forums the next version should be out in the next couple weeks or so
What's that?
whaat has it really been 2 months already
changelog says 09 but thought it came out like a month ago
I think a better qn would be, when they can actually document ECS stuff @_@
@deft stump actually it is a sync point, a structural change(which is also a sync point) is when there are changes to the entities/entity data
I stand corrected then
Like when a comp gets added /removed? Cuz it moves in / out of the chunk
if you are referring to structural changes, yes
You have component sync points which will force all jobs related to a component or set of components to complete immediately, or a structural change which will force all ECS jobs in the entire game to complete immediately
Yes
anyone know what exactly this means in the hybrid renderer docs The following hybrid components are supported by Hybrid Renderer: //blah - ie if its a hybrid component, what exactly is the hybrid renderer even doing related to those components? is this just unrelated conversion documentation?
tf is dots
@wanton fossil https://unity.com/dots
so basically stuff only large games need
I mean if you want perf
Yeah
And it keeps stuff organized
Cuz you're forced to code in that way
every game (not all of them) needs perf.
it means that those components are compatible with the sub scenes approach without requiring you to create the conversion systems yourself when using the Hybrid Renderer
all it does for you is to call AddHybridComponent for those specific components
Is it me or that sounds super ironic xd
Though I do agree every game needs perf, since 1 fps is like unplayable
@rancid geode thanks
hmm this seems useful for when I want to start optismising
But a lot of stuff are not DOTS compatible yet
Which is why I decided to try it out only this year
The lack of documentation is @_@
Yeah you also need to dig through the examples
even then, the spec moves so fast
but still they made an effort to begin introducing the concepts form a high level perspective on the packages docs, kudos to them on that point
How relative is this book in understanding the DOTS paradigm:n https://www.amazon.com/Data-oriented-design-engineering-resources-schedules/dp/1916478700/ref=sr_1_2?crid=1KYM3YEWTDFLS&dchild=1&keywords=data+oriented+design&qid=1606001642&sprefix=data+ori%2Caps%2C420&sr=8-2
No idea tbh, but I think there's this free PDF online that people recommend for DOTS
Do you have a link?
Let me try finding it brb
I've not read it
It was recommended to me
Brb
Data-Oriented Design
This is the one apparently
🧐
LOL that's the same exact book I referenced
@gusty comet it's pretty related
as much related as reading an object oriented book to better understand classic Unity gameobjects
It is?
Wtf
LOL
I always thought the book is free
The book literally feels like
Reading a website via Internet Explorer 8
There is a free version and a paid version with a few more content. I have read the paid version, and I do recommend for anyone that is struggling to understand how to think in a data-oriented way
I'm reading the paid version so far. In the first few sections it is basically making the case that OOP is inferiour to DOD. That change in code is going to happen and in OOP you have a lot of dependencies of data to methods and classes to other classes.
So if I wanted to have it so an entity had a series of stats
should I make 1 "Stat Component" which holds them all in something like a dictionary
or just make a bunch of different types of stat components
Hey, has anyone recently tried the Hybrid Renderer V2 ?
I just enabled it and while it doesn't have major rendering glitches anymore, the performance seems to be worse by up to 30% in the editor 😦
oooh the package manager failed to resolve when it hits the 2 min mark is now resolved the b12
How would I go about 'replicating' a entity through a System?
could you give some more context? can imagine multiple things for that one
Hm yeah, I have multiple entities that all have a chance to replicate / reproduce. And when that happens, I need to replicate that entity.
as in create a copy with the same components+values?
Yes
EntityManager.Instantiate(entity) should do that i think
don't remember if it only copies the component types or the values as well, but guessing the values too
I'm not sure if it's possible to get the EntityManager in a System though? I'm quite new to this
How do I dispose of (delete?) a DynamicBuffer? Say I want to remove it from an entity in a system?
@hollow sorrel Entities.ForEach Lambda expression makes a structural change. Use an EntityCommandBuffer to make structural changes or add a .WithStructuralChanges invocation to the Entities.ForEach to allow for structural changes. Note: LambdaJobDescriptionConstruction is only allowed with .WithoutBurst() and .Run().
I'm guessing it's due to using Burst?
ah yea
if you're doing it in a foreach you gotta use
.WithoutBurst()
.WithStructuralChanges()
.Run();
instead of schedule() as it's a structural change (creates new entities)
Also, How would you go about changing a entities color after it's instantiated :p?
I don't think you can do that, unless you're talking about some different color component than the one for GameObjects.
oh yea if you're using hybrid renderer it's different
not sure about that one, not using hybrid renderer
gotcha
EntityManager.Instantiate(entity) returns the new entity
on that new entity you can then call setComponentData method
then check the material related component in the Entity debugger, I dont remember how it's named
once you have its name you can edti the value of this component
edit*
I didnt try but that's a guess
@karmic basin That does make sense but I cannot find any component in my entity that relates to a material.
Oh wait nvm I might've found it
Tried doing this but it made it apply to all entities. ```csharp
RenderMesh renderMesh = entityManager.GetSharedComponentData<RenderMesh>(creature);
Material material = renderMesh.material;
material.color = color;
renderMesh.material = material;
I'm guessing it's because of that SharedComponent part, I don't know much about it but it does have 'shared' in the name :p
So... how do I start a particle system attached to an entity? Post conversion, the particle system doesn't appear to have an ECS component that I can get a handle on.
I'm looking to .Start() and .Stop() the particle system at runtime.
(Really, the complicating factor is that the particle system in question is attached to a Unity NetCode Ghost, and on instantiation, it's not starting to run in the client presentation.)
Well it’s a managed component so it needs to be accessed on the main thread but there isn’t really anything special to it. Personally not using net code so not sure if that adds any wrinkles to component access
I can deal with it being on the main thread. Can you point me to an example of accessing a managed component from a System?
Entities.ForEach.WithoutBurst((Entity entity, ref LocalToWorld localToWorld, ParticleSystem particleSystem, Transform transform)=>{
transform.position = localToWorld.Positon
particleSystem.Play();
}).Run();
i dont know how you added your particlesystem in the first place but that presumes you added as a managed object or hybridcomponent
Well, that definitely got a handle on the component. I didn't realize it would be that easy, because everything else tends to be hard when it comes to ECS.
However, I'm still not able to see the particle system on the client side. Interesting. I'll report back once I've come up with the answer, for those curious.
Thanks for your help, @safe lintel !
good luck 🙂
Yeah, so here's the weird thing. I pause the scene when the explosion is occuring, and I go to the scene tab, and i can see it fine. Then when I go to the game tab, it's now appearing. I'm starting to this this might be a bug either in Netcode or URP
Womp womp
I had the material set to transparent instead of opaque. 🤦🏻♂️
I'll show myself out, thanks 🚪
gotta love the silly things that eat up so much time
Im a beginner, and trying to optimize a monobehavior based project
Can i use the job system to check for triggers?
I'll use the particle system jobs, and wanna know what each particle is triggering with what collider (so i want the ID of the particle, and the array(?) of colliders it's triggering with, to be used in the main thread)
As in, im still using unity's default physx(?) colliders
Earlier you said you were in an Entity.ForEach lambda, did that changed ?
Through the foreach args you can query the entities with the RenderMesh component (plus other relevant components as you need). This way you can access material on a single basis.
I'm on the phone so I dont write the code but hopefully you see what I mean
@karmic basin Oh right, There are two places I need to do these in, when they replicate in a ForEach and when they originally get spawned which is in a Monobehaviour.
Actually as its a shared component I might said something wrong. Unfortunately wont be able to test this as i'm waiting for a new SSD delivery, so no computer for 2 days
Alright
I didnt tried yet to have entities with own material
If you Instantiate by code i'd say putting a simple Component instead of shared one should be straightforward. But in case of conversion from GO, not sure what happens
@odd cipher a good starting point https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.10/manual/index.html
(dunno which version you're in, i let you pick)
hello! I have the same problem from this link below https://answers.unity.com/questions/1657759/ui-elements-not-rendering-properly-on-android.html
anoybody knows a solution?
@karmic basin Hm I guess I could add HDRP to the project and use a ShaderGraph and expose the color variable as a IComponentData as they show in that link you posted.
I think that would work, I'll try it.
im wondering why i can't search for entity in package manager : (
i can only see Job , wth ...
Did you check "preview packages" in that window ?
Otherwise you could manually add the package com.unity.entities (i guess) in thé manifest file
Try search entities instead ?
same man
Erf, sorry
Preview packages don't show up until you add them manually now
Aw :/
ok i'll try the edit manifes approach, so other than entity, anything i need to add to begin ECS ?
Hybrid renderer ?
Just use add via github link com.unity.entities it's easier
Im doing all the examples here
https://docs.unity3d.com/Manual/particle-system-job-system-integration.html
But there's no difference between usingJobs or not. The 3 examples gave me 30fps, 3fps, 25fps respectively, with or without jobs
thanks @karmic basin @zenith wyvern i installed entity and hybrid by git all red things gone now!
No problem. I'd suggest you make use of the links in the pinned message, it has a lot of docs/examples that are kept up to date by unity
@stoic monolith jobs help with cpu, so maybe your bottle neck is not cpu bound but gpu ?
my bad Sark, i should read pins first before screaming
a lots of thing to read, wow
Actually, the 2nd particle example, i'm getting 3fps with jobs, and 30fps without
you probably don't have burst enabled and safety tests on? check in a build if not sure
I have burst enabled
Oh wait omg, the example doesnt have burstcompile on..
But still tho, burst aside, why am i getting reverse result on some, and no difference on the other?
Do you have safety checks on? It makes a huge difference when profiling in the editor
Trying it now
The 2nd example still gives the reverse result. 3fps with jobs, 30fps without
With burst its 300 fps so that looks alright
Alright, i'll have to never not use burst for comparison then
does anyone have any good resource regarding generating meshes in c# jobs
cause I have voxel chunks, and I wanna generate the mesh for these chunks in a paralleljob with like 1 job per voxel, but I can't see how to properly have each job write their vertices,tris,uvs,etc to the proper spots in the array when taking into account faces that should not be generated because they're not visible
I assume you mean 1 job per chunk? You just iterate over each block, check each side to see if the adjacent face is opaque, and build the mesh data for that face accordingly
Although it can't be an array. It needs to be lists.
And you need to clear your mesh data and rebuild all the lists any time your chunk changes
@runic crystal This was my last attempt https://github.com/sarkahn/dots-blockworld/blob/version2/Assets/BlockGame/Runtime/Chunks/ChunkMesh/ChunkMeshSystem.cs
thanks
@karmic basin Sadly still haven't been able to figure it out, I installed HDRP and made a Lit Shader Graph with a Vector4 called _Color. I then change the MaterialColor component that comes with Unity Rendering to the color I want but nothing happens. The MaterialColor component value does change but it doesn't change the shader color it seems.
Why not use the entity command buffer and retain burst and parallel computing?
I'm assuming you're talking about spawning entities from other entities and yes, entity command buffers would be better since the current way I do it crashes the game but I have yet to learn how to use them.
Ah - well lucky for you its not that difficult. Just not super documented.
This example from the manual is actually pretty good: https://docs.unity3d.com/Packages/com.unity.entities@0.16/manual/entity_command_buffer.html
No problem. After you get the ecb into the ForEach its pretty straight forward to destroy (as in the doc), create or modify entities.
Also - in case you haven't seen it - this example repo is excellent: https://github.com/Unity-Technologies/EntityComponentSystemSamples
I haven't seen it before but I will take a look.
EntityCommandBuffers definitely helped, no longer do I have crashes and it just generally way nicer.
And as an update to the color thing I was going on about, I managed to fix it, it seems to have been caused by other shader master settings.
Hi im pretty new here. Not using ECS, only trying to job-ify my MB project
My use case is, i'm making triggers to follow particles to act as the particle's "triggers" (instead of using the Collision/Trigger module, for more control)
Ill schedule 2 jobs. First the ParticleSystemJob to get the particle's position, then the ParallelTransform job to move the triggers to the particle's position
I wont need any output result, just wanna let the TransformJob do its thing, and schedule the next cycle after the TransformJob part is finished. So the main thread dont "need" to schedule this every frame and not in a rush at all. Accuracy of the trigger movement is not a concern
Do i just wait every frame if jobHandle.isComplete, if so then call Complete() then Schedule the next cycle?
Im passing a ParticleSystemJobData to my IJobParticleSystem struct, basically trying to do ps.GetParticles but through job
Im getting InvalidOperationException: The NativeContainer UpdateParticlesJob.particleDatas.<positions>k__BackingField.x has not been assigned or constructed. All containers must be valid when scheduling a job.
Is this not allowed?
It's saying the array hasn't been allocated, are you sure you initialized it correctly?
I only did new ParticleSystemJobData(); bcoz cant do anything else than that
Apparently that thing is a struct containing a bunch of NativeArrays, so now im gonna try passing each individual array instead
From what I'm understanding from the manual it's not something you should be creating yourself. It's something that unity passes into your IJobParticleSystem's execute method (which gets called by unity when you schedule your job).
And you build your job around the data you're given
Yeah... but i wanna avoid doing GetParticles and only do SetParticles bcoz (i read) that SetParticles is not very performance heavy, and GetParticles is the heavy one
The point of IJobParticleSystem (from what I understand) is that you don't have to do anything on the main thread, including GetParticles. It gets the particles for you and passes them into the job.
When you're dealing with ParticleSystemJobData you're dealing directly with the particle data, so there should be no copying.
SetParticles can set the particle's remainingLifetime
But u cant do that in the IJobParticleSystem, for some reason. Only position, color, size etc
They're get only
How would you go about generating Random numbers within ECS?
So if you do 1f / inverseLifeTime you get the lifetime. Change that. Then do 1f / inverseLifetime and reassign it back to the array.
You're trying to assign to a property.
Assign the array to a local variable.
But they're get only. This still doesnt work
The alive time percent is a factor of the remaining lifetime, so I guess it makes sense you can't assign to it. It's how you tell where in the total life of the particle it currently is
So as how it is, there's no way to modify remainingLifetime in Job like how u could in main thread?
The inverseStartLifetime is the lifetime of the particle. So if you change that you are changing it's remaining lifetime aren't you?
It's the same
Oh, you shouldn't need to assign the array back. It's a native array
When you assign to the array you're changing the data
Oh no way
Sorry I missed the part earlier where you were trying to assign the array back
You don't have to do that
Yaaay ok it works thanks!
If i want to chain the next Job that needs NativeArray<float3>, and the first job is this particle job.
Can i somehow "pass" the particles.positions to the next job?
Or i need to make a NativeArray<float3> from main thread, pass it to both the particle job and the 2nd job?
Second thing - you need to pass in an array and copy the data to it so you can then pass that to the second job. You can use the static function NativeArray<float3>.Copy though, it uses MemCopy under the hood and is very fast
Or just make your second job also be an IParticleSystemJob
If the 2nd job has nothing to do with particle, wouldnt that be uhh, a waste?
Or it's actually a good idea?
I'm not sure honestly. If Unity is doing a bunch of copying under the hood then yeah it would be a waste. If it's not doing a copy and you're really just working directly with the data then no it wouldn't be a waste
Just depends what they're doing under the hood
Actually i might just make it into 1 job
The 2nd job is supposed to be a IJobParallelForTransform
So in this case, i'll instead pass in a float3 array, let this 1 job deal with the particles AND do stuff with the float3s, then assign the positions of the transform manually in main thread when it's back
dont suppose anyone knows how to feed dataflowgraph node data back into a component? without doing it manually through its nodehandle that is(as theres a way to get entity component data into a node simply by connecting ports)
So I instantiate a Entity through a EntityCommandBuffer inside of a ForEach. I'm wondering how I would change the instantiated entity's components when it's instantiated.
Entity e = ecb.Instantiate(entityInQueryIndex, entity);
figured it out 🥳
ecb.SetComponent
Oh that was easier than I anticipated, I thought since I was using an EntityCommandBuffer I wouldn't be able to do it directly after instantiating it.
Yup you just have to make sure any operations you do on it are through the ecb, or it won't work
Gotcha
finally figured out how to properly connect component data to and from dataflowgraph nodes for animation, so these characters are being driven by physicsvelocity derived from rootmotion delta https://gfycat.com/assuredsleepyhellbender cant test performance in a build tho due to a subscene issue 😦
When will Havok Physics be usable in a large unity project?
There's a "Mathematics" package now for dots
Yeah I just needed to figure out how I would get it to work in a ForEach, figured that out an hour ago or so.
havok physics is stable and usable, it's the rest of ecs ecosystem to worry about
@hollow sorrel bruh thats weird. Ecs has been out for more than a year
It should be close to production ready by now
@median glen what specifically is stopping you?
Nothing?
I just don't want to use something that's gonna give me problems with a lot of bugs