#archived-dots

1 messages · Page 240 of 1

devout prairie
#

So i can see when i run the game that my prefabs are created inside the Subscene, along with my singleton entity:

#

However inside one of my systems, in OnCreate, when i try to get the singleton i get this:

#

Actually it's not OnCreate, it's being called from a mono, hmm

haughty rampart
#

yeah, so not sure

devout prairie
#

Curious also that as you can see for example FirstPersonCamera, which is a GameObject existing in the GameScene, isn't shown as a child of GameScene in Entities view

haughty rampart
#

cause it's probably not being converted to an entity

#

since the main camera can not be an entity anyways currently

devout prairie
#

it's a hybrid it has ConvertAndInject and you can see above it exists in the original scene hierarchy, but also in the Entities view

coarse turtle
#

you're using convert and inject in a subscene?

devout prairie
#

something's telling me this is an issue with the order in which systems are created

haughty rampart
#

subscene does ignore any convert to entity components

devout prairie
coarse turtle
#

oh

haughty rampart
#

no object in a subscene needs a convert to gameobject component and if there are any on any object it just get's discarded

devout prairie
#

yeh ignore that it was a separate observation

coarse turtle
#

if you're grabbing an entity from OnCreate, subscenes aren't loaded yet 🤔

robust scaffold
#

Try OnStartRunning, not OnCreate

devout prairie
haughty rampart
#

btw can someone convey the usefulness of multiple worlds to me?

haughty rampart
haughty rampart
robust scaffold
devout prairie
robust scaffold
#

Actually doing logic beyond basic loading is fairly tricky on a separate world and Im still trying to figure it out. Lots of bugs and Im getting the impression that multiple worlds is not really supported on 0.17

haughty rampart
devout prairie
#

only other thing it has is a buffer

haughty rampart
devout prairie
#

i've tried using GetSingleton<myBuffer> also but then tried with the tag same problem

robust scaffold
#

That at least works, mostly. SharedComponentData and ChunkComponents are not supported in transferring between worlds. You need to re-assign them in the primary world using EntityQuery EntityManager commands, which is fairly simple and quick.

haughty rampart
#

interesting. i've only ever seen a different world being used to do some physics calculations and then display a trajectory based on those in the main world. but that was ages ago and to me it just felt strange

safe lintel
#

imo you should add a HasSingletonComponent<T> check, not sure what the order/timing of conversion is but maybe its just not getting converted right away?

haughty rampart
safe lintel
#

or requiresingleton for update

devout prairie
#

yeah i'm thinking it's an ordering problem ie it just doesn't exist yet..

#

basically i've had the problem where my dots character animation clips are not running when i build the project, apparently they don't unless they're included in a subscene

#

they run fine in the editor..
so i'm having to restructure my character prefabs into a subscene to get the build working

#

it's probably for the better that i learn subscenes and also restructure some of my code to have clearer separation between monos and systems

safe lintel
#

animation only converts in editor, so for a build you have to use a subscene to preconvert them(elaborating on my previous comment)

devout prairie
#

yep, thanks for that as i had no idea of that caveat

safe lintel
#

id assume they will change it in the future because that seems a bit half baked but then again not really sure what the future of conversion is supposed to look like

devout prairie
#

how'd you figure that one out?

safe lintel
#

it mentions it somewhere in the anim samples, also theres a comment somewhere in the conversion code that is if def'd for the editor I think. I wanna say it was curves? maybe if you are particularly brainy you could even wewrite it to run at runtime 🙂

devout prairie
#

heh yeah maybe later, i'll try figure this out first..

safe lintel
#

ah its ClipConversion.cs

#

all editor only

devout prairie
#

although i think i did have to dump animation package into assets to make something public at one point

#

ah thanks

#

not sure if there's any way to debug the subscene loading, for example do a console print when a subscene loads

#

might help debug ordering

#

bit of a black box atm

junior latch
#

So I'm just starting out learning and using ECS and I've run into something quite annoying: namely that the ConvertGameObjectToEntitySystem doesn't run ahead of everything else by default, which is annoying when I'm trying to use it for configuration :/

What's the best way to make sure that my system's onCreate runs after ConvertGameObjectToEntitySystem has done its thing so I can use a singleton from the editor for config?

safe lintel
#

what are you trying to do? do conversion stuff after the bulk of gameobject entity conversion has taken place but before runtime systems start? or something during runtime only?

junior latch
#

I'm trying to use the mesh, material and couple of other things I can define in the editor with a dummy gameobject, by grabbing it from the entity that is created, to config the initialization of other stuff

#

except that well yeah

#
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        dstManager.AddComponentData(entity, Config);
        Debug.Log("added component");
    }
safe lintel
#

we sorta just went over this, not really sure on the specifics of conversion timing but options could be to do

if(HasSingleton<T>)
//stuff
else
return;

or theres also RequireSingletonForUpdate<T>();

junior latch
#

Yeah I noticed that that exists, but I'm hoping I can avoid merging the intialization of the system with the normal update loop?

safe lintel
#

RequireSingletonForUpdate can go in OnCreate

#

also shouldnt be a problem to query within the update loop for certain things I assume if you arent going crazy, thats literally what its there for

junior latch
junior latch
safe lintel
#

you pasted the getsingleton error so I assumed you were trying to do this during runtime, the alternative is doing something in conversion, and outside of that Im not sure what you want?

#

actually singleton stuff shouldnt be connected to conversion, im not thinking straight 🙂 but im still not sure what the issue is tbh

junior latch
#

Sorry, let me clarify again.

I have a system whose onCreate sets up a bunch of stuff, and then runs my my current test logic.
I wanna be able to tweak the config outside of code for ease of use and being able to drop meshes/materials/etc in easily.
The solution I wanted to use would have been do define my own authoring component which would allow me to do this in the editor (which creates an entity from the gameobject with create and destroy)
And then have the system try to grab that Entity during onCreate, except as we can see, it doesn't exist yet

#

I read into it some more and apparently there's some other approach with an addressables key? so I'm going to look that

safe lintel
#

ah, you shouldnt be changing entity data in oncreate afaik

junior latch
#

I mean technically I'm only trying to read it, but why/where can I read up more on that?

safe lintel
#

well its just for system initialization, id wager that across all examples and their own packages, you wont see unity doing any entity component data reading/writing in a systems OnCreate

#

assumably you could dig into the code and see if entities exist prior to a world running system's oncreate

junior latch
#

That's fair, but does that mean I just have no solution for easy configuration?

safe lintel
#

what are you doing in OnCreate?

junior latch
#
  • use that to make entities
#

but that part works fine

junior latch
# junior latch

But yeah basically just wanted a way to get that info in the same way you could normally do with a monobehavior

safe lintel
#

lets assume this slice worked on OnCreate, are you wanting to change this again sometime during gameplay? oncreate wont run again

junior latch
#

No

#

That's the point

#

This is all initialization

safe lintel
#

ok then use conversion 🙂

junior latch
#

I...

#

I'm confused

#

Gameobject -> Entity conversion apparently runs after onCreate

#

So I can't?

safe lintel
#

conversion in subscenes runs prior to gameplay, conversion outside of subscenes should i think run before, and conversion can happen later during runtime ie if you have a gameobject(and dont tick ConvertToEntity checkbox before the game starts, and tick that during the game it will convert while the game runs(in its current state and runtime conversion may disappear in the future, unity havent been clear).

#

entities shouldnt be accessed in oncreate

#

access the entity and its data during OnUpdate

junior latch
#

Alright, thank you

devout prairie
#

Seems someone else is having ordering problems!

#

@safe lintel i've noticed if you have role 3dArtist you don't have a little icon next to your name.. should put in a formal complaint to server admin regards this horrendous injustice

#

as a long time 3d artist ( and coder as it happens ) i find this an insult of the highest order

safe lintel
#

i guess im a generalist these days, but I cling on to my roots 🥲

frosty siren
#

What can i potentially do wrong?

this code causes error (screenshot). When i comment this code then no error happening

var count = _argsBuffer.BeginWrite<int>(1, 1);
count[0] = group.y;
_argsBuffer.EndWrite<int>(1);

_argsBuffer initialized through this code

// Argument buffer used by DrawMeshInstancedIndirect.
var args = new uint[5] { 0, 0, 0, 0, 0 };
// Arguments for drawing mesh.
// 0 == number of triangle indices, 1 == population, others are only relevant if drawing submeshes.
args[0] = (uint)_quad.GetIndexCount(0);
args[1] = (uint)INSTANCE_COUNT;
args[2] = (uint)_quad.GetIndexStart(0);
args[3] = (uint)_quad.GetBaseVertex(0);
_argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments, ComputeBufferMode.SubUpdates);
_argsBuffer.SetData(args);
frosty siren
# haughty rampart is that even dots related

sorry, i saw compute buffers was mentioned few times in this channel + i use here native array to write data + also IMHO here in dots channel sitting the most experienced devs. Yes, this probably more related to shaders channel or to advanced code channel

haughty rampart
#

anyway i've got no idea why why that throws an error. looks functional to me. did you try it in a blank project?

frosty siren
#

yep, this is blank project

haughty rampart
#

maybe it's in some other area of your code?

frosty siren
#

mmm, i don't think so, because comment this one completely stops throwing error

haughty rampart
#

but i mean, if you don't push that buffer to your shader because of commenting out, well.......then there's no data to be worked on which might stop the error.

frosty siren
#

no, i pushing this buffer to shader, and this buffer has initial values passed with array in initialization code, i only comment out code which edit 2nd value of buffer

haughty rampart
#

maybe the stride is too small because you pass in an array, not 5 uints? idk

frosty siren
#

i think i get it, initial values is uint, and code which edit values tryes to write int

haughty rampart
#

i mean that shouldn't really change anything?

frosty siren
#

i'll check

#

no, the issues is in using SetData() lol, when i use BeginWrite/EndWrite instead of SetData, all goes well

devout prairie
#

just looking at the ComputeBuffer docs

#

So when u use SetData it's ok?

haughty rampart
#

very strange though.

haughty rampart
devout prairie
#

but you said the code crashes it, the code you showed uses Begin/EndWrite

frosty siren
# devout prairie but you said the code crashes it, the code you showed uses Begin/EndWrite

new code is:

_argsBuffer = new ComputeBuffer(1, 5 * sizeof(uint), ComputeBufferType.IndirectArguments, ComputeBufferMode.SubUpdates);
var args = _argsBuffer.BeginWrite<uint>(0, 4);
args[0] = (uint)_quad.GetIndexCount(0);
args[1] = (uint)INSTANCE_COUNT;
args[2] = (uint)_quad.GetIndexStart(0);
args[3] = (uint)_quad.GetBaseVertex(0);
_argsBuffer.EndWrite<uint>(4);
#

no SetData now

devout prairie
#

ah ok sorry

#

so the first arg is the offset i'm assuming 1 is accurate, you're skipping 0?

haughty rampart
#

1 aka 1 array aka 1 * 5 uint

devout prairie
#

ah i was looking at the first code he posted:

var count = _argsBuffer.BeginWrite<int>(1, 1);
count[0] = group.y;
_argsBuffer.EndWrite<int>(1);
haughty rampart
#

oh my bad

junior latch
#

So apparently the Jobs system isn't recommended for multiframe tasks, what is the recommended way of working on a longer task? Why shouldn't I use a job?

haughty rampart
junior latch
#

That's unfortunate since it doesn't let me multithread background tasks (not easily anyway afaik?)

haughty rampart
#

i as well as others hope that there will be a possibility for long running tasks eventually though

junior latch
#

Only beginning to work on this but the standard stuff eg reading a bunch of files or procedurally generating a bunch of terrain

#

Is stuff I'd wanna have done fast

devout prairie
junior latch
#

But I could probs get away with not focusing literally every single resource on

devout prairie
#

He def mentioned his mesh builder is taking 1-200ms

haughty rampart
#

mesh building definitely can be easily done in 1 frame if you chunk up your terrain, which you'd probably want to do anyway

devout prairie
junior latch
frosty siren
devout prairie
junior latch
junior latch
frosty siren
devout prairie
devout prairie
junior latch
# junior latch it's ded xD

I could definitely find it but not trying to build anything rn, just wanted to know what the possibilities are

haughty rampart
junior latch
haughty rampart
#

why crossed swords?

devout prairie
#

aw i just like that one

#

hehe

haughty rampart
junior latch
#

(I mean obvs for burst)

haughty rampart
#

cause IO is unreliable and you don't do IO every frame. jobs is totally irrelevant for that. if you'd make a long running job that does IO it would pretty much be a worse writeasync which already exists

hollow jolt
haughty rampart
#

+1

devout prairie
hollow jolt
#

yes , a simple test like adding a spinning cube will confirm this , u can see the visual tearing even tho the frame rate might be 60

junior latch
#

(not actually sure that this is the best solution to my problem but am curious)

haughty rampart
#

loading screen etc

devout prairie
haughty rampart
#

i am quite certain that's the case

junior latch
rotund token
#

what do you mean? jobs can run as long as they want as long as a) they don't use entity data b) don't use tempjob memory

haughty rampart
hollow jolt
junior latch
haughty rampart
#

if you're on the main menu, for what would you need jobs

devout prairie
junior latch
hollow jolt
haughty rampart
devout prairie
#

maybe if the long job is parallel, and it hogs all available threads, it could block entity system jobs

rotund token
#

yes if you run a long job in parallel you will block everything else running

#

you need to ensure you still have workers available for regular work

#

ideally you only run long jobs in a single worker

junior latch
#

Is there currently no way to ensure this with the regular jobs system?

rotund token
#

an example of long running jobs + loading data off disk (ignore the flickering, was just because I at the time hadn't stopped chunks from despawning before all children had spawned)

devout prairie
#

so technically you could schedule ( not parallel ), it'll start the job on a single thread, ensure it operates only on class/system level native data

junior latch
haughty rampart
rotund token
#

complete finishes a job, not starts the execution

haughty rampart
rotund token
#

JobHandle.ScheduleBatchedJobs();
will start all jobs scheduled immediately

devout prairie
#

so i suppose the question is how do you know when it's completed and/or setup the dependency

haughty rampart
rotund token
#

it gets queued for schedule and won't run until the above line is called

#

this is handled after a system finishes usually

haughty rampart
#

ah interesting. that was a key element i didn't know. cause i have tried long running jobs and they never ran without complete

rotund token
#
    ///   <para>By default jobs are only put on a local queue when using Job Schedule functions, this actually makes them available to the worker threads to execute them.</para>
    /// </summary>
    [NativeMethod("ScheduleBatchedScriptingJobs", IsFreeFunction = true, IsThreadSafe = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]```
haughty rampart
#

so i thought it was impossible

rotund token
#

now btw, this is called in AfterOnUpdate on a system

#

so you shouldn't have to call it yourself (and I don't for the above example)

haughty rampart
#

well i only tried long running jobs in OnStartRunning()

rotund token
#

yes that won't work without calling this

#

because this requires OnUpdate

devout prairie
#

is there no way to designate specific number of threads to jobs

rotund token
#

the system does to see if any new jobs were scheduled

#
        {
            AfterUpdateVersioning();
            // 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();```
haughty rampart
devout prairie
#

shame, would be nice for that kind of stuff

rotund token
#

you kind of can

#

ijobfor.scheduleparallel(2)

#

will only work on 2 threads max

frosty siren
haughty rampart
#

wow so much i didn't know yet

rotund token
#

and you can manually calculate the indices per thread

devout prairie
#

i worked with c4d's c++ api quite a bit, and i'm pretty sure from memory it had some nice threading tools with the ability to be specific about launching thread count

rotund token
#

but you can automate this a lot less effort if you just write a custom scheduler

junior latch
#

As a simpler question, is there a way to setup an entitycommandBuffer to playback automatically after a job is finished, and before later queued jobs?

haughty rampart
#

doesn't it do that automatically?

junior latch
#

Uh the examples suggest otherwise but I haven't actually tested

devout prairie
#

ecb will playback in the ecb system itself afaik

haughty rampart
#

if your other jobs are in others systems you should have no problem

rotund token
#

that's the whole point of the EntityCommandBufferSystem

#

and while I recommend against adding new ones (sync points) you can

junior latch
#

So if I just add one without calling playback, and a job is queued after, everything will work fine?

#

man they really need to update the examples this is stupid lol

devout prairie
junior latch
haughty rampart
#

yes

haughty rampart
junior latch
haughty rampart
#

that's why i said in about

#

XD

devout prairie
#

well with scheduling the jobs can be actually run in any order unless you specify that one job depends on another

junior latch
safe lintel
#

btw @rotund token do you happen to know if theres any way to use dynamic buffers with dataflowgraph?

rotund token
#

i don't sorry, i'm not that familiar with dfg. i wasn't that happy with it/performance when i looked at it way back and have my own graph implementation

junior latch
#

Also also, if I have a really simple thing I wanna have done after a job is completed and before some other stuff happens, (some cleanup) is it fine to schedule a small job for it or should I be doing something else/not doing that at all?

haughty rampart
#

small job should be fine

junior latch
#

Alright, ty you guys have been a massive help and probs saved me anywhere from an hour to many of googling and trial and error

#

appreciate it

haughty rampart
#

if you can cram the cleanup in after the actual work in the same job, that might get you a bit better performance? although that may depend if it's a parallel job or not

safe lintel
#

ah ok, thanks anyway

junior latch
#

the cleanup that is

devout prairie
rotund token
#

dependency = myNativeArray.Dispose(dependency);

i've always found this interesting

#

why does the next job care about this dependency ^_^

haughty rampart
#

because that's how it knows what order

rotund token
#

we just leave all our dispose dangling at work

#

we don't care when it disposes as long as it does

devout prairie
#

well i guess it clears temp memory of that array data

junior latch
#

I don't really understand how foreach works, some of the documentation I found suggests its singlethreaded? but then the more recent stuff wasn't really clear?

devout prairie
#

then you move on an do other bits

haughty rampart
#

schedule is singlethreaded. scheduleparallel is multithreaded

junior latch
#

I see, okay

junior latch
rotund token
#

dont use IJobParallelFor

#

its old

haughty rampart
#

though schedule doesn't mean all that use schedule will be on the same thread

rotund token
#

just use IJobFor

#

that's what is probably confusing you

junior latch
#

It's not marked as deprecated though

#

But that would make sense yes

haughty rampart
junior latch
#

lol

#

Ah unity

rotund token
#

actually thats a good question, ive been meaning to ask unity about that and conversion systems

#

and if anything is changing

haughty rampart
#

SystemBase or probably System with 0.5 all the way

#

ISystemBase will definitely be ISystem

rotund token
#

i suspect they're not calling it System due to issues with the System library

#

but i don't have confirmation on that

haughty rampart
#

idk. it's def ISystem though. not ISystemBase anymore

#

and i actually doubt that they would call the class SystemBase then because that would just be even worse even with considering the system namespace

haughty rampart
#

if class: SystemBase
if struct ISystem

probably lots of people would be upset

junior latch
# rotund token just use IJobFor

I'm not sure how to translate easily? I want to iterate a known number of times and create that many entities, with IJobParallel for I can just pass the total number of iterations and the innerloopbatchcount, but with IJobFor I need to pass entities?

rotund token
junior latch
#

ah it just requires an explicit jobhandle

rotund token
junior latch
#

which IJobParallellFor didn't

rotund token
#

you can just pass in default if you don't n eed it

haughty rampart
rotund token
#

go make a class called System

#

and look at your whole project break

#

using System;

haughty rampart
#

only if you use the system namespace

haughty rampart
#

which you likely won't in dots

rotund token
#

there's only 316 uses of it in the Entities package alone

haughty rampart
#

shrug there's always aliasing

#

but maybe you're right. but then i would not like to see ISystem as well

#

then they should just stick with SystemBase / ISystemBase or like better JobSystem / IJobSystem

junior latch
#

Any reason I shouldn't use Job.withcode() to create a job? specifically thinking to use this for the cleanup stuff I mentioned earlier but also asking for more complex stuff

rotund token
#

no reason it works perfect for what you're suggesting

junior latch
#

Awesome ty

haughty rampart
#

since we were on compute buffers recently, i've got a tangential question to that. a computeshader has a .SetBool() method
with the SRP's you are required (encouraged?) to use a commandbuffer though. but i can't find a commandbuffer.SetComputeBoolParam() method or similar. all other param types have a method though. anything i'm missing?

junior latch
#

Is there a way for me to force a sync for a new entitycommandbuffer after a job is completed/before a new job starts without doing a .playback in the main thread (regardless of where they are structured relative to the predefined ECBSes)?

haughty rampart
#

i don't think so

junior latch
#

Well while we're on the topic of bad news I might as well ask, can I do something like this in Entities.ForEach?

    [BurstCompatible]
    public struct FillHexGrid : IJobEntityBatchWithIndex
    {
        public HexGrid Parent;
        [ReadOnly]
        public EntityTypeHandle TypeHandle;
        [ReadOnly]
        public ComponentTypeHandle<Hex> HexHandle;

        public void Execute(ArchetypeChunk chunk, int batch, int index)
        {
            var entities = chunk.GetNativeArray(TypeHandle);
            var hexes = chunk.GetNativeArray(HexHandle);
            for (int i = index; i < chunk.Count; i++)
            {
                Parent.Hexes[Parent.getIdxFor(hexes[index].q, hexes[index].r)] = entities[index];
            }
        }
    }

specifically having the parent field, (I'm effectively trying to modify a nativecontainer).
When I try this

Entities.WithBurst().WithAll<Hex>().ForEach((ref Entity e, ref Hex hex) =>
        {
            test.Hexes[test.getIdxFor(hex.q, hex.r)] = e;
        }).ScheduleParallel(handle);

I get
InvalidOperationException: The previously scheduled job TacticalSystem:OnCreate_LambdaJob0 reads from the Unity.Entities.EntityTypeHandle OnCreate_LambdaJob0.JobData._lambdaParameterValueProviders.forParameter_e._typeHandle. You must call JobHandle.Complete() on the job TacticalSystem:OnCreate_LambdaJob0, before you can deallocate the Unity.Entities.EntityTypeHandle safely.

haughty rampart
#

first, you do not need WithBurst() foreach is burstcompiled by default. second, you do not need to pass the handle into scheduleparallel

junior latch
#

ty for #1, as for #2 why do I not need to pass the handle?

haughty rampart
#

oh wait, right, um, maybe you do need the handle

junior latch
#

Also either way that isn't solving the issue

#

From what I understand it doesn't like that I'm trying to access/modify the nativearray but I'm not sure how I'm supposed to do that then?

haughty rampart
#

hm, well i have to think about it a bit. btw, you should not pass Entity by ref or in

junior latch
#

ah right ty

haughty rampart
#

for the error itself unfortunately i'm not a big help. i haven't worked a lot with typehandles

junior latch
#

The typehandle stuff doesn't seem to be relevant, I just need to know if/how I can reference a nativeArray in a foreach

haughty rampart
#

you can just access a native array in a foreach

#

it must be a method local native array though

junior latch
#

Also even then I still get the same error

haughty rampart
#

the error has something to do with the entity type handle though

junior latch
#

Oh

#

I'm an idiot

#

lol

#

had to do handle = foreach and then complete

#

w/e

#

ugh -_-

haughty rampart
#

👌

junior latch
#

Well I'm having a great time, I'm trying to set up a grid of entities in an ECS manner, but it seems to be impossible.
Trying to set up a Singleton Entity which would hold references to what is effectively a 2d array of Entities(yes I know it's not really the ECS way to do this, but the alternative is not only a larger execution speed cost from having to iterate over all entities every time I wanna find some entities within a certain range, but also some memory overhead as all the Entites have to know their coordinates)
I can't use NativeArray because it's not blittable, but I also can't use a Dynamic Buffer because not only do they not allow for parallel writing, but I also can't do something as simple as

        public DynamicBuffer<HexEntities> HexEntities;
        [ReadOnly] public HexGrid HexGrid;
        [ReadOnly]
        public EntityTypeHandle TypeHandle;
        [ReadOnly]

        public EntityCommandBuffer.ParallelWriter Ecb;

        private static readonly float Sqrt3 = Mathf.Sqrt(3);

        public void Execute(ArchetypeChunk chunk, int batch, int index)
        {
            var entities = chunk.GetNativeArray(TypeHandle);
            for (int i = 0; i < chunk.Count; i++)
            {
                var coords = HexGrid.getHexCoordsFor(index);
                HexEntities.Add(new HexEntities{Value = entities[i]});
                Ecb.AddComponent(index, entities[i], new LocalToParent{Value = ComputeHexPosition(coords)});
                Ecb.SetComponent(index, entities[i], coords);
            }
        }

because I'm restructuring the DynamicBuffer every time.

Is there a reasonable way to do this with relatively pure ECS or should I really just use a NativeArray and use some system fields rather than a singleton?

#

impossible
obscenely difficult*

rotund token
#

I can't use NativeArray because it's not blittable
what is stopping you use native array

#

also dynamic buffer has the exact same parallel limitations of nativearray

rotund token
devout prairie
#

well i guess i'm looking at it from the context of ForEach jobs, but you could maybe try using the ecb for the buffer..

haughty rampart
#

if you really want to do this like this, which i wouldn't recommend, you might as well use a fixed buffer. that's probably be the best way for this approach

junior latch
junior latch
junior latch
junior latch
#

And what alternative approach would you recommend?

haughty rampart
#

i thought you had a fixed size grid?

junior latch
#

Well the grid is fixed once I intialize it with a certain width/height

haughty rampart
#

theres also fixed list for dynamic size

junior latch
#

From what I could gather, the fixed lists aren't anywhere near bug enough, since I'm trying to plan for anywhere from a minimum of a few hundred to a max of a few thousand hexes

devout prairie
#

i would suggest get it working then optimize from there..

#

i think using a DynamicBuffer is possible it's how i do some stuff..

#

but also just having a dedicated system, with a member NativeList might be the simplest approach

#

but i'm not exactly sure on your setup/requirements

junior latch
haughty rampart
#

yes you can

junior latch
devout prairie
#

ecb.AppendBuffer i think

devout prairie
haughty rampart
junior latch
#

I'm trying to create a hex grid system for my game, basically.

The main requirement for this is to use coordinates somehow and be flexible enough to use in at least two situations later on down the line (one where the grid is relatively small, and one where it's much larger) and potentially some variability within each of those examples

From my thinking, I can either store the coordinates for each hex inside of each hex so whenever I wanna get all the hexes within x tiles of another hex I check them all to try to find the ones with matching coordinates,
OR
I have some sort of data structure that holds all the references for me in a structured way so I can calculate the exact hexes I need mathematically and just use those directly.
(This is for example to highlight them)

#

I mean maybe I'm doing this completely the wrong way and ECS and Burst are so efficient I should really just iterate over the max few thousand hexes and compare their coordinates vs what I need, but that seems fundamentally wrong to me 😅

haughty rampart
#

maybe @robust scaffold can help you here more

devout prairie
#

Quite similar to a spacial lookup system then like quad trees etc

#

With the benefit that all your hexes are fixed in position so once you have your data layout of hexes, you're just looking those up right

junior latch
devout prairie
#

Some interesting math involved obviously to convert a lookup of a bunch of hex positions around a specific radius to a lookup of a linear list of hexs

#

But not that difficult really

junior latch
#

Yeah, I'm quite looking forward to setting it up cuz it'll be quite satisfying I'm sure but need to figure out how I'm storing it first 😅

#

Hexes are cool

devout prairie
#

i mean the quickest an easiest would literally just be iterate all with burst as you said

#

but definitely possible to optimize that further

#

so for example say your hex's are a bunch of entities each with a Hex tag and a Translation component.. just iterate all and check if dist of your focal point and translation.value is less than certain amount, and if so update that hex or add it to a NativeList which you can then process in an additional step

#

something like a basic quadtree system could optimize this by quite a bit though

#

and then there's other ideas that go even further

junior latch
#

I'm just really worried about linking the amount of time it takes to get these hexes for a certain set of arguments to the size of the grid when I don't have to

devout prairie
#

yeah that's really where stuff like quad trees etc can come in handy

#

rather than brute forcing the whole thing you're breaking down into a predictable number of steps no matter the size of the data set

junior latch
#

I mean the appendBuffer stuff you suggested should work exactly like I need, tbh. I'm just uncertain how performant adding stuff to a buffer is at this point

#

When I'm potentially adding a few thousand entities

junior latch
devout prairie
#

and disadvantage is your results are delayed until after the ecb has played out

#

i would definitely suggest, look up basic quadtrees and get an understanding, and then re-think how you're doing it in the context of ecs

junior latch
devout prairie
#

so you're constantly doing lookups and modifying say the material of the hex grid or whatever

junior latch
#

Once I've created it I have all the references I need to then be able to do the stuff mathematically and getting a subset of hexes to (for example) highlight a certain way should be very simple

#

Thanks for discussing this for so long btw, I rly appreciate the help

devout prairie
#

Ah i see what you mean yeah you're just trying to populate the array

#

Really it shouldn't be that difficult i think you should be able to initialize a NativeArray or even NativeList in a systems OnCreate if you're able to pass in the count

#

and then burst through all the hex's and update the specific indexs

#

let me try and do a quick ForEach example of what you've attempted above with your struct job..

devout prairie
#

Okay so roughly, something pointing in this direction ( again not exactly sure if it fits your exact use case but this is how i'd roughly approach with just a ForEach ):

protected override void OnCreate()
{
       hexQuery = GetEntityQuery(ComponentType.ReadOnly<HexTag>());
       var hexCount = hexQuery.CalculateEntityCount();
       HexEntities = new NativeArray<Entity>(
                  hexCount, Allocator.Persistent);
}
protected override void OnUpdate()
{
      hexEntities = HexEntities; // local copy
      Dependency = Entities
      .WithAll<HexTag>()
      .WithNativeDisableParallelForRestriction(hexEntities)
      .ForEach((Entity e, ref Translation t, in int entityInQueryIndex) =>
      {
          var coords = GetHexCoordsFor(entityInQueryIndex);
          hexEntities[entityInQueryIndex] = e;
          ECB.AddComponent(entityInQueryIndex,e, 
                new LocalToParent {
                    Value = ComputeHexPosition(coords)
                });
          t.Value = coords;
      }).ScheduleParallel(Dependency);
}
#

So yeah only thing i'm not sure is if it'll let you init the NativeArray in OnCreate with the result of a query count, worth a shot though and i'm sure there would be a workaround

#

I'm assuming your HexEntities is essentially just an array of Entities

#

There's other approaches also, you could simply create a list of hex entities directly from a query, and store it to the array

#

*just updated to add WithAll<HexTag> and also writing directly to the Translation t instead of using ECB to set that ( if coords is indeed Translation value )

junior latch
#

Or an entity with a HexGrid component rather

devout prairie
#

I have to say i'm not exactly sure what you mean, sorry i'm probably just being a bit thick 😛

junior latch
#

Nah I'm probably not being clear enough since I don't understand the limitations of what I'm working with.

I'm unable to use a struct containing a NativeArray as a component because they aren't blittable. This means that if I go with this approach, I wouldn't be able to easily pass this HexEntities data structure to other systems by having it exist as a singleton entity with a HexGrid component. (If my HexGrid is the struct containing the NativeArray).

#

I'd wanna store the HexEntities array for as long as I want since I'm using it to get the other hexes so I have to store it somewhere

devout prairie
#

Yeah i mean with my approach you'd need to reference the system/nativearray with the data, from other systems that need it, and i'm not sure of the overhead of that or if it breaks the ecs paradigm, i did have a discussion a week ago or so on here about that..
So definitely the alternative approach is just to use a singleton entity with a DynamicBuffer containing the data you need.. which is i take it what you were trying to do originally..

#

Essentially i think with the code i've written above, just replace HexEntities with the dynamicbuffer..
var hexEntities = GetBuffer<HexEntity>(hexBufferEntity);
Something like that i think

#

And either add to the buffer inside the ForEach or make sure the buffer is pre-inited to the size you need and fill the indexs directly

junior latch
devout prairie
junior latch
junior latch
#

So just wanted to thank you and say that the good news is that it all works and is great so ty all, the bad news is I now realize that when using localToParent apparently the parent also gets a buffer of its children which has equivalent data to my Hexentities buffer LOL so now i'm gonna see if I can hopefully just use that the same way to avoid duplication

rotund token
#

From what I can see you're making a hex grid out of entities correct?

junior latch
junior latch
rotund token
#

Ok so it's just you want to attach it to any entity got it.

So my actual question is, why are your individual cells entities in the first place?

#

This seems to be a common early mistake people fall for; making everything into entities

junior latch
#

eg to get all the actors within x tiles of a hex i'd have to either have an array (or equivalent) with a bunch of empty fields that actors would could walk around in, or iterate through all actors' coordinate data

junior latch
rotund token
#

Without knowing your exact requirements, in general the best approach imo for handling a world grid is just building a 'standalone simulation' and just attaching it to a singleton

junior latch
#

And if I wanna allow variable sized grids?

#

just create a super massive one and shrink it based on requirements?

rotund token
#

Nothing stopping you, I have an infinite world

#

If you don't want to deal with the complexities of storing this in a singleton (unsafe code) , you can do what we did at work and just have a single system hold and manage the dependencies for the grid access

#

Personally I find this gross but it's a very very common approach

junior latch
#

Honestly the part I'm most worried about is dealing with the graphics aspect of variable heights for my mesh because I don't have much experience with Unity and almost none with the graphical aspect of 3D games so wanna make that part of this project as straightforward as possible

junior latch
#

Or say if I wanted to highlight all the hexes within x tiles of a central one, how would you approach that?

rotund token
#

On a fixed grid that's purely maths

junior latch
#

I mean that's true

rotund token
#

On a hex grid slightly harder but still the idea is the same

#

Are you using physics or something for this?

junior latch
#

No

#

Shouldn't need to

rotund token
#

Yeah that's what I thought

#

So I don't see why making it entities helps you for this

junior latch
#

Being able to adjust heights easily is #1

junior latch
rotund token
#

Id just use a spatial query on a point

junior latch
#

Yeah

rotund token
#

Whether it's physics or my own collection

junior latch
#

I'm personally not a fan of that approach idk

#

Would be cool if the system was easily drag and droppable in 2d as well

#

also something like pathfinding could be annoying without hexes I think?

rotund token
#

again, how does making the hexes into entities help any of this

#

instead of just using collection of structs or something

junior latch
rotund token
#

not at all

junior latch
#

It also doesn't really offer the advantage of easy rendering but that's minor

rotund token
#

unity writes most of their solutions as standalone simulations

#

i.e look at physics

#

they convert all the entity data into rigidtransforms etc

#

and only use that in the physics simultion

#

they don't use entity data at all, it's a completely standalone simulation

rotund token
junior latch
rotund token
#

anyway i should at least say, if it works for you go for it. maybe your game is quite simple and it doesn't need an elaborate optimized design.
i currently spend most of my time at the moment trying to make stuff run on old consoles so performance is at the forefront for me and I am hyper focused on this.
however i will leave you with a warning though and that is in the past 4 years I have seen a lot of users fail trying to implement entities are grid. these are mostly really large grids/games so scale matters.

junior latch
#

I mean I want to allow the possibility of creating a large scale grid, I'm just uncertain which part of this wouldn't work with that :/ Is it just trying to draw them all or is it something inherent to using Entities rather than a structured array of data? are you saying I should just be doing that?

rotund token
#

There's a lot of pitfalls, however if you say stick to only using 1 system to do all your game logic and are just using entities to store your data you avoid a lot of this

#

but again, if you are just using entities to store your data the question comes back around to, why store it on entities instead of a separate struct if you not are iterating/working on them? just slowing down everything for no reason.

devout prairie
#

Just to chime in - i think your grid will be a bunch of hex objects being rendered tho right, either way..

#

I mean you could obviously cheat and have a single texture which draws the hex's all onto a plane, if that suits..

#

but if you're hex grid is physical hex's ie 3d objects then i'm guessing you're instantiating those in your world.. in which case i'd understand the requirement to map Entity id's to the logical spacial data

robust scaffold
#
protected override void OnStartRunning()
{
    _altWorld = World.All.Where(world => world.Name == "Alternative World").First();

    var pullState = _altWorld.CreateSystem<PullSystemState>();
    _altSystemState = pullState.StatePtr;
    _altWorld.DestroySystem(pullState);

    var simulationGroup = _altWorld.CreateSystem<SimulationSystemGroup>();

    var testSystem = _altWorld.CreateSystem<TestSystem>();
    simulationGroup.AddSystemToUpdateList(testSystem);
}

protected override void OnUpdate()
{
    if (!_altSystemState->Dependency.IsCompleted)
        return;
    
    _altWorld.Update();
}```
#

I'm gonna try to see if I can create an independent-from-FPS updating world by manually calling update and checking the World's dependency chain. I think this works... hopefully without blowing up spectacularly.

#

The root of .IsCompleted is an internal C++ call that is marked threadsafe readonly so theoretically this should work

robust scaffold
#

Fuck, doesnt work

#

still stalls main thread until dependency is completed...

#

Oof. I dont think unity likes what I'm trying to do

#

nope, not at all

#

alright, unity really doesnt like that. Crashed my whole computer when I ran it again. Full blue screen of death

#

Hrm, job completion upon end of frame seems to be baked into IJobEntityBatch inherently. I've tried all sorts of ways to get IJobEntityBatch to last longer than 1 frame but it just wont

#

Exact same issue with IJobChunk. I'm thinking its something to do with the query mechanism.

#

TODO tomorrow, attempt to port IJobChunk to IJobFor. I know that IJob and IJobFor / IJobParallelFor are frame independent. There could be a way to instead use the framework of an IJobFor to iterate through chunks independent of frame...

rotund token
#

not exactly the same but our server world is broken into 3 frames

#

initialization + simulation2 first frame
simulation second frame
networking third frame

#

and we have jobs that run into the next frame without issue

rotund token
hollow jolt
# robust scaffold

i seen this popup so many times , considering to use this as my lock screen wallpaper

devout prairie
#

Anybody know what works and doesn't work within the ecs/dots ecosystem on Unity 2021?

#

Currently using 2020 but there are a couple of things i'd like to take advantage of in 2021 ( addition of a buffer input to vfx graph - currently using a workaround which writes data to a texture which is then fed into the graph )..

dense crypt
#

Since the official stance is that it's not supported I don't think it's worth getting in to. Worst case scenario you just end up having extremely hard to debug behaviour. 2021 support is probably not coming until late Q1/Q2 of 2022 according to their latest post

#

From what I've seen in this channel it seems to run fine on 2021 but it's at your own risk

devout prairie
proud pawn
#

Hi! I converted my project to DOTS and added the ClassicBuild configuration and am trying to build a scene, but when I do it the content for the sub-scenes is not loaded as well as the resolution is different in the build.

I installed platforms packages as well as all the dots packages. See the screenshot. Any Ideas what am I doing wrong?

devout prairie
robust scaffold
robust scaffold
hollow jolt
#

here is a strange observation , i compared single threaded vs multi threaded jobs ( for the same code base ) , where i schedule them and won't force them to complete , and check each frame if handle is complete on the next frame and time the duration it took for the execution since the schedule and the handle.isComplete , some numbers :

Single Threaded is around [ 50ms ~ 100ms ] , at [ 400fps ~ 500fps ]
Multi Threaded is around [ 15ms ~ 25 ms ] at [ 250fps ~ 350fps ]

first metric is measuring Timer difference , second value is looking at the Game Stats

Which kinda looks like the single threaded jobs free up space for the unity internal jobs when looking at the profiler

devout prairie
hollow jolt
#

its less accurate then looking at the profiler but at a high enough frame rate its not too bad ( considering my jobs are quite heavy )

#

i was surprised at the fact that multi threaded jobs execution reduces frame rate

safe lintel
#

@proud pawn afaik you shouldnt have to explicitly include subscenes(maybe thats breaking it?), also to be sure you are building from the inspector panel of the build configuration asset?

robust scaffold
#

I'm reading the DOTS thread and there are just so many people asking for Unity to incorporate Rust or just switch to Bevy. I get it, bevy is just superior in terms of language and foundation but theres more to a game engine than just DOTS. Bevy is better compared to Godot in terms of a game engine than Unity...

safe lintel
#

the guys asking for a whole new language to be the driving core of dots is stupid, thread keeps getting derailed from actual development q&a

robust scaffold
#

Maybe Unity was right in never talking to us. Restarting the discussion about DOTS was a mistake.

safe lintel
#

i sure as hell wouldnt want to touch that thread if I were a unity dev

robust scaffold
safe lintel
#

its a good question, maybe the core devs left leaving it in a lurch? i dont have any other ideas

robust scaffold
safe lintel
#

well maybe my other idea is the whole direction dspgraph was going in was the wrong one?

robust scaffold
#

Maybe we should just get together and rip apart Entities.. I'm planning on spending a few days to maybe weeks trying to find a way to implement a frame independent IJobEntitiesBatch.

haughty rampart
#

i hate that one guy in the thread who's like: uhhh, i think dots was a mistake. literally only big projects benefit from it. unity shoiuld've focused on something that does graphics better. like unreal engine nanite, .........

rotund token
#

Well I think we'd all like nanite but that's a completely separate issue

#

I do wonder if unity has madly rushed something experimental in the works to compete

devout prairie
#

i kinda see it like a whole new paradigm, basically taking everything every game engine and platform has ever done over the past 20 years and throwing it out, doing it a different way

#

so i think architecting that should take a lot of time.. they've been good enough to give public access while they do it

#

they're kinda simultaneously creating something entirely new, whilst trying to bridge it to the old world..

#

so you look at the thing as whole, and say to yourself, have you ever worked on a big project that didn't require substantial refactoring along the way, rethinking parts, etc

zenith stirrup
devout prairie
#

when every game and app out there sucks the life and battery out of mobile devices, hogs memory really inefficiently and yet, hardware year on year has got multiples more powerful, you have to say - there's some pitfalls to oop, devs are being reckless

zenith stirrup
#

it’s kind of like asking Microsoft if this whole linux subsystem is going to be worth it over say using Linux directly.

frosty siren
#

I have jobs chain like
JobA0 writes to array 0..5 indexes then JobB0 and JobC0 reads 0..5 in parallel (so JobB0 and JobC0 depends on JobA0)
all this happens N times, so next
JobA1 writes to array 6..10 indexes then JobB1 and JobC1 reads 6..10 in parallel

but safety system throws an error, because JobA1 scheduled after JobB0 and JobC0

i can schedule all JobA before all JobB and JobC, but it leads to unnecessary iterations. Maybe i can use some attribute like [NativeDisableContainerSafetyRestriction]? Will it help?

devout prairie
#

i'd love to see an A/B comparison between two simple cases, a simple game with all the usual OOP inheritance and spaghetti junction stuff, against some equivalent dots/ecs thing - i reckon even without using schedule or parallel, just run, with well structured cache friendly data etc it's going to be 200% faster and better.. probably, paradoxically, easier to deconstruct and understand also than the OOP mess.

rotund token
#

well if you strip it back to just burst/jobs i have a few examples of converted code

  • i experimentally rewrote our template placement at work and it went from taking ~4 seconds to ~200ms
  • i also have a person project with a multi frame noise/terrain gen function that takes, no joke, 180 seconds to execute without burst on in mono but only ~1 second with burst
#

(because of that last one I asked Unity and they're investigating if it's possible to always force burst on with an attribute because it basically prevents me turning it off project wide for debugging)

devout prairie
#

burst in itself is a revelation.. someone shared an article here with the whole thought process and reasoning behind it, just amazing, imo

#

i mean i'm not blowing smoke up their *** i genuinely love what they're doing, but i do also wonder maybe they could get shit done a little bit quicker ( and be a bit more transparent on it )

haughty rampart
robust scaffold
#

Ya know, Im staring at EntityComponentStore source and I'm thinking... why dont I make my own entities from just a collection of NativeArrays. Roll my own ECS?

rotund token
#

And write it in rust?!

robust scaffold
#

The primary issue with rolling my own ECS is how I would manage chunk segmentation via my equivalent of ISharedComponentData...

robust scaffold
#

Maybe a UnsafeList<UnsafeList<ComponentType>> EntityChunks?

#

The scheduling is probably going to be absolutely god awful.

devout prairie
#

Just noticed they've removed the little icons next to peoples discord names

devout prairie
#

Yeah because i have 'generalist' role i had a little 3d unity cube, 'programmer' had a pc monitor.. directly next to peoples names in the chat

robust scaffold
#

What the fuck unity

#

Parallel jobs can not cross multiple frames?

#

WHHHHATTT?

#

also god damn that optimization (the lack of it)

#

Yea, it's a problem with parallel jobs, not IJobEntityBatch.

#

this warrants a deeper dive, something is rotten in the state of IJobParallel.

rotund token
#

ah that's not true, i have parallel jobs crossing frames fine

robust scaffold
rotund token
#

let me load up my terrain gen library

#

the only job that causes me issues (atm) is IJobParallelDefer because it uses some tempjob memory internally when scheduling for some reason

robust scaffold
#

Something is calling complete() but I dont know what. And it's not my scripts

rotund token
#

i count 12 frames it ran over

robust scaffold
#

hrm... yea

rotund token
#

are you writing it back to Dependency?

robust scaffold
#

do you have the scheduling code?

#
Dependency = new ApplyDeltas
{
    Deltas = GetComponentTypeHandle<Deltas>(true),
    Inventories = GetComponentTypeHandle<Inventories>()
}.Schedule(_econQuery, Dependency);

SystemHandle = Dependency;

// SystemHandle = new TestJob
// {
//     Deltas = _deltas,
//     Inventories = _inventories
// }.ScheduleParallel(_deltas.Length, 1, default);```
rotund token
#

yeah you can't do that

robust scaffold
#

The commented section remains in one frame

rotund token
#

if you write to Dependency it'll be completed

robust scaffold
#

I'm manually updating this world

#
if (!_incrementTransactions.SystemHandle.IsCompleted)
    return;

_world.Update();```
#

I traversed this entire method and there is no Dependency.Complete(). Which allows the singlethreaded version of ApplyDeltas to cross frame boundaries as expected

#

But conversion to ScheduleParallel(_econQuery, 1, Dependency) results in a frame lock

#

I can remove the Dependency and straight write to SystemHandle but it wont change anything

rotund token
#
        {
            if (!this.lastUpdate.IsCompleted)
            {
                return;
            }

            this.lastUpdate.Complete();

            this.Dependency = JobHandle.CombineDependencies(this.lastUpdate, this.Dependency); // TODO should not be needed

            // Apply Update
            this.lastUpdate = this.ProcessOperations(this.Dependency);

            var camera = Camera.main;
            FrustumPlanes.FromCamera(camera, this.frustumPlanes);
            this.lastUpdate = this.clipmap.Update(camera.transform.position, this.frustumPlanes, this.lastUpdate);
        }```
all the jobs are scheduled in this.clipmap.Update(camera.transform.position, this.frustumPlanes, this.lastUpdate);
#

just looks like this

#

(more jobs above it)

robust scaffold
#

hrmmm, I need to keep testing my IJobFor / IJobParallelFor version then.

rotund token
#

but yeah, if i turn off burst and turn on my noise generation, this will run for nearly 3 minutes in separate threads in mono until it completes

#

without a forced sync

robust scaffold
#

I'm running this job completely independently from Entities (other than the SystemBase it exists in), so it's not an issue with the query systen

rotund token
#

how are you creating the world?

robust scaffold
#

'just finding the world then calling update

rotund token
#

ok but not added to player loop or anything hmm

robust scaffold
#

nope

#

completely independent

#

The issue is with this: _incrementTransactions.SystemHandle.IsCompleted. It's returning true even when the job is not completed

#

If I were to instead singlethread execute the same job, SystemHandle properly returns false when the job is not completed

#

Interesting. Turning off burst to extend the runtime of this job shows that IJobParallel can cross frames

#

However it's not stable.

#

and still bleeds into the FPS of the main loop

#

Well fuck. Turning off vsync crashed my entire laptop

robust scaffold
#

Singlethreaded: no crash of computer. Multithreaded: crashes my computer. Clearly the conclusion is self evident.

cerulean pulsar
#

Does anyone know the state of DOTS audio? Should I skip over it for now and use a hybrid solution? Going to read the DOTS Audio Discussion forum thread right now

robust scaffold
robust scaffold
robust scaffold
#

You'll be in for the long haul for any update to audio

cerulean pulsar
#

Gotcha. I think I'll just go hybrid unless I realize my audio perf is too slow

devout prairie
#

Something i've been curious about, has anybody tested performance with using several components each with a single or very few variables, compared to fewer components with a larger spread of variables..

#

i can understand the practical advantages of using more components, say if you have one system that works on only say health, another that works on weapon data, and another that only uses movement speed and translation, it would make sense to separate that data out into different components

#

just curious what the balance of that might be.. i would guess it comes down to cache utilization and stuff, which is something i've not really spent any time doing the math on

robust scaffold
#

Alright, I've crashed my computer about 10 times already. I think I got a reproducible system for the burst guys to look at.

rotund token
devout prairie
#

Yeah that makes sense, easier to split apart larger components if/when needed later

robust scaffold
#

There we go, a reproducible bug report, at least on my computer. Hopefully the burst team will help.

still pewter
#

I've been trying to get a shadergraph material to work with DOTS, but as soon as I put something as simple as a color into the base color node, in play mode the object with given material starts flickering many colors. Black, unlit black, red, green, blue, UV. Every frame a different one. Anyone know what the problem is?
I've overridden the property declaration for the Color Property to be Hybrid per Instance, and enable GPU-instancing on the material itself.

viral sonnet
# devout prairie Something i've been curious about, has anybody tested performance with using sev...

I've been pondering about this myself. Burst really like structs with 1 field for auto vectorization. The CPU doesn't seem that smart about reading several small sized structs though. (On profiling I have read stalls) It would be interesting to essentially force feed a full chunk into the L1 cache because then it doesn't matter how small or big the structs in the archetype are. Reading them by cacheline and doing something in between doesn't seem that great. I've asked this in the forum lately (to support other memory layouts) but it wasn't that helpful. I've a lot of reads in my biggest job but merging the data makes little sense. Maybe I get around in making a dedicated test for this to see how much merging would really get me.

safe lintel
#

@still pewter did you add ENABLE_HYBRID_RENDERER_V2 to your scripting defines?

devout prairie
#

it could be one of those situations like for example parallel jobs, where it's not really worth it below a certain point, but beyond that it makes a big difference

#

so i'd guess it depends on the situation also

low hazel
#

@still pewter No meme/reaction gifs here.

hollow jolt
dense crypt
robust scaffold
#

Quality of forum discussion here mates. Unity was right in never updating us. I now regret my wishes for unity to talk to us.

hollow jolt
#

is that a Keren developer ?

rotund token
#

Stopped reading that guys posts 2 years ago

devout prairie
#

God damn there's some salt on that forum, jeeez

frosty siren
#

🥲 this guys on forum makes me feel pain

devout prairie
#

If you look at what's happened over the years with 3ds Max, it's interesting and maybe relevant..
When i started out it was pretty much the industry standard for 3d modelling, animation and vfx, although of course there were others, Maya etc. It's now essentially a dead horse, new generations of artists learning Blender and old artists jumping ship, because they see that Max is a sluggish, bloated pile of legacy junk, the codebase is legacy and Autodesk have spent the last few years just buying third party tech and strapping it on top of the old.. and on top of that it's expensive..
Compare that to something like Blender, not only is it free but it's lightening fast, actively developed and constantly evolves and develops on the cutting edge of tech. Blender does everything Max does but 100x better and faster. Just starting Max takes several full minutes, Blender starts in an instant..
Now looking back, Max could have kept on top of the game, if they'd wanted and had vision. Substantially refactoring old legacy code, cutting dead weight, making it faster and better over time. But they didn't, they just kept piling on top of the old until it fell over..
So where i see the analogy is with what Unity are doing with ECS/DOTS.. A few people complaining 'why don't you just give us new features instead of working on this' etc etc.. I guess it's a toss-up between what's more important, the current Unity 'works' and new features would 'make it better', but looking ahead i think that at some point you have to make big decisions and do some work that's better in the longer term. If ever there was a time to refactor Unity at it's core it is now, before it becomes just another bloated dinosaur, and essentially gets replaced by the next Blender of game engines.

#

Despite UnrealEngine's awesomeness and all it's very cool work i feel under the hood they're doing the same, gunning for faster and leaner and better, because they know they literally have to. I think they just tend to do it more in a way of providing the end-user finished tools with these improvements rolled in, rather than the approach Unity is taking which is more bottom-up i think. I prefer Unity's approach and in a bunch of years i can see Unity's groundwork now taking it ahead of even Unreal.

frosty siren
devout prairie
#

Hehe, it's just my 2cents tbh.. i understand peoples pain, but as the saying goes you have to break a few eggs to make an omelette

safe lintel
#

yeah what autodesk did(or didnt do) to their top 3d products is really just sad, mudbox, 3dsmax, softimage, maya all languishing with few or zero updates. but at least in this case they never made any announcements of "rebuilding the core" or had open demos/preview builds of anything demonstrating anything close to such an initiative. that alone should give people some indication this isnt quite the same case for unity, nor was there ever any real developer interaction on these types of things to my knowledge. I dont even know if the 3dsmax team is different from the maya team 🥲

north bay
safe lintel
#

ha I just tested the forum ignore function, i just added his name and poof, all posts vanish like magic 🪄

haughty rampart
frosty siren
haughty rampart
astral marten
haughty rampart
#

Also, they require more dev time to work with whereas nanite is all about less dev time

viral sonnet
#

Every forum has an "AcidArrow". It's like some universal rule.

#

Having him on ignore makes threads a lot more sane and focused. His derailing is insane. I think hippocoder has just given up at this point. He'd have to delete like 98% of his posts outside of the general subforum.

viral sonnet
#

I wonder when someone will port EnTT to burst 😄

rotund token
#

finally happy with my camera/cinemachine implementation

#

might dump it unsupported on github (the cinemachine conversion, not my camera/state system)

robust scaffold
#

I would've sworn unity was on 0.21 or 0.23 internally. Yet the most recent DOTS training samples are on 0.20. Odd. The preview number though has increased from 25 to 45 within the past 3 months so something is going on. I just wish these guys would use struct based jobs and not lambdas...

viral sonnet
#

they are writing "optimized" code for a framework that doesn't exist. welcome to unity development

robust scaffold
viral sonnet
#

they still haven't talked what's actually in 0.5. it's really weird.

robust scaffold
#

Ya know, now that everything is a singlethreaded job, coding is so much easier. No need to do weird hacks to access behind the scenes class buffers or pointers. Having frame independent system update is so liberating.

#

Race conditions? Never heard of it.

#

Performance? Look that way, the graphics thread is updating at 60FPS. Ignore the simulation ticker updating at 60 SPF.

robust scaffold
viral sonnet
#

have you read the thread from the guy who uses rust for lots of stuff?

robust scaffold
viral sonnet
#

yeah

robust scaffold
#

Thats pretty much what Unity does with their game engines. If I wanted to program a game engine, I wouldnt be here.

viral sonnet
#

it's interesting in that rust has bevy and c++ has EnTT

robust scaffold
#

It's not new or radical tech, you can attach native DLLs but its a bit of a security concern.

safe lintel
#

tbh im not expecting 0.5 to be much different

robust scaffold
viral sonnet
#

into an ifdefed enable/disable feature that needs another year to iron out the edge cases ... 😆

robust scaffold
#

Just take a look at burst for example. In the same amount of time, they introduced SIMD / manual vectorization commands for nearly all CPUs, improved function pointers and enabled additional connections across the main - job thread barrier, and drastically improved the burst inspector. The DOTS team: uhhhhhhh... nothing visible. Possibly source gen'ed improved lambda code?

viral sonnet
#

apparently the entities team works on the HR and netcode too

robust scaffold
#

I dont think so about Netcode. That was branched off and now is a fully released package. Unless you're talking about DOTS netcode which has gone radio silent. Same as DOTS physics.

viral sonnet
#

working on a new renderer in 2021 and then seeing Nanite ... ouch

#

of course dots netcode

safe lintel
#

@robust scaffold yeah me too, doubt we will ever know though

viral sonnet
#

at least tims name is in the patent of entities

#

so he must be involved more than just in netcode

robust scaffold
#

DOTS netcode is definitely a different team. No way is mainline Entities gonna get this clear of an answer of whats coming in 0.50

safe lintel
#

technically nanite was in development for like 10years though, must be disappointing to see epic leapfrog your work again but then again that was brewing for a loong time

robust scaffold
#

Also the DOTS netcode team said no to ISystemBase upgrade of their provided supporting systems. Which doesnt bode well. SystemBase pretty much only needs entity query capability in bursted OnUpdate and it's feature complete compared to SystemBase.

viral sonnet
#

However, the main issue you can encounter with archetypes is the fragmentation.
Shortly, an aspect that is less evident but still present is the fact that archetypes aren’t primarily designed around usage patterns.

#

Something I'm definitely dealing with.

robust scaffold
viral sonnet
#

some serious pros and cons with archetypes with the biggest pro being so easy to multithread

viral sonnet
robust scaffold
#

I've gotten identical (well slightly faster by fractions of ms) when iterating through a NativeArray<UnsafeList<float>> as using IJobEntityBatch to access float components.

viral sonnet
#

right, which ends in weird stalls. I haven't found a good solution for this. merging data is one but really meh. it's the same problem with authoring<->runtime data. now it's component<->chunk data

#

ah interesting, I thought about dropping Entities for data that doesn't fit.

robust scaffold
viral sonnet
#

yes, when vectorized 🙂 but what if not? 🙂

robust scaffold
robust scaffold
#

Sometimes, it simply can not be avoided. Or i'm just not thinking creatively enough

viral sonnet
#

I sent you one of my code files. 🙂

robust scaffold
#

That's one giant IJobChunk

#

My most complex job is about the size of that GetNativeArray section

robust scaffold
#

My head is exploding. I dont think I can properly think in SIMD...

#

I even pulled out a sheet of paper and a pen to figure this out...

whole inlet
#

I've got a BuildPhysicsWorld system that takes about 20ms each frame to run, I've got a terrain (1000 by 1000) which I generated a manual PhysicsCollider for, to bring it into ECS land which I suspect is what's causing the long run time and thus low fps, any ideas on how I can reduce the per frame run time?

safe lintel
#

in the profiler what is taking up the time?

#

profiler timeline view that is

#

make sure to expand the jobs view

whole inlet
robust scaffold
#

also lots of empty idle time, have you considered collecting the job handles and then calling Handle.Complete() at the end of the frame?

whole inlet
#

It does help when I burst compile, however I can't debug very easily when it's on, I'll do so for release (if that ever happens).

whole inlet
robust scaffold
#

The problem with your frame utilization is that you're waiting on one very long job at the end of every system. Locking the main thread

#

Try turning every schedule parallel to just schedule.

whole inlet
#

I currently have about 3 meshes - 2 characters (low poly) and one terrain mesh - on the scene. The terrain is the one that has a lot of vertices, so I presume it's the thing that's holding everything up, just my assumption though

robust scaffold
#

only 3 meshes yet it's holding up the entire frame. something doesnt seem right

whole inlet
#

From the EntityDebugger, looking at the systems run time, it points to the BuildPhysicsWorld as the system that takes the longest at 20ms per frame - I don't have any control over this system, how do I go about changing it?

robust scaffold
#

Ya gonna have to find someone more experienced than me because I have no clue why that runs every frame

safe lintel
#

looks like the fixedstep systemgroup is doing catchup because the frame time is so long or something

whole inlet
safe lintel
#

wait did you disable burst or something?

whole inlet
safe lintel
#

sec

whole inlet
# safe lintel wait did you disable burst or something?

I did disable burst, to debug code, as with it on, I can't seem to hit breakpoints. However, with only 3 meshes on my scene, something still feels not quite right and it's easier for me to see if changes result in frame rate improvement in non-burst, rather than in burst

#

This is usually what I use to watch which system might have issues - which is why I'm drilling into BuildPhysicsWorld as it takes up the majority of the frame time, of ~22ms

safe lintel
whole inlet
#

With Burst enabled, everything runs smoother and I'm hitting 33fps, but it feels like I'm just sweeping a possible issue under the rug with "burst"

safe lintel
#

I circled what I suspect are the repeated runs of the physics stuff

#

if you click the three dots by the arrow I made theres an option to turn on something that shows what jobs are spawned by what system

#

cant remember the name but there are only a few options there

#

without burst, a heavily ecs project in unity will just run like ass, theres no real way around that.

#

like burst is essential and you shouldnt consider perf with entities without burst to be anywhere close to even good, its leagues worse than stock unity gameobjects which genuinely surprises me

#

as for debugging with or without burst, not at main comp so cant check atm and cant remember if I need to disable it for breakpoints to work

whole inlet
safe lintel
#

no, yeah its shockingly low 😅

whole inlet
#

alright, then maybe there isn't a problem here and I'm testing this wrong without burst.

whole inlet
safe lintel
#

ill ping you tomorrow if I remember to check it out

whole inlet
robust scaffold
safe lintel
robust scaffold
#

A few sheets of paper and I've done it. A vectorized way to evaluate two 8xints for most positive grouping

#

It's so beautiful. So purple

#

If you're not a robot and can not immediately understand what is going on, this is basically what that chunk of code does:
T1 = 2, -2, 1, -1 -> 2, 0, 0, -1
T2 = 3, 4, -2, -3 -> 3, 2, -1, -3
With a delta change from T1 -> T2 of 0, -2, 1, 0

robust scaffold
#

right, lets see. Maybe burst knows what they're doing?

#

damn it burst team, too good for me. Actually knows how to properly vectorize. I just spent the past 4 hours writing code that doesnt even matter.

#

Lesson learned. First see if burst knows what they're doing

robust scaffold
#

<@&502884371011731486> scammer ^

devout prairie
#

I have no idea what this does, but in my case it seems to prevent multiple instances of BuildPhysicsWorld and i think StepPhysicsWorld

#

I think i got this from the ECS Physics samples when trying to diagnose a problem.

rotund token
#

It stops physics running in fixed update

devout prairie
#

Not sure really why that is either way tbh 😐

rotund token
#

FixedRateManager is what makes it fixed update, if it's null is just a regular update group

whole inlet
#

Now, to try understand what might be going on, does anyone know what the repercussions of deleting the FixedRateManager are?

rotund token
#

Your physics won't simulate as expected

#

Lose determinism

devout prairie
# rotund token Lose determinism

Hmm yeah i definitely need to look into this more i think, it's definitely faster that's for sure, and again only does that single physics step.. is the determinism aspect more related to the networking side?

rotund token
#

you're not running with a fixed step anymore

#

so the first time you run it your timesteps will be different to the second time you run the simulation

rotund token
#

just reduce the update of the fixed update manage to like 20fps instead of 60 in editor

#

if you are concerned about lag in editor/debugging

devout prairie
#

Yeah these are the technicalities i need to get my head around with physics.. I appreciate the knowlege there..

#

I did notice it seems to be pretty slow maybe similar to uneatenbreakfasts problem.. So i guess the question is - with just terrain and a couple of characters, why is it like 20ms+ doing physics

#

ie without this deleting FixedRateManager hack

#

So if it's better to not delete that manager, why is it so hella slow

rotund token
#

it's the fixed update feedback loop

#

if you have a fixed update at say 60fps, and you are running less than 60fps - let's say 30 fps

#

then your fixed update has to run twice a frame

#

but now that it's running twice a frame your frame is taking longer, so your fps is even lower and well now you need to run some frames 3 times a frame

#

anyway from memory it's mostly slow because of jobs debugger

#

turn that off and it speeds up a lot

devout prairie
#

ok yeah i think that makes sense

#

i did notice tbf i get 30 or less fps in the editor and like 140 on built project, i wonder how much physics itself is held back in the editor

rotund token
#

if you turn off debug mode in editor and all the safety

#

it runs nearly identical to builds

#

but yeah, then no safety + can't attach debugger 😅

#

but good for your artists/designers/qa

devout prairie
#

stupid question time - how do i set my unity.physics fixed update to a specific rate? assuming i could set application.targetFramerate to a specific value and tie fixed update to that, or is that fixed update?

devout prairie
rotund token
#

by default it's 1/60

#

so what, 0.0166~
make it 0.05 for 20fps etc

devout prairie
#

Okayyyy.. thanks 🙂

#

I did say i need to look into it 😛

maiden token
#

Anyone knows if its possible to run ICollisionEventsJob jobs in an Entities.ForEach or Job.WithCode (on main thread)?

#

All code examples seem to rely on Job.Schedule(simulation, physicsworld, ..) but the project I work on the guy wants it written as ForEach or WithCode to run sound and vfx (not possible on parallel threads)

safe lintel
#

i dont think you can yet, seem to recall it was sort of on their roadmap but then again that was before they paused public releases. not a bad thing to ask on the roadmap thread

rotund token
#

245ms - OptimizeFor.Default
346ms - OptimizeFor.Performance
That's not ideal >_>

whole inlet
#

I made a dev build of my game, however I'm running into a crash. Attaching the debugger to the build, I see this error:
"Exception thrown at 0x00007FFE73526059 (lib_burst_generated.dll) in mmo.exe: 0xC0000005: Access violation reading location 0x00000280D649425F."
Any ideas on where I might look for further information? It seems like something broke in the burst sections

rotund token
#

this is mostly commonly caused by something like
ComponentFromData<Translation> trs;
var tr = trs[entity];
where entity doesn't have a translation or doesn't exist

#

you should be able to find the exact job/line of code that is crashing from the dmp file

#

there's no safety in build so any failure like this is a crash

whole inlet
rotund token
#

basically just hit that, link your pdb if you need

#

and it should show you the call stack of your crash

whole inlet
rotund token
#

In theory, the safety system should error this out for you in Unity. In practice a lot of timing issues will only show up in builds, or at least more frequently.

whole inlet
rotund token
#

/depends/

whole inlet
rotund token
#

dmps are just a memory dump of your application when it crashes. by default this only includes general information, the stack, etc

#

the pdbs store a list of all your symbols and their address of your application to link against it

karmic basin
#

Hey guys, been severely ill in Nov/Dec, did I miss something since ?

karmic basin
stiff skiff
#

Just in the hope I find someone. Anyone here know how to debug a Unity coredump from a crash in Linux?

hot basin
#

somehow my compilation never ends, anyone know why it may be?

frosty siren
#

is NativeArray.Sort job unready to use in prod or its my special case? (editor profiler)

robust scaffold
robust scaffold
frosty siren
hot basin
left oak
robust scaffold
#

Well fuck.

#

Welp, time to scrap this idea

frosty siren
#

I see in burst docs that burst can't compile generic jobs which gets context indirectly like being scheduled in generic method

//from docs https://docs.unity3d.com/Packages/com.unity.burst@1.4/manual/docs/OptimizationGuidelines.html
public static void GenericJobSchedule<TData>() where TData: struct {
    // Generic argument: Generic Parameter TData
    // This Job won't be detected by the Burst Compiler at standalone-player build time.
    var job = new MyGenericJob<TData>();
    job.Schedule();
}

// The implicit MyGenericJob<int> will run at Editor time in full Burst speed
// but won't be detected at standalone-player build time.
GenericJobSchedule<int>();

How then NativeArray<T>.Sort compiled in standalone? Is it even compiled? I've seen thread somewhere on forum, where someone have mentioned that NativeArray.Sort isn't burst compiled in build and some unity dev was like "its a shame that built-in functionality isn't burst complied, because performance by default and stuff". And it still in uncompiled state?

rotund token
#

burst goes over this in their documentation

frosty siren
#

i know, because sample code is from this docs. So it is well known fact that sort extension isn't burst compiled, ok

rotund token
#

i was under the belief it worked from about mid last year after one of the burst updates, though i haven't tested i've always just call sort from within a job already

#

side note: my personal trick for burst and generic systems

    where T : struct, IStateComponent
    where TP : struct, IStatePreviousComponent
{

    /// <summary> Create the job struct for burst support. </summary>
    /// <remarks> You only need to return default. The struct is populated for you. </remarks>
    /// <returns> The job struct. </returns>
    protected abstract StateJob CreateStateJob();

    [BurstCompile]
    protected struct StateJob : IJobEntityBatch
    {
    
    }
}```
#
    {
        protected override StateJob CreateStateJob() => default;
    }```
#

just been the easiest/cleanest approach I've found

frosty siren
#

if this is so simple and it works then i wonder why burst still can't detect such cases

rotund token
#

because burst needs a concrete implementation, i'm providing this

frosty siren
#

but if you just gives it default why then they can't do the same in analyzer when it faced indirect context

rotund token
#

the answer is mostly, performance

#

it could take a long time to compile if it did what you wanted

gusty comet
#

I'm not able to use NativeHashMapExtensions.Remove(key,value) despite having Unity.Collections in my project. This is strange considering that other extension methods like Unity.Entities Schedule are working

#

I was trying to call NativeMultiHashMap.Remove(key,value), but keep getting compilation errors claiming that the method does not take 2 arguments

#

Nevermind, I forgot to implement IEquatible for the value type of the multi hash maop

graceful mason
#

argh I see I use translation not transfrom.position, but still not working 😄 will crack on trying more

#

sorted

hollow jolt
#

what's MethodImpl( MethodImplOptions.AggressiveOptimization ) and can / should we use it with burst ?

#

i noticed that mathematics package is using AggressiveInlining , which i guess strips the method at compile time and writes the function body were its been called

robust scaffold
hollow jolt
#

Any ideas whats AggressiveOptimization AggressiveOptimization ?

#

i read a stack0erfl0w - p0st and it had s0mething t0 d0 with a JIT - which kinda seems like what burst already d0es , n0 ? ( I L0st my "0" key )

robust scaffold
hollow jolt
#

laptp getting 0ld might need t clean the keybrd r s0mething

robust scaffold
hollow jolt
#

was actually checking 0ut s0me 0ther rep0 0n github and it included that

#

s0 i th0ugh if there is a need t0 make it burst c0mpatible 0r* n0t

#

OPTIMISE = 512

robust scaffold
#

probably what they are doing is this [BurstCompile(FloatPrecision.Low, FloatMode.Fast)]. This allows for MADD and other less accurate single operation mathematics. Also assuming no null or overflow values so stripping the checks off the process log.

hollow jolt
#

s0 the0retically this shu0ld give similar speeds t0 burst ?

robust scaffold
#

That looks like to be a different .NET complier, not burst, so who knows.

robust scaffold
#

Doing some testing on shared component propagation to chunks. Apparently copying of shared components to accessible chunk components is in fact worse in terms of performance than an external HashMap containing a lookup of <int, ISharedComponent>. The HashMap lookup resulted in about 1.05 ms vs accessing a chunk component of 2.0 ms. Odd.

#

Definitely recommend anyone who cares do tests themselves but having external databases may be better than attempting to use Entities components. Which is probably why Unity has not yet implemented a ISharedComponentAccessableInJob or whatever.

plain hatch
#

Just a quick question:
Does reading from a randomly accessed entity represent a sync point when doing it outside of a job (e.g. in a monobehaviour)

robust scaffold
#

However, it will call the job complete for the dependency of any jobs accessing that component of the entity.

#

Which, depending on how you structured your jobs, may be a sync point.

plain hatch
outer panther
#

I'm trying to install the entities package in my project but am getting this error after it is done

Library\PackageCache\com.unity.entities@0.17.0-preview.42\Unity.Entities\Serialization\BinarySerialization.cs(47,81): error CS8377: The type 'T' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'NativeList<T>'

How can I resolve this?

robust scaffold
outer panther
#

I'm on version 0.15.0-preview.21

robust scaffold
outer panther
#

it's from january, but updating it will only show a november release as the latest (I'm on unity 2020.3.15f2 btw)

outer panther
#

after having updated that, I'm getting 165 errors that all have the same error code

Library\PackageCache\com.unity.entities@0.17.0-preview.42\Unity.Entities\Iterators\EntityQuery.cs(1222,100): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('EntityDataAccess')
safe lintel
#

if you add entities to an empty project you can see what dependencies it needs and then change your project's packages accordingly. the latest collections isnt compatible with it though not sure about some other packages

graceful mason
#

say I have a bunch of data components, each with unique X value.

how do i simply say get entity with component value of X if exists, or create it?

#

I justg entity query for all DataComponents... then loop the resulting array and see if an item that is what I want exists?

devout prairie
#

There is an 'change' filter which will return a query only if the component has changed, but not for narrowing down on specific values

outer panther
vast flicker
#

So i was trying to reimplement the boids demo from the Mike Acton talk (https://www.youtube.com/watch?v=p65Yt20pw0g) to learn DOTS and but have seen that "IJobNativeMultiHashMapMergedSharedKeyIndices" has now been removed from the collections package. Is the way this was done now seen as bad practice in DOTS and are there better examples/docs i could look at? The ECS samples still seem to use the removed job type.

rotund token
#

it's not bad practice, they just decided it wasn't suitable for the package. the exposed the data required so you couldn't implement it yourself

vast flicker
#

as a related follow up, in the boids example they copy all the translation components from the boids entities into an array to access later. Is this significantly faster than just calling GetComponentDataFromEntity?

rotund token
#

for this type of critical work it can be

shrewd lion
#

So I'm having trouble understanding something. Where are the gains from dots supposed to kick in? I'm instantiating 5000 trees as game objects, and then 5000 trees as entities (converting from the tree prefab; it's the tree in the unity standard assets)

And it turns out those 5000 trees as game objects run a lot faster in terms of FPS than as entities. Is this normal or am I doing something wrong? I'm not doing anything other than instantiating game objects and entities

#

This appears to be true even for empty game objects and entities; 250k empty game objects runs faster than 250k "empty" (containing only rotation, translation, prefab and localtoworld components) entities

#

Why is this happening?

robust scaffold
#

What you want to compare is the performance when you start rotating all the objects

shrewd lion
robust scaffold
hollow sorrel
shrewd lion
robust scaffold
#

DOTS hybrid renderer suffers from being a "generic" solution. A customized render pipeline and something like DrawMeshInstanced or a compute shader solution is what you want.

shrewd lion
robust scaffold
#

I only render 3 game objects and one of which requires virtual texture tiling. I am not capable of programming the compute shader required for rapid redirection table updating so I use HDRP and do simulations on 2.4M entities (not rendered). However if you are capable of doing so or slogging through the text books to learn how to, you can get 10x better performance at most just programming your own rendering solution. But then you might as well make your own engine and so on.

shrewd lion
robust scaffold
#

Even then, you can go extremely far with the DrawMeshX variant Burst arrays - compute shader pathway. It's highly recommended if you need to do anything more complex to 10k+ objects than rotating them.

amber flicker
#

A few other ideas that seem worth mentioning:
Make sure the enable_hybrid_renderer_v2 define is defined. Make sure you’re testing in a build, or at very least ensure burst enabled, safeties disabled, warm start etc. Very possible that however this tree is made is breaking instancing for the version of hybrid renderer we have access to. Lastly, dots isn’t going to help perf for a lot of people as most projects are gpu bound. Static meshes are never usually the biggest pain points either. Will mostly help for cpu simulation… though Unity continue to promise eventually job/system code should all execute faster than MBs but it’s not always the case currently.

shrewd lion
#

Clearly the GameObject object is far too heavy to have as many of these things as one might desire

#

What you said makes sense and I'll try to make it work

amber flicker
#

Yea don’t use entities for voxel representation- there’s no need. Quite a few posts about voxel stuff on the forums that’s probably worth digging through

shrewd lion
#

I'm using them for chunks, not individual voxels if that's what you mean

amber flicker
#

Cool yea that sounds sensible.

shrewd lion
#

Still, 1000 chunks and 5000 "entities" as in small drops, rocks, etc. as GameObjects will absolutely grind unity to a halt; which is why I'm experimenting with dots

amber flicker
#

If you plan to do voxel sim on cpu (rather than eg compute shaders), I’m sure dots will be much faster than GOs, yea 👍

shrewd lion
amber flicker
#

I’m not advocating either way. Just pointing out that the biggest scale voxel stuff out there is mostly gpu afaik. Doesn’t mean that’s what you should be aiming for at all - just checking you were actually aiming for cpu.

#

As otherwise dots isn’t going to help much (sweeping general statement, burst is always lovely)

rotund token
#

i have a pretty good dual contouring (with seams) implementation working with burst that can update in real time (posted a video here before)

#

i believe no mans sky uses a combination of cpu/gpu for their implementation

#

pretty certain their uber noise function is going to be the gpu as it's just not feasible on a cpu, but i think a lot of the dc is done on the cpu

shrewd lion
#

they dont have the problem with most simulation games in that most of that part of the game runs on hardware they control, you're not supposed to be able to run the master server for a no mans sky instance from your laptop

#

whereas with minecraft you might even be expected to run it from a mobile phone

robust scaffold
#

This is what math.pow(float, float) compiles to. Pain.

dreamy zenith
#

hello everyone. i am newbie. how i can translate object using local axis?

rotund token
dreamy zenith
rotund token
#

yes, translate/rotation components in ecs are in local space

#

you can use the LocalToWorld component to get world space forward/etc

#

unfortunately at this time it's a lot more manual / less helper methods

whole inlet
#

Is there any tools to help debug/see entities in a development build? I'm trying to get animations to display, but they use a method (toDenseClip) that only exists in the editor, so apparently I need to build the project in a way that embeds the prebuilt subscene in order to use the animations from it. However once built, it's empty, the build runs, but I can't see any of my entities anywhere - Is there an entity debugger but for released builds? How would you guys tackle this?

sinful cipher
#

Is it possible to disable the IJobParallelFor write range restriction for the entire job, as opposed to the per-collection basis?
The problem I'm having now is that I have a custom struct that contains 2 NativeArrays. Adding the usual attributes to fields of this custom struct type in the Job does not work.

#

Highlighted in red is the field in question

#

...which contains:

#

Of course I could just put these two arrays in the job as two separate fields, but I was wondering if I could prevent such a workaround

sinful cipher
#

This window will list all the entities

#

& click on an entity to view its components

sinful cipher
#

Does anyone happen to know what the threshold size is for these to occur with Allocator.TempJob?

graceful mason
#

can we add buffers to components?

using Unity.Entities;

public struct EngineData : IComponentData {
    public DynamicBuffer<RequiredActiveMapTileBufferElement> requiredActiveMapTiles;
}
#

I keep getting '<> used in NativeArray must be unmanaged and cannot itself be native' if i try

#

it compiles ok but then when i try to use the buffer

#

To get around it, I just added the buffer seperately to the same entity using the manager:

EntityManager.AddBuffer<RequiredActiveMapTileBufferElement>(engineDataEntity);

which I can work with, just wondering if the 1st way is possible

coarse turtle
#

Yea you wouldn't be able to add a dynamic buffer directly into a ComponentData You can add pointers to your component datas/fixedlists/unsafelists tho (pointers and unsafe lists would require you to manually manage their memory)

graceful mason
#

ok sounds complex, ill add the data seperately to the same entitys 😄

#

thanks

coarse turtle
#

fixedlists are fixed size, so they're also safe candidates 👍

graceful mason
#

It also accesses some global engine settings variables and stuff, so hopefully its ok to use it like that

#

this task isnt heavy so i not worried about schedule parallell at this point

robust scaffold
graceful mason
#

maybe but enginedata will have reference to multiple different buffers

robust scaffold
#

That sounds like object oriented coding right there but there are ways to get arrays into components

graceful mason
#

yeah 😛

robust scaffold
#
public struct EngineData : ISystemStateComponentData {
  public UnsafeList<RequiredActiveMapTileBufferElement> requiredActiveMapTiles;
}```
You will need to manage the allocation of that unsafe list (basically a NativeList) and dispose of it manually, hence the ISystemStateComponentData
#

This will massacre your Burst auto vectorization so I highly do not recommend this. Lists and references inside Component Data is highly object oriented coding and goes against DOTS design

graceful mason
#

ok, I will for now leave it as:

EntityManager.AddBuffer<RequiredActiveMapTileBufferElement>(engineDataEntity);

robust scaffold
#

How many elements do you need? You can use a fixed list interpretation inside a component as well. Also how often are you requesting that data?

graceful mason
#

Im still experimenting but just trying to code a 2d ecs chunk loading system, but am very new at the moment 😄

#

have done a load of tutorials including a standard unity 3d chunk loading system series before: https://www.youtube.com/watch?v=h66IN1Pndd0 *20+ hours) so have done siimilar, but not using ecs

JOIN THE DISCORD SERVER!

https://discord.gg/aZgBgC2


NOTE: I have NO idea what happened around the 6:30 minute mark with the epilepsy-inducing flashing red screen. Sorry about that :-/

This is my first attempt at a coding tutorial video. As I explain in the vi...

▶ Play video
robust scaffold
#

On that note, I just finished a manual vectorization of a exponential estimation function, currently 2x faster than math.pow() but requires all positives and only accurate within the ranges of 0.5f and 7f.

#
private static void ComputeTaylorExponential(v256* inputPtr, v256* outputPtr, v256* powerPtr)
{
const int vectorLength = Length / 8;

for (var i = 0; i < vectorLength; i++)
{
    var input = inputPtr[i];
    var power = powerPtr[i];

    var ln = new v256(0f);
    var numMulti = X86.Avx.mm256_div_ps(X86.Avx.mm256_sub_ps(input, new v256(1f)),
        X86.Avx.mm256_add_ps(input, new v256(1f)));
    for (var j = 1; j <= Expansion; j++)
    {
        var numerator = numMulti;
        for (var k = 1; k < 2 * j - 1; k++)
            numerator = X86.Avx.mm256_mul_ps(numerator, numMulti);

        var denominator = new v256(2f * j - 1f);

        ln = X86.Avx.mm256_add_ps(ln, X86.Avx.mm256_div_ps(numerator, denominator));
    }

    ln = X86.Avx.mm256_mul_ps(ln, new v256(2f));

    var exp = new v256(0f);
    var multiplier = X86.Avx.mm256_mul_ps(ln, power);```
#

    
    var sign = X86.Avx2.mm256_srai_epi32(multiplier, 31);
    sign = X86.Avx2.mm256_mul_epi32(sign, new v256(2));
    sign = X86.Avx2.mm256_add_epi32(sign, new v256(1));
    sign = X86.Avx.mm256_cvtepi32_ps(sign);

    multiplier = X86.Avx.mm256_mul_ps(multiplier, sign);
    
    for (var j = 0; j <= Expansion * 2; j++)
    {
        var inverseMulti = new v256(1f);
        for (var k = 0; k < j; k++)
            inverseMulti = X86.Avx.mm256_mul_ps(inverseMulti, sign);
        
        var numerator = new v256(1f);
        for (var k = 0; k < j; k++)
            numerator = X86.Avx.mm256_mul_ps(numerator, multiplier);

        var denominator = new v256(1f);
        for (var k = 2f; k <= j; k++)
            denominator = X86.Avx.mm256_mul_ps(denominator, new v256(k));

        var main = X86.Avx.mm256_div_ps(numerator, denominator);
        main = X86.Avx.mm256_mul_ps(main, inverseMulti);

        exp = X86.Avx.mm256_add_ps(exp, main);
    }

    outputPtr[i] = exp;
}```
#

so yea, absolute pain debugging that

#

Benchmark, the first number is math.pow() result, second is estimated

robust scaffold
graceful mason
#

yeah i mostly achieved that tutorial using DOTS in the past, but I had performance issues so didnt have it right, and 3d is complex so figured i could do a 2d :D. Ill try a few more days see if i get anywhere.

robust scaffold
#

For any performance improvement, you must understand how the burst compiler works and all the tricks it requires. A correctly designed DOTS entity component structure requires a completely different way of thinking from standard OOS mono coding.

#

Taking a tutorial designed for mono scripts and converting it to DOTS correctly is honestly one of the most challenging tasks I think a programmer can do. Very low skill "floor" as DOTS is fairly forgiving in what can actually be computed but stratospheric skill ceiling as doing it correctly requires knowing the Entities source code inside and out.

graceful mason
#

the main bit I struggled with is, I can burst my entire game logic using the burstable stuff inside my arrays, but my world is split into 16x16 tiles each with own array. And I can burst within a given 16x tile, but never worked out how to access a neighbour tile well to calculate logic at boundarys.

#

then it got a bit OO'y

robust scaffold
#

what are you computing?

graceful mason
#

not sure yet, but maybe want to try a sand simulation..very basic style

robust scaffold
#

also 16 * 16 is divisible by 8, which is good, but it's 32, which is ouch, quite a bit.

graceful mason
#

Download and play with this simulation here: https://tinyurl.com/43dzu9r5

Java Repository: https://tinyurl.com/88ndcdez
C++ Port Repository (In Progress): https://tinyurl.com/a246r6pp

Links:
All the old Java Applets: https://androdome.com/Sand/
Exploring the Tech of Noita: https://www.youtube.com/watch?v=prXuyMCgbTc&t=322s
Conways Game of Life...

▶ Play video
#

but i will use perlin to generate a random world, you could drop sand / water into

robust scaffold
graceful mason
#

I have made a simulation work before, but want it in an endless generating world 😄

#

not a predefined size grid

robust scaffold
#

Something simple would be a flat sand surface and then clicking or just a random distribution at the start would smooth the surface out over time via diffusion.

robust scaffold
#

honestly Burst is not structured properly for 2D or 3D arrays required for something like a sand simulation.

graceful mason
#

yeah my game logic uses 1d array, with functions to know the above/left/right cell

robust scaffold
#

Burst works linearly along a 1D index and preloads linear data for vectorization along that index.

graceful mason
#

but i struggle at Chunkboundary, to get the cell

robust scaffold
#

Even knowing above, left, and right breaks vectorization as those are random accesses.

#

What you want is a compute shader. Those are designed with 2D and 3D wavefronts in mind with proper index access.

graceful mason
#

I see, thanks, Ill look at those

#

GPU stuff

robust scaffold
#

And do you need chunks? What's wrong with just simulating everything singularly? And yea, check out compute shaders. They're basically Bursted Jobs with a little less flexability.

graceful mason
#

Maybe for a 2d game its ok, but for 3d game i use chunks, so mesh only exists for nearby chunks

#

so i only have about 4x TileMesh Gameopbjects at a time, that get dynamically created and destroyed

#

using data from my DynamicBuffers

#

as you scroll around

robust scaffold
#

If you want mesh culling and modifications, yea. Focusing on GPU side calculations will be the best way forward.

graceful mason
#

unity tilemesh is limited size etc, so chunks of data there

#

the game iutself is simulated singularly

#

but in chunks hmm :S

#

i wanna make a basic minecraft in 2d ideally

#

but with some OxygenNotIncluded style machines or something

whole inlet
robust scaffold
sinful cipher
#

I wrote this bit for my own specialized 'entity inspector' within the editor. But the same idea could be done for development/release builds as well.

#

Note: EntityQueries have to be disposed though if created every update like this. Its something you dont have to think about when doing this from within a System.

coarse turtle
remote crater
#

The Holy Grail of reusing your Old GameObject code game and adding DOTS/ECS levels without ever having to recode your player controller twice: https://youtu.be/GIEV14B20Pc

#

Sorry it's stupid rambly, and wait about 10-20 a few minutes for upload/processing on youtube.

#

Everyone who has old GameObject games can simply make DOTS/ECS games without starting from scratch, it is awesome.

#

The basic concept is this: After making entity off your player gameobject, keep gameobject in memory, do not render gameobject it and remove collider from game object

#

Then as you move gameobject with your ol player controller, Entity player just mimics it

#

In the basic idea: You force the entity player to be where the gameobject player's position/vel/angle is.

#

The advance idea: You read in the entities' velocity/angle/position

#

Then player controller adjusts it

#

And you send back the velocity/angle

#

for if you force position, you mess the collision engine