#archived-dots

1 messages · Page 186 of 1

odd cipher
#

Hm. I would like to use them with jobs and burst. And I’m guessing fixed means it’s unchangeable? Which it can’t be in this case.

north bay
#

Fixed means that it has a max capacity

odd cipher
#

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.

tawdry tree
#

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

odd cipher
#

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;

}```

hollow sorrel
#

dynamicbuffers are basically a component themselves stored on the entity, can't store them in a different component

odd cipher
#

Yeah, that's what I realized. I'm trying to find different way of doing it.

hollow sorrel
#

what's wrong with that though?

odd cipher
#

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.

hollow sorrel
#

i meant what's wrong with storing a dynamicbuffer on the entity instead of component

#

it's just different syntax

odd cipher
#

I'm not sure what you mean, Quite new to Entities so.

hollow sorrel
#

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

odd cipher
#

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();
    }
tawdry tree
#

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

odd cipher
#

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

tawdry tree
#

IComponentData

#

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.

odd cipher
#

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?

odd cipher
#

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.

half jay
#

is it possible remove Component derived from one interface like this

#

or any another way but with same result

odd cipher
#

Sadly I can't seem to find many resources into learning DOTS and how to do certain things.

red marsh
#

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 ?

#

and at the moment only the healtbarcontainer get dissabled

amber flicker
#

@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

red marsh
#

okay should i set a refference then to the childs in healthbarcontainer

#

i mean in HealthbarComponent

#

ref the childs

amber flicker
#

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

zenith wyvern
#

Disable should work if they're in a linkedentitygroup I think

#

Turn your hierarchy into a prefab

red marsh
#

problem is that the Healthbar is also a Child of a other entity

#

so the linkedentitygroup if in parent already

amber flicker
#

oh good to know @zenith wyvern

red marsh
#

like this

half jay
#

@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.

amber flicker
#

I believe those methods will only accept concrete types

odd cipher
#

@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.

tawdry tree
#

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"?

scarlet inlet
#

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?

odd cipher
#

@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.

tawdry tree
#

@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

odd cipher
#

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.

scarlet inlet
#

@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

tawdry tree
#

@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

scarlet inlet
#

yes once you do the combine you don't need to use Dependency in the schedule

#

weird

#

I will test

scarlet inlet
#

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

odd ridge
#

how can I trigger a system to do an update right now?

vagrant surge
#

@odd cipher one job per neural net execution makes a lot of sense

#

im assuming they are relatively expensive, no?

tawdry tree
#

@odd ridge If you can get a reference, yes. It's a complicated topic, though

odd cipher
#

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.

vagrant surge
#

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

odd cipher
#

Makes sense, I'll try and get the stuff you've mentioned here to work but it'll take some time.

odd ridge
#

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

scarlet inlet
#

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

zenith wyvern
#

What do you mean they're world related

#

It's just a jobhandle

vagrant surge
#

i have no idea about that part

#

so cant help you there

scarlet inlet
#

yes but Dependency is really stored by the world EntityManager, isn't it?

zenith wyvern
#

No

#

It's just a jobhandle. It's a jobhandle that sits inside a system

scarlet inlet
#

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

zenith wyvern
#

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

scarlet inlet
#

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

zenith wyvern
#

I have no idea about any final job handle that it all gets combined into

#

Sounds like you know a lot about it

tawdry tree
#

Dependency in a given system is based on the system group and UpdateAfter/UpdateBefore, among others from what I understand

scarlet inlet
#

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

zenith wyvern
#

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

scarlet inlet
#

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

scarlet inlet
#

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

odd cipher
#

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.

green path
#

Hi, is there a thread-safe version of NativeQueue<T> ?

vagrant surge
#

@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

odd cipher
#

that doesn't really work since the job tries to change/read data that doesn't exist anymore.

vagrant surge
#

jobs cant do that in unity

#

jobs specifically are pure functions

odd cipher
#

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.

vagrant surge
#

a job in unity needs to "own" its data, of sorts. So you have to copy the neurons into the job

odd cipher
#

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.

vagrant surge
#

if it copies, deleting the orignal one wont be a problem

odd cipher
#

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;
steady blaze
#

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

rancid shell
#

Is it safe to actually start using ECS for development, or is it really not ready to go?

solar spire
#

Jobs, sure, ECS, likely not

zenith wyvern
#

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

rancid shell
#

@solar spire LOL. Alright that's the most blunt "Nah fam" I've read in a long time.

solar spire
#

It's very much something you don't recommend to anyone unless they're excited to get into trouble 😄

rancid shell
#

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

zenith wyvern
#

I've heard people in this channel say good things about Entitas

rancid shell
#

Interesting

#

Confusion

zenith wyvern
#

It's my understanding the paid version has extra features. I've never used it myself

glacial bolt
#

@rancid shell Please don't post memes/reaction gifs.

rancid shell
#

@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?

vagrant surge
#

@rancid shell the paid version uses a better codegen

#

that gives less trouble

#

the ecs itself is the same

rancid shell
#

Less trouble how exactly?

vagrant surge
#

the codegen in default entitas uses normal C# reflection, so your code has to compile

rancid shell
#

I went on their Discord and found that someone has made a variant called "Entitas Redux"

vagrant surge
#

this gives some trouble when you want to rename components, for example

rancid shell
#

which uses a different code generator

#

I'm assuming you've used Entitas before?

vagrant surge
#

the codegen is the biggest issue on the open source entitas

#

yes, for a real project

rancid shell
#

How do you like it if so?

vagrant surge
#

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

rancid shell
#

This "Entitas Redux" seems to use a different code gen named "Genesis"

vagrant surge
#

havent used that

rancid shell
#

would you happen to know if it solves the problems?

#

hmm

vagrant surge
#

i see it seems to use a different codegen and thats it

#

i wonder if it runs into the same issues

rancid shell
#

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 😛

vagrant surge
#

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

rancid shell
#

Even just deleting a member?

vagrant surge
#

yes

rancid shell
#

Yeesh thats frustrating

vagrant surge
#

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

rancid shell
vagrant surge
#

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

rancid shell
#

The code gen aspect of it is really strange honestly

vagrant surge
#

it gives some extra sintax sugar

#

but its fairly optional

rancid shell
#

Oh? Can you go without it?

#

Or is it a pain if you dont

vagrant surge
#

not much of a pain

#

its fairly minor sugar

rancid shell
#

Did you use the gen or did you just say fuck it and do it all yourself?

vagrant surge
#

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

rancid shell
#

hmm

#

Is there a way to check for specific component types?

#

I'm seeing only by index

vagrant surge
#

what you mean?

rancid shell
#

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.

vagrant surge
#

entity.hasPosition()

rancid shell
#

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

vagrant surge
#

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

rancid shell
#

big sad

#

Alright well it doesnt take too long to change the values for the code gen

#

like you delete 3 lines per member

vagrant surge
#

ye

#

its just annoying

rancid shell
#

but is it 90$ annoying is the real question 🤔

#

I'm not having the entities/contexts appear as gameobjects during play mode

#

odd

hollow sorrel
#

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

rancid shell
#

ye mb

odd cipher
#

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)

vagrant surge
#

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

zenith wyvern
#

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"?

odd cipher
#

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

vagrant surge
#

then dont delete instantly, and wait a frame to delete it

rancid geode
#

@odd cipher make any data that need to be manually destroyed by a system to be a ISystemStateComponentData

odd cipher
#

I do not use ECS at the moment @rancid geode

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

steady blaze
#

@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.

zenith wyvern
#

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?

odd cipher
#

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

zenith wyvern
#

@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

steady blaze
#

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)

zenith wyvern
#

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

steady blaze
#

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

zenith wyvern
#

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.

steady blaze
#

ah, ok - then should be ok I guess

vagrant surge
#

@zenith wyvern are there refcounted versions? or a way to do a refcount

zenith wyvern
#

Not that I know of

vagrant surge
#

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

zenith wyvern
#

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

vagrant surge
#

thats beyond jank

zenith wyvern
#

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

rancid geode
#

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

zenith wyvern
#

I don't know, I wouldn't mind a lot less boilerplate in ECS too, hahah

deft stump
#

I've been wondering this for a while but, is it safe to sched a job inside a c# async method?

zenith wyvern
#

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

safe pulsar
#

It doesn't set the values of CirclePosition to 5.

zenith wyvern
#

You have to write it back to the query

#

query.CopyFromComponentDataArray

safe pulsar
#

So what is the nativearray pointing to in this instance?

zenith wyvern
#

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.

safe pulsar
#

Oh. Uh, I thought NativeArray indexes were all pointers. Got lots to learn. Thanks

zenith wyvern
#

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

rancid geode
#

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.

odd cipher
#

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?

coarse turtle
#

you copy the native list into a new native list?

steady blaze
#

@odd cipher I think you need to use destination.copyFrom(source), something like that

odd cipher
#

possibly

coarse turtle
#

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

steady blaze
#

yes, you need to generate a copy somehow

zenith wyvern
#

You can pass in the source array to the constructor of the destination

odd cipher
#

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.

static dune
#

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?

zenith wyvern
#

NativeLists are resizable

#

As in they will expand capacity as needed

static dune
#

Yeah, it's an amortized operation. "Dynamic arrays".

#

So does that mean I can use NativeLists?

coarse turtle
#

not directly in components, you will probably get a runtime error due to a safety check which makes that structure not blittable

zenith wyvern
#

Not sure what you're asking. Use NativeLists for what?

static dune
#

Yup, that's what I'm thinking.

coarse turtle
#

there's DynamicBuffers you can use

static dune
#

@zenith wyvern as a property in my dots component.

zenith wyvern
#

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

static dune
#

Oh does that put it on the heap?

#

Kind of like Box in Rust

zenith wyvern
#

They get put on the heap if they expand beyond their initial capacity

static dune
#

Yup, okay. Makes sense.

zenith wyvern
#

Which you specify in an attribute on the dynamic buffer struct

static dune
#

Thanks guys. I'll try that out. Time to get back to my actual job. Fun times with microservices

fallen zephyr
#

Unity Physics promises to be deterministic. Can anyone confirm this or is this a baseless claim maid by unity?

gusty comet
#

Promises have futures

hollow sorrel
#

@fallen zephyr it is same platform deterministic

#

not sure about cross platform

steady blaze
safe lintel
#

well for starters a nativequeue must be created with an allocator of your choosing ie
_queue = new NativeQueue<T>(Allocator.Persistent);

steady blaze
#

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

steady blaze
#

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

zenith wyvern
#

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

steady blaze
#

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.

odd cipher
#

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();
low tangle
#

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

odd cipher
#

That seems to have fixed it, thanks.

odd cipher
#

@low tangle Well hm, I'm still getting this error occasionally. It's not consistent.

stiff skiff
#

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?

odd cipher
#

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

stiff skiff
#

Have you checked how large these NativeHashMap's are?

odd cipher
#

well they can't be the same size, n.connections should be 0, connections can be any amount

stiff skiff
#

if the n.connections hashmap is created with Temp or something, it might overflow it's size as well

odd cipher
#

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);

stiff skiff
#

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

odd cipher
#

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.

low tangle
#

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

odd cipher
#

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.

low tangle
#

ah, gotcha. so your doing a componentwise value copy then

#

main thread?

odd cipher
#

Well, I'm not using ECS, just Jobs and Burst. And yes it's on the main thread

low tangle
#

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

steady blaze
#

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

low tangle
#

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

odd cipher
#

Yeah hm, you lost me there

low tangle
#

its alright, not something you need to worry about

low tangle
#

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

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!

odd cipher
#

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.

low tangle
#

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

maiden delta
#

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

zenith wyvern
#

Best you can do is make a bug report through unity then post about it in the physics forum with the id

maiden delta
zenith wyvern
#

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

viscid dust
#

Hi all, sorry If im not asking on the proper channel, i want to ask you what I'm missing about importing BurtsCompile

coarse turtle
#

Are you using an assembly definition?

#

@viscid dust

viscid dust
#

I do not think so, how can I check about assembly definition? @coarse turtle

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

viscid dust
#

the code does not complie because of that, its giving me this error

#

I just open the project and import the assets

coarse turtle
#

Hmm - i assume you have the Burst package in your package manager

viscid dust
#

oh, let me check

#

nope, the burst package wasnt installed

coarse turtle
#

alright yeah install it and see if it compiles

viscid dust
#

yes, it compiles now, thanks! @coarse turtle

static dune
#

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:

zenith wyvern
#

You can't use Linq in burst

static dune
#

Direction is an enum btw.

zenith wyvern
#

It returns tons of managed objects

static dune
#

waaaat~

#

I can't use it anywhere in burst or just in JobComponentSystems and the like?

zenith wyvern
#

Just in burst

static dune
#

Oh so I can move that code into its own object.

zenith wyvern
#

So inside the foreach

static dune
#

Hmm, let me try moving the code out then.

zenith wyvern
#

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

lucid palm
#

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.

zenith wyvern
#

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

lucid palm
#

Ack, that's too bad! I'll give project tiny a look.

static dune
#

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();
    }
}
zenith wyvern
#

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

static dune
#

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

zenith wyvern
#

Well people made games without OOP long before unity adopted ECS, right? You just have to try to get into an DOD mindset

rancid geode
#

You are going OOP, ECS is DOD

zenith wyvern
#

Like I mentioned earlier if you want some decent examples of "full" working prototypes check out the Project Tiny samples

rancid geode
zenith wyvern
#

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

lucid palm
#

is DOD different from Domain Driven Design?

static dune
#

You know what, that's probably for the better. Project Tiny looks good.

rancid geode
zenith wyvern
static dune
#

DDD reminds me of Scott Wlaschin for some reason

#

He's that F# shill, smart dude in general.

lucid palm
#

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

zenith wyvern
#

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

lucid palm
#

for performance reasons?

static dune
#

DDD is basically "use algebraic data types to model the domain". DOD is "fuck the world, you design your program around data.

zenith wyvern
#

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

rancid geode
#

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

lucid palm
#

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 🙂

deft stump
#

Addind to this conversation on not doing OOP in DOD.
This vid helped me write better dots code

vagrant surge
#

he uses DoD to optimize parts of the web renderer for Coherent UI

maiden delta
#

ok i submitted the bug about unity physics, hope i did everything correctly

maiden delta
#

why do fixed step simulation component group systems not execute every fixed step?

olive kite
#

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

deft stump
#

there's [UpdateAfter(typeof(yourSyste))] and also UpdateBefore

olive kite
#

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

zenith wyvern
#

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

olive kite
#

Okay, yeah I see that too. Maybe it's just retraining my brain, just wanted to make sure I wasn't approaching it ineffectively

zenith wyvern
#

I'm not really a fan of the UpdateBefore/UpdateAfter stuff either. But it works I guess

olive kite
#

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?

deft stump
#

BlobAssets

zenith wyvern
#

There's no sane way to convert SO's to blobassets though. It's all very manual and bad

olive kite
#

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

zenith wyvern
#

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

olive kite
#

Okay, I kind of do that still

green path
#

Hi, is sending events to specific systems a good idea?

zenith wyvern
low tangle
#

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

green path
#

Wym by direct messages?

zenith wyvern
#

Like subscribing to an event or just directly calling a function in another system

green path
#

Yeah I'm trying to call a function belonging to a system

#

Is that any good?

zenith wyvern
#

I mean it directly couples your systems which is bad. But sometimes it's the right way to go

green path
#

Why is it bad to couple systems?

zenith wyvern
#

The same reason it's bad to have public member variables in a class. Just basic good practice stuff

green path
#

Oh

#

Is it a good idea then to say, have a public system function that modifies an entity's component data?

zenith wyvern
#

Only if it's static and doesn't touch any mutable static data

green path
#

Rip

safe lintel
#

@low tangle speaking of escalating complexity, have you given animation a try?

green path
#

Hey, is it possible to serialize an Entity? 🧐

low tangle
#

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

safe lintel
#

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

low tangle
#

for real

safe lintel
#

did you see the rigremap example in regards to skeletal remapping?

low tangle
#

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

safe lintel
#

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

low tangle
#

gotcha

#

I've already ruled it off the shelf for this game, but maybe in a side project

safe lintel
#

huh just noticed RequiresEntityConversion is obsolete now

safe lintel
#

probably best to use 2020.1 and up for dots

#

and yes its still in development @gusty comet

shy pilot
#

has anybody else been experiencing the problem where networkid entities aren't being spawned for players joining?

safe lintel
#

havent touched networking sorry

shy pilot
#

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

rancid shell
#

So generally in ECS, can components hold reference to other Entities/Components?

minor sapphire
#

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

green path
#

Hi, is there a way to clone worlds?

odd cipher
#

How would you make a system to be able to click on Entities?

slim nebula
#

@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.

odd cipher
#

Hm Alright, but for the location couldn't I just use Translation and compare it?

slim nebula
#

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

odd cipher
#

Yeah I had that problem earlier with a previous attempt. I'm not sure how to do that though.

slim nebula
#

you could use a sphere collider, then a physics ray trace

#

or a mesh collider if it already has some other physical shape

odd cipher
#

You mean using the Physics package or?

karmic basin
#

Maybe just comparing distance between 2 vectors ?

#

First one is the mouse click, other one from the Transform

odd cipher
#

@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.

odd cipher
#

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?

karmic basin
#

I see you're using Physics to cast a ray

#

There's a new Physics package with dots

odd cipher
#

Yeah I downloaded it just 10 minutes ago, I'll have to learn it :P

lusty dirge
#

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?

coarse turtle
coarse turtle
vagrant surge
#

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

coarse turtle
#

yea I agree with the rust part - also their error messages are really nice and show you where it's a problem

main wing
#

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,

shy pilot
#

sorry, no idea 😆

#

has anyone managed to get a custom bootstrap to work with netcode

north bay
#

I'm using a custom bootstrap for my netcode worlds

shy pilot
#

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

north bay
#

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 );
odd cipher
#

How would you enable UI / call a script through a ComponentSystem?

shy pilot
#

@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

odd cipher
#

I'm trying to run the FindObjectOfType function but it doesn't seem to be working and the gameobject it returns is null.

shy pilot
#

are you running it from OnCreate() or OnStartRunning()?

#

the methods for client only join etc are simmilar

odd cipher
#

OnStartRunning. I'm not sure what the difference between the two are.

shy pilot
#

simmilar to Start() and Awake()

#

try switching to a Find() or tag based find

#

@north bay this is ConnectLocal()

odd cipher
#

That did not work either.

shy pilot
#

hmm

odd cipher
#

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.

shy pilot
#

ok

#

you could try using a singleton in a monobehaviour and getting the reference from that

amber flicker
#

fyi: Yes 0.17 release should happen in the next ~3 weeks.

shy pilot
#

so have a static CreatureViewerUI inside CreatureViewerUI

#

and set that in the monobehaviour's Awake()

odd cipher
#

I just realized I had the gameobject disabled this whole time, though enabling it and changing it to use a singleton worked. Thank you.

shy pilot
#

lol, happens to the best of us

odd cipher
#

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.

shy pilot
#

are you using jobs?

#

you can't run a raycast from a jobs thread

odd cipher
#

In this case, no I'm not using Jobs.

shy pilot
#

are you moving the camera before or after the raycast

#

it might be raycasting from the old position

odd cipher
#

camera movement is based upon the players input.

shy pilot
#

yes but does the raycast happen before or after the camera actually gets moved

odd cipher
#

I'm not sure.

shy pilot
#

just look at the code order

odd cipher
#

Though the problem still happens when the camera is still so I don't think that is the cause

north bay
#

@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.

shy pilot
#

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

north bay
shy pilot
#

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 😆

north bay
#

No he doesn't

#

If i remember correctly xD

shy pilot
#

hmm

#

so how do we distinguish between the server's networkid and the client's entity

north bay
#

I'm sorry, what do you mean with the client's entity?

shy pilot
#

so in the client world there are two networkidcomponents right?

#

one for the server and one for the client?

north bay
#

No the client only has one NetworkIdComponent which contains his information

#

The server has one for each connection

rancid shell
#

Are there any other ECS Libraries you guys suggest using while Unity's ECS remains in development?

shy pilot
#

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

north bay
#

Exitgames games made an ecs for unity, but that's more of a game engine itself.

compact robin
#

Still, it would be great if anyone can provide a way to clone worlds

odd ridge
#

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?

compact robin
#

Both works

#

@odd ridge

odd ridge
#

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

compact robin
#

Hmmm

odd ridge
#

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.

zenith wyvern
#

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

wet epoch
#

you can speed up the play mode bit

#

that makes the play mode bit instant for me most times

#

but not the building part

solar spire
#

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

wet epoch
#

using assembly definitions can help too

solar spire
#

and in earlier versions of Unity there are lots of other things that can break

#

UI gets screwed for me on 2019.4

hollow sorrel
#

@compact robin there's entitymanager.copyentitiesfrom, you use that with the entitymanager of the other world

compact robin
#

Oh wow thanks a bunch I will try it out

#

Btw, do you think they would retain their entity ids?

hollow sorrel
#

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

compact robin
#

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

odd cipher
#

Hey anyone able to help with the Raycast problem I had yesterday? scroll up a bit and you'll find it.

karmic basin
#

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 ?

odd cipher
#

the collider seems fine to me, this gameobject gets converted when instantiated as a prefab.

#

@karmic basin

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

odd cipher
#

I'll try and use Gizmos to draw it, I'm not sure how but I'll try.

karmic basin
#

Debug.DrawRay()

odd cipher
#

@karmic basin The raycast is hitting the entity correctly but it seems to go undetected.

karmic basin
#

I think I cant help you more than that 😦

coarse turtle
#

If it's the Unity dots physics package you might want to check that the collision flags/bitmasks match

odd cipher
#

I'm not sure how those work.

coarse turtle
#

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

karmic basin
#

Yeah that's the filters, I assumed it would be set to Everything by default because its converted from GameObjects

coarse turtle
#

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

karmic basin
#

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)

odd cipher
#

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.

gusty comet
#

@odd cipher Have you tried adding the PhysicsDebugDisplay component to the object with the PhysicsShape/Body component?

odd cipher
#

I have not, what does it do? @gusty comet

gusty comet
odd cipher
#

Oh that’s very useful, I’ll try it out as soon as I can, in about 10 minutes or so

odd cipher
#

@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.

tight blade
#

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?

zenith wyvern
#

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

tight blade
#

yeah that makes sense. and the camera, I imagine you cant change the camera's position in a job, right?

#

or can you

safe lintel
#

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

tight blade
#

@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

zenith wyvern
#

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

safe lintel
#

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

tight blade
#

youre telling me the physics samples has usefully current code?

zenith wyvern
#

The physics samples are still lagging a little behind. Better than it used to be though

safe lintel
#

it always has, some of the examples are a little contrived but its always been very useful

tight blade
#

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

odd cipher
#

@tight blade I do not have those. By the way, if it matters, the ground the entities are on is also an entity.

tight blade
#

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?

zenith wyvern
#

Yup. So once your camera is attached to an entity you can do

Entities.WithoutBurst().ForEach((Camera cam)=>
{
  cam.transform.position = float3.zero;
}.Run()
odd cipher
#

@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);
}

tight blade
#

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

odd cipher
#

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

tight blade
#

@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?

safe lintel
#

@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

tight blade
#

does it even schedule anything when you do .withoutBurst.Run?

safe lintel
#

the work that you .withoutburst.run is not scheduled, it runs immediately

tight blade
#

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

safe lintel
#

what?

tight blade
#

Im just saying this doesn't seem worth it:

Entities.WithoutBurst().ForEach((Camera cam)=>
{
  cam.transform.position = float3.zero;
}.Run()
safe lintel
#

compared to what exactly?

tight blade
#

ill probably just have a static reference to the entity and just do

override public void onUpdate():
   this.cam.transform.position = float3.zero;
safe lintel
#

so how are you finding that camera entity then? seems like you are just kinda fighting what exists to make your life easier

tight blade
#

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

candid verge
#

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!

candid verge
#

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.

sand dome
#

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.

odd ridge
#

😄

#

@sand dome I'm not aware of such thing. you would have to use queries and do the logic yourself

safe lintel
#

@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

candid verge
#

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.

safe lintel
#

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

candid verge
#

kk, will do.

safe lintel
#

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

sand dome
#

is there a concise example of accessing a MonoBehaviour from DOTS and DOTS from a MonoBehaviour?

compact robin
#

Yo, is it a MUST to call Job.Complete() if I do not care about the completion state of a job?

odd ridge
#

@compact robin it's a must to not call Job.Complete() if you want maximum performance ^^

compact robin
#

Why?

#

It just ensures that jobs are complete, no?

#

The job*

#

And in fact, it creates a sync point I think

#

@odd ridge

odd ridge
#

no, it stalls the main thread until the job is done

deft stump
#

no it doesn't create sync point

odd ridge
#

sync points happen when you don't call job.complete(), you don't need a sync point if you run code synchronously

deft stump
#

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.

hollow sorrel
#

@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

compact robin
#

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?

deft stump
#

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

compact robin
#

What if I'm not using native containers? @deft stump

rancid geode
#

@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

compact robin
#

Yeah my job is a fire and forget one

rancid geode
#

then you don't need to call Complete at all on it

compact robin
#

Nice, thanks for the info

rancid geode
#

just run and, well, forget

compact robin
#

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()

rancid geode
#

you can see Complete as "PriotizeThisAndDontMoveToNextLineUntilIsCompleteIsTrue"

compact robin
#

I mean its basically await in async, but it blocks the thread

#

Right?

rancid geode
#

yeah, basically that

compact robin
#

Nice then

#

So it won't lock the NativeContainer

#

If I don't Complete() it right

#

Despite the job being already complete

rancid geode
#

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

compact robin
#

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

rancid geode
#

correct

compact robin
#

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

hollow sorrel
#

i dindu nuffin but sure i'll take credit

stiff skiff
#

Any news on new packages? It's been nearly 2 months since the last one with little news 😅

zenith wyvern
#

Jaochim said on the forums the next version should be out in the next couple weeks or so

deft stump
#

is it gonna be the enable/disable components?

#

please say it is so

compact robin
#

c;

compact robin
hollow sorrel
#

whaat has it really been 2 months already

#

changelog says 09 but thought it came out like a month ago

compact robin
#

I think a better qn would be, when they can actually document ECS stuff @_@

safe lintel
#

@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

deft stump
#

I stand corrected then

compact robin
safe lintel
#

if you are referring to structural changes, yes

zenith wyvern
#

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

safe lintel
#

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?

wanton fossil
#

tf is dots

safe lintel
wanton fossil
#

so basically stuff only large games need

safe lintel
compact robin
#

I mean if you want perf

#

Yeah

#

And it keeps stuff organized

#

Cuz you're forced to code in that way

deft stump
#

every game (not all of them) needs perf.

rancid geode
#

all it does for you is to call AddHybridComponent for those specific components

compact robin
#

Though I do agree every game needs perf, since 1 fps is like unplayable

safe lintel
#

@rancid geode thanks

wanton fossil
#

hmm this seems useful for when I want to start optismising

compact robin
#

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 @_@

karmic basin
#

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

compact robin
#

No idea tbh, but I think there's this free PDF online that people recommend for DOTS

gusty comet
#

Do you have a link?

compact robin
#

Let me try finding it brb

#

I've not read it

#

It was recommended to me

#

Brb

#

This is the one apparently

#

🧐

gusty comet
#

LOL that's the same exact book I referenced

odd ridge
#

@gusty comet it's pretty related

#

as much related as reading an object oriented book to better understand classic Unity gameobjects

compact robin
#

Wtf

#

LOL

#

I always thought the book is free

#

The book literally feels like

#

Reading a website via Internet Explorer 8

rancid geode
#

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

gusty comet
#

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.

compact robin
#

Oh

#

Does the paid version look more user friendly?

#

Might get it then

#

🧐

rancid shell
#

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

spark glade
#

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 😦

deft stump
#

oooh the package manager failed to resolve when it hits the 2 min mark is now resolved the b12

odd cipher
#

How would I go about 'replicating' a entity through a System?

hollow sorrel
#

could you give some more context? can imagine multiple things for that one

odd cipher
#

Hm yeah, I have multiple entities that all have a chance to replicate / reproduce. And when that happens, I need to replicate that entity.

hollow sorrel
#

as in create a copy with the same components+values?

odd cipher
#

Yes

hollow sorrel
#

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

odd cipher
#

I'm not sure if it's possible to get the EntityManager in a System though? I'm quite new to this

hollow sorrel
#

you can just do EntityManager in any systembase

#

it's a property

distant imp
#

How do I dispose of (delete?) a DynamicBuffer? Say I want to remove it from an entity in a system?

odd cipher
#

@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?

hollow sorrel
#

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)

odd cipher
#

Ah. Alright

#

Yep that worked

odd cipher
#

Also, How would you go about changing a entities color after it's instantiated :p?

hollow sorrel
#

instantiate returns an entity

#

you can setcomponentdata color with that

odd cipher
#

I don't think you can do that, unless you're talking about some different color component than the one for GameObjects.

hollow sorrel
#

oh yea if you're using hybrid renderer it's different

#

not sure about that one, not using hybrid renderer

odd cipher
#

gotcha

karmic basin
#

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

odd cipher
#

@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

frigid onyx
#

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.)

safe lintel
#

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

frigid onyx
#

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?

safe lintel
#
Entities.ForEach.WithoutBurst((Entity entity, ref LocalToWorld localToWorld, ParticleSystem particleSystem, Transform transform)=>{
transform.position = localToWorld.Positon
particleSystem.Play();
}).Run();
frigid onyx
#

? that'll work? I didn't think ParticleSystem supported IComponent

#

testing...

safe lintel
#

i dont know how you added your particlesystem in the first place but that presumes you added as a managed object or hybridcomponent

frigid onyx
#

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 !

safe lintel
#

good luck 🙂

frigid onyx
#

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

frigid onyx
#

Womp womp

#

I had the material set to transparent instead of opaque. 🤦🏻‍♂️

#

I'll show myself out, thanks 🚪

safe lintel
#

gotta love the silly things that eat up so much time

stoic monolith
#

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

karmic basin
odd cipher
#

@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.

karmic basin
#

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

odd cipher
#

Alright

karmic basin
#

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

#

(dunno which version you're in, i let you pick)

trim lichen
#

anoybody knows a solution?

odd cipher
#

@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.

formal crescent
#

im wondering why i can't search for entity in package manager : (

#

i can only see Job , wth ...

karmic basin
#

Did you check "preview packages" in that window ?

formal crescent
#

yes

#

i can see preview packages

karmic basin
#

Otherwise you could manually add the package com.unity.entities (i guess) in thé manifest file

#

Try search entities instead ?

formal crescent
karmic basin
#

Erf, sorry

zenith wyvern
#

Preview packages don't show up until you add them manually now

karmic basin
#

Aw :/

formal crescent
#

ok i'll try the edit manifes approach, so other than entity, anything i need to add to begin ECS ?

karmic basin
#

Hybrid renderer ?

zenith wyvern
#

Just use add via github link com.unity.entities it's easier

stoic monolith
formal crescent
#

thanks @karmic basin @zenith wyvern i installed entity and hybrid by git all red things gone now!

zenith wyvern
#

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

formal crescent
#

@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

stoic monolith
#

Actually, the 2nd particle example, i'm getting 3fps with jobs, and 30fps without

amber flicker
#

you probably don't have burst enabled and safety tests on? check in a build if not sure

stoic monolith
#

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?

zenith wyvern
#

Do you have safety checks on? It makes a huge difference when profiling in the editor

stoic monolith
#

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

runic crystal
#

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

zenith wyvern
#

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
#

thanks

odd cipher
#

@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.

gusty comet
odd cipher
#

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.

gusty comet
#

Ah - well lucky for you its not that difficult. Just not super documented.

odd cipher
#

Yeah, worst part about DOTS at the moment is the lack of documentation tbh

#

Thank you

gusty comet
#

No problem. After you get the ecb into the ForEach its pretty straight forward to destroy (as in the doc), create or modify entities.

odd cipher
#

I haven't seen it before but I will take a look.

odd cipher
#

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.

stoic monolith
#

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?

stoic monolith
#

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?

zenith wyvern
#

It's saying the array hasn't been allocated, are you sure you initialized it correctly?

stoic monolith
#

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

zenith wyvern
#

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

stoic monolith
#

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

zenith wyvern
#

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.

stoic monolith
#

SetParticles can set the particle's remainingLifetime
But u cant do that in the IJobParticleSystem, for some reason. Only position, color, size etc

stoic monolith
odd cipher
#

How would you go about generating Random numbers within ECS?

zenith wyvern
#

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.

stoic monolith
zenith wyvern
#

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

stoic monolith
#

So as how it is, there's no way to modify remainingLifetime in Job like how u could in main thread?

zenith wyvern
#

The inverseStartLifetime is the lifetime of the particle. So if you change that you are changing it's remaining lifetime aren't you?

stoic monolith
zenith wyvern
#

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

stoic monolith
#

Oh no way

zenith wyvern
#

Sorry I missed the part earlier where you were trying to assign the array back

#

You don't have to do that

stoic monolith
#

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?

zenith wyvern
#

Or just make your second job also be an IParticleSystemJob

stoic monolith
#

If the 2nd job has nothing to do with particle, wouldnt that be uhh, a waste?

#

Or it's actually a good idea?

zenith wyvern
#

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

stoic monolith
#

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

safe lintel
#

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)

odd cipher
#

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);

safe lintel
#

figured it out 🥳

odd cipher
#

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.

zenith wyvern
#

Yup you just have to make sure any operations you do on it are through the ecb, or it won't work

odd cipher
#

Gotcha

safe lintel
median glen
#

When will Havok Physics be usable in a large unity project?

karmic basin
odd cipher
#

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.

hollow sorrel
median glen
#

@hollow sorrel bruh thats weird. Ecs has been out for more than a year

#

It should be close to production ready by now

safe lintel
#

@median glen what specifically is stopping you?

median glen
#

Nothing?

median glen