#archived-dots

1 messages ยท Page 211 of 1

night venture
#

ok...that was already answered, so here it goes the reasoning:

#

If i were going to load an "external 3D model" on my ECS system, would I need to instantiate a gameobject? would I use a prefab?

zenith wyvern
#

Typically you would author a traditional gameobject with your mesh attached then use the conversion system to convert it to an entity at runtime

night venture
#

how it's supposed to load ECS "visible objects" (so far to my understanding, i added typeof(RenderMesh) to my archetype

#

so, I need gameobjects to load 3D meshes into DOTS !?

zenith wyvern
#

You don't "need" to, but the expected workflow for dots is you author in the editor with traditional gameobjects/prefabs then the conversion system converts those into entities for runtime

night venture
#

ok....so the expected workflow (until DOTS supports otherwise) is to have gameobjects, prefabs and such things and convert them into entities at runtime.

zenith wyvern
#

Doing it that way is a lot easier than trying to manually add all the necessary components at runtime as well, in my experience

night venture
#

yes...it might be easier, but not "pure ecs". and, tbh, sounds quite "temporary"

#

so far, seems the mesh is my only component left

zenith wyvern
#

It is "pure" ecs at runtime. The point is to leverage the existing editor tools at edit time.

#

At runtime you would only be dealing with entities

night venture
#

I'm a total newbie, but for me something like Resources.Load() or Assets.Load would have made sense instead

zenith wyvern
#

And no, it isn't temporaey as far as I know

#

It's the expected way to make dots games

night venture
night venture
#

@zenith wyvern seems this is what i was looking for: Resources.GetBuiltinResource<Mesh>("Cube.fbx"); Going to test...

stone osprey
#

Is there a way to check if an Entity is still "alive" ?

#

Like when you store the entity struct somewhere and you wanna check later on if you can still "use" that entity ?

north bay
#

EntityManager.Exists

stone osprey
#

Ah great, thanks ^^

night venture
#

ok...so my entities are being created but aren't visible.

turbid sundial
#

This utility adds all the necessary classes to hybrid rendered entities

night venture
#

@turbid sundial hello STAN. let me review that. stop moving your arms. im not going to buy you anything

#

do you have a working example by hand?

stone osprey
#

When does an entity query update ? Im currently having the issue that i "1. Create an entity, 2. Search that entity ( Same frame )" and it doesnt show up...

night venture
#

@stone osprey a scope issue perhaps?

stone osprey
#

I dont think its a scope issue... because i create that entity by the entitymanager and it wont vanish once out of scope

night venture
#

in which method do you create the entity? is the entity object at class-level or method level?

stone osprey
#

EntityManager.CreateEntity();

night venture
#

that returns an object

stone osprey
#

What ? ^^

night venture
#

which u have to store somewhere

stone osprey
#

Uhmm... i dont think so, because the ecs itself stores the entities

#

The struct is just an identifier

#

Like an id

night venture
#

...im not sure about what you say...but my entities doesn't dissapear xD

#

let me explain myself:

stone osprey
#

It doesnt dissappear...

var entity = manager.CreateEntity();
// Run query to get all entities
// its not there ?!

Thats what is happening...

#

So the query doesnt find it... YET... so im not sure if i need to wait one frame

#

or if it normally should update instant

night venture
#

try Entity e = manager.CreateEntity();

#

and, even more...

#

Entity e at top, at class level

stone osprey
#

?

#

Thats what im already doing ? I dont know what you are trying to tell me ๐Ÿ˜„

night venture
#

let me write what works for me so far...

stone osprey
#

I just have the problem that my query does not update instantly... and i just wanna know if thats normal or not

#

Oh i found my problem... i was still using an entity command buffer... thats why it took one frame for the query to update

night venture
#

then, my code is useless xD

light mason
#

Can I use dots for Vr

#

Seems like XR is all go

odd ridge
#

yes

gusty comet
#

learning dots rn

#

ive faced fps drop after instantiating ton of planets

#

will dots help

stone osprey
#

BTW is it possible to render a mesh with multiple materials in the hybrid renderer ?

gusty comet
#

materials increase setpass calls

stone osprey
#

So is it possible or not ? ^^

#

Btw... are there any docs on how exactly the hybrid renderer works ? I would assume it offers such a good performance because it "instances" all its drawn meshes. Like opengl does with "DrawMeshInstanced". Is this right ?

karmic pilot
#

internally it still uses the srp batcher and URP, but as it has way better data layout. Gathering the data needed to send to the gpu each frame takes considerably less time. It is not a completely new rendering pipeline

stone osprey
#

@karmic pilot Thanks ! So it basically loops over all entities with a renderer each frame, gathers its data ( Transform, Rotation, Material, Shader ) and sends them to the GPU by either Opengl,Vulkan,DirectX and draws them instanced ? I just wonder how they exactly do that... because i saw examples of the hybrid renderer with 500K entities being drawn with nearly 60 fps... but in some pure c/c++ opengl examples 200K instanced objects are already lagging. So they are somehow more performant then pure opengl which makes me wonder why

gusty comet
#

did entity packages

#

dissapear from package manager

#

ew

karmic pilot
#

comparing hybrid renderer to opengl is like comparing apples to stones ๐Ÿ™‚ the hybrid renderer cannot accelerate the underlying rendering backend (vulkan/dx/opengl), it can only improve the effort needed to prepare the data for them (render data + commands).

stone osprey
#

@karmic pilot Hmmm... but how its possible that its faster than a pure opengl instanced renderer ? :/ I read somewhere that it only sends the "changes" to the gpu. But as far as i know opengl/directX force you to send everything everyframe

karmic pilot
#

a hybrid renderer with opengl backend faster than a pure opengl optimized solution?

stone osprey
#

Isnt this the case ? Atleast i recently saw an dots example where someone drew about 500k entities. But the official opengl "instanced" renderer with those asteroids is only able to draw about 200-300k. Everything higher lags

karmic pilot
#

no idea which comparison you saw, but in general the hybrid renderer can improve performance by quite a bit compared to the old fashioned game object rendering due to more efficient queries on the data. It always depends on what your bottleneck is ... memory access, cpu computation, gpu bandwith, gpu computation... the hybrid renderer is no silver bullet

#

where it really fails horribly for example is using unique meshes... if you have 100k unique meshes, the hybrid renderer won't be able to save you (might even be far before that)

stone osprey
#

Alright, thanks ! Well thats understandable ^^ Its just possible to instance entities with the same mesh and material... and shader... Everything else is one more drawcall.

amber flicker
#

Has anyone here got a non-trivial dots project that when processing a low number of entities doesn't end up taking e.g. 1ms just to schedule jobs? I'm finding that I just can't get my main thread time down. The cost of scheduling (not doing work) is more than doing the same work in a traditional way on e.g. 500 gameobjects. I have to be running over more than 1000 entities before it's worthwhile. So far from performance by default. (I have many jobs and many components, this is all in a build, burst enabled even some ISystemBases where I can, reduced sync points, mostly unmanaged etc).

karmic pilot
#

if you have a small amount of entities, just .Run() on the mainthread

#

scheduling has an overhead that is only negligible if you are working on a lot of entities across multiple jobs

amber flicker
#

Not an option as it has to scale to a larger number of entities. I do swap to .Run() dynamically based on number of chunks where I can but it still doesn't help that much.

karmic pilot
#

are you jobs depending on results of previous jobs in the same frame ?

gusty comet
#

ehh tutorial stopped at this

    Entities.ForEach()
```![Adam](https://cdn.discordapp.com/emojis/502892114313740308.webp?size=128 "Adam")
amber flicker
karmic pilot
#

does this necessarily have to happen in the same frame in order to work ?

#

since I don't know what you are doing, all I can do is randomly guess what might be the issue ๐Ÿ™‚

amber flicker
#

yea - it's a tween library so it all has to be frame accurate sadly

karmic pilot
#

in general jobs for a small amount of entities has a larger scheduling overhead than the actual execution on the main thread, since as you saw you have to check for dependencies, it has to be wrapped into a job to be executed somewhere and then it has to be scheduled... this is a lot more work than a simple iteration on a handful of entities that might even fit into a single cache line alltogether

amber flicker
#

yes... what I didn't appreciate is how badly this scales for any non-trivial project.

karmic pilot
#

they are working on that ๐Ÿ™‚

amber flicker
#

I also thought that burstable ISystemBases were supposed to improve things

#

but they don't unfortunately.. not yet anyway

#

do you know if that's because they haven't finished that or they're working on something else to help?

gusty comet
karmic pilot
#

I'll end by saying that the claim of performance by default in ECS / DoD only applies to many entities is not a correct assumption. DoD has a higher impact when you process more than one thing, but the expectation is that it is faster in all cases. If you have one thing, OO might be only a little bit slower while when you have many things it is a lot slower.

The current issues with low entity counts, are simply performance bugs that are in the process of being fixed.
this was at the end of 2019, no idea how much better it is since then .. haven't started using dots before mid 2020

amber flicker
#

yea.. I've been working on this for the past 2 1/2 years - waiting for this to be improved... as far as I've seen communicated, ISB's were supposed to be a large part of the answer

#

I'm at the point where I think I need to pause dev until they actually do something about it

#

but with no comms, I'm not sure if this is really something they think they can do more about

#

like you say, almost 2 years and very little improvement

karmic pilot
amber flicker
karmic pilot
#

and Timboc, did you profile with checks/debugger on or release built player?

amber flicker
karmic pilot
#

does burst work with il2cpp? never tried

amber flicker
#

yup ๐Ÿ‘

gusty comet
amber flicker
gusty comet
#

oh ok xD

stone osprey
#

@gusty comet If you have the same problem as i had ( Boxed structs... structs casted to objects ) and you wanna add/set them... i wrote an extension for that ๐Ÿ™‚

gusty comet
#

oh im not quite there yet anyway..

#

started learning yesterday

rancid geode
karmic pilot
#

thats why I said "in comparison" ๐Ÿ™‚

gusty comet
#

why I can use .Schedule when ref Translation

but I have to use .WithoutBurst().Run(); when using my own componentdata?

frosty siren
gusty comet
#

OH so it had to be struct LMAO thanks

#

yea i didnt like that WithoutBurst cus i assumed it would be slower

frosty siren
#

yes, every .Run() will produce sync point which leads to all jobs will be forced to complete

gusty comet
#

oh ok

#

but i kinda wonder

#

what if your meshes are generated dynamically in monobehaviour script ?

#

maybe having one object with mesh generator, and he would supply the mesh dynamically to all the entities? (so mostly different meshes, eg 5 entities per mesh)
would that work

frosty siren
gusty comet
#

the generation is done with monobehaviour, i just want to "pass" generated mesh to dots entities

#

you mean RenderMesh component?

frosty siren
gusty comet
#

yea but so far I know that i can access entities from entitymanager

#

and then i would also need to know which entity i need to access

half jay
#

I need to store NativeHashMap somewhere and get access in systems. What may be better create static class and store NativeHashMap in it or it can be store in component like blob asset? Also this collection should be updated and use in system with burst parallel jobs.

frosty siren
#

you can store it in another system

cerulean forge
#

How do you guys handle events with ECS? E.g. a mob has died and you need to react to that (run death animation, remove some components from the entity, drop loot, ...).

frosty siren
# cerulean forge How do you guys handle events with ECS? E.g. a mob has died and you need to reac...

i see few variants

  • Add to your entity some component and have a system that will react on it. Like DiedTag in your example. But every combination of components is one archetype and also archetype changing leads to memory copy.
  • Create some event entity that will have components of "what happend" and "with what entity". And have a system that will react to this entity through link. But it's not really ecs, because you will need to access components not through query and not linearly
  • Other clever approaches which i don't know about. Maybe you can search on forum. I saw some projects for dots event system.
cerulean forge
#

Yea that's pretty much what I've been reading on the forums

#

Was hoping there'd be a better way ๐Ÿ™‚

sturdy rune
#

@stone osprey did you ever figure out your serialized/deserialize?

gusty comet
#

is it useless when theyre not the same?

sturdy rune
#

He is talking about the shared component specifically creating a new chunk for every unique value

frosty siren
stone osprey
#

@sturdy rune Yes kinda ^^ I actually just added a little feature to my deserializer. I call them events. And it kinda works like this, a deserializer receives a packet, deserializes it into a struct and passes it to the events. At this point we know the type and can use generics. If a event returns a certain value it wont box/return the deserialized struct. So i just hook in such a event, which basically enlists the deserialized struct into the ECB and now they arent generating anymore garbage. Which reduced the gc alloced memory from 20-40KB every few frames to about 1KB.

#

So there kinda like two branches for my deserializer. It either returns a list of objects... deserialized class/boxed structs... or it invokes its events to pass the deserialized structs straight to the ECB without returning and boxing them first

#

@iron jacinth WTF ?

gusty comet
#

with monobehaviors and coroutines i executed somewhat heavy code every 3 5 10 seconds, how would you achieve this in DOTS? since ONUPDATE executes every frame.

would it be OK to count time.deltatime and wait until it has passed eg 10 seconds? or thats slow

#

oh well theoretically I still can interact with entities via coroutine and entity manager

pliant pike
#

systems aren't that different to monobehaviours, they update every frame also

gusty comet
#

ah im still somewhat confused, but I guess its better to do 'occassional' stuff from monobehaviors, and stuff that executes every frame, from systembase OnUpdate

#

( theres no performance gain if something executes once per 5 seconds anyway)

pliant pike
#

I don't think you can use coroutines in Systems but you can do a simple timer which I doubt would be much performance difference than a coroutine

gusty comet
#

ah yeah i already made the timer, but the more i think of it the more i feel i need monobehaviours

#

i will still use dots for rendering, colliders and movement(as this is every frame), but other stuff from monobehaviours, by calling entity manager

pliant pike
#

yeah you can use both together just fine

gusty comet
#

btw, theres no fixed update for dots?

safe lintel
#

@gusty comet put systems into the fixedsimulationsystemgroup

night venture
#

not 100% ECS but here it goes:
I want my 2D board game to be static but large enough to consider using a file backend as the place to mark, for each [x,y] which tile components should I set.
For example: [3,0]is a sidewalk tile, while [4,0] it's a road tile...is this a BAD idea? would it be possible to write entity "components" within file to create them at runtime?
ie: .CreateArchetype(foreach_tile_types_defined_in_file)

gusty comet
#

what if Hybrid renderer v2 made my entities invisible?

turbid sundial
#

Hoping someone can give me some optimization ideas here, https://gist.github.com/jamieshepherd/d9b6a93c907e6fea5cd0744e82a7abbb
This is the biggest bottleneck in my procgen terrain at the moment, putting all of my verts etc. into the world. If the world is really small it's acceptable, but becomes noticeable at any real scale. How can I reduce this bottleneck as much as possible? It looks like the main reason I can't use ecb as parallel is because I need to pass the RenderMeshDescription a Material, can I skip this step somehow and apply this later?

https://i.imgur.com/kFg0zNZ.png
This is the current profiler snapshot, 33ms every time I need to generate new chunks

hollow sorrel
night venture
turbid sundial
#

It seems like I do have to use .WithStructuralChanges because of the material passed in, at least on removal I get Entities.ForEach Lambda expression captures a non-value type 'baseMaterial'. This is only allowed with .WithoutBurst() and .Run()

#

I mention that in the first message ^

#

I did read up a little on the new mesh data api, but it seemed from the outside like it was more useful for editing existing meshes than instantiation of new ones, but I could be wrong

night venture
#

in plain human, what is your code doing?

hollow sorrel
#

it's also for new ones
i'd separate out the instantiation of new meshes into bursted jobs using mesh data and that should be decent speedup (main thread just to start with), in future you could look into separating the instantiation asynchronously, start applying meshes in 1 frame off main thread, apply them to components the next frame(s) on main thread

turbid sundial
#

I'll read deeper! thanks for the tip

night venture
#

๐Ÿฅบ

hollow sorrel
#

@night venture seems it is getting pregenerated mesh data and creating new meshes with them

night venture
#

im not sure in interested on that approach, but FOV/LOD/distance could help a lot on this kind of things

#

i mean, dont render everything, but only "closer to you" things

#

but, i guess those are my 2 cents xD

night venture
#

ok...here it goes: i have a 2D array of entities. each entity has several components

#

how can I save it to json?

#

can I JsonUtility.ToJson(entityArray)?

ocean tundra
#

no

#

that wont work

#

you need to look at SerializationUtility

#

but it works from the World

night venture
#

...that means....?

ocean tundra
#

so you may need to copy/move the entities to a new world then save that

night venture
#

why?...

ocean tundra
#

as you will save the whole world

#

might not want that

night venture
#

oh....so move to a blank world to only save that, right?

ocean tundra
#

yea

#

the default is to save the entire world

night venture
#

it might work for a test, but ill need a blank world later probably

stone osprey
#

Hmmm... A item is an entity in my case, i want to list them in the players inventory. So basically each item has a icon, a list item/entry and a name. Therefore i have following structs... Item{ bool stackable, int amount, FixedString32 name }, Sprite{ short spriteInDatabaseID }, Mesh{ short meshInDatabaseID } Is this too detailed ? Does it make sense to split into three components, one for sprite and one for mesh ? I thought about reusing them ^^ What do you think ? Or should i just merge them all into the item struct ?

night venture
#

and...2 more questions, if u dont mind

stone osprey
#

@night venture You can also write an extension which returns you all structs/objects of an entity. Then you an write your own serializer

night venture
#

i dont know what is an "extension", but probably out of my league

stone osprey
#

@night venture Yeah kinda ^^ Or you could use an existing json serializer... But you first need to write an extension that returns you all components as objects or whatever.

night venture
#

the world moving seems cleaner

#

although tricky

stone osprey
#

@night venture Look into extension, they allow you to write your own methods for existing structs and classes... without extending them

night venture
#

!extension xD

#

may I ask anyway about the other thing @ocean tundra suggested?

#

if using the world serialization utility

#

2 things left....creating/moving to a new world

#

it doesn't sound so complex

ocean tundra
#

there are methods on the EntityManager for that

night venture
#

and...if my entites have multiple components, after saving them...will they be stored in json, in a human readable way, with all their components and so?

ocean tundra
#

h sorry its binary

night venture
#

i need a text format ๐Ÿ˜ฆ

#

the idea behind all this is to load my board/scenario from a file

stone osprey
#

Then a own serializer is your only way

night venture
#

each tile being a collection of components

stone osprey
#

@night venture No... i mean a custom serializer written by YOURSELF. You need to find a way to get all components of an entity as objects. Then you need to serialise them into json somehow.

stone osprey
#

It is...

#

Plenty of work

night venture
#

ok...i'll ask another way. reflection is there, but if i can avoid it....

stone osprey
#

You can avoid reflection.... but it will cost you development time

#

You actually need to write huge switch statements or develop some sort of plugin system for all possibly components n stuff

#

I would actually go with reflection if such serialisation operation do not happen during the game

ocean tundra
#

oh im working on that

#

a modding kit

#

will use code gen to create that switch statement

stone osprey
#

With json ? ^^

ocean tundra
#

yup

stone osprey
#

Oh that sounds great ๐Ÿ˜„

ocean tundra
#

its awhile away tho, focusing on my networking atm

#

but the code gen is really easy

night venture
#

as you sound quite skilled, let me ask:

consider the following scenario: a board is a set of tiles.
my board is stored on a json file similar to [0,0]={Component1, Component2}, [0,1]={Component1, Component3, Component4}....
is reflection the unique way to "create the board" in unity following that?

ocean tundra
#

highly recommend code gen for DOTs

night venture
ocean tundra
#

kinda

#

more of a general tip

#

๐Ÿ˜›

stone osprey
#

If hes a beginner he should probably avoid code gen ^^

ocean tundra
#

so many things in DOTS needs actual types, for speed

#

and writing massive switch statements sucks

stone osprey
#

Yep

night venture
#

what is code gen? link, please

ocean tundra
#

code generation

#

no real link

stone osprey
#

An alternative to massive switch statements is a plugin system... where you plugin your switch cases... way cleaner, but still sucks

night venture
#

reflection?

stone osprey
#

No code gen

#

xD

#

You tell the compiler what to generate

ocean tundra
#

so i write a system but with {{TEMPLATE}} stuff inside

night venture
#

templating

ocean tundra
#

then from a scriptable object i call scriban and write out a cs file

night venture
#

i dont think that's the way....

ocean tundra
#

the scriptable object is to pass in Unity values if i need it

night venture
#

there might be something simpler

ocean tundra
#

yea probably

stone osprey
#

Then use reflection

night venture
#

reflection, in fact, is simpler

stone osprey
#

is easy

ocean tundra
#

write the switch statment manually

stone osprey
#

but generates garbage

#

but that doesnt matter if you dont serialise every frame

night venture
#

we all know im not going to switch xD

stone osprey
#

Oh

#

The problem with reflection is

#

You cant use it on entities

#

๐Ÿ™‚

ocean tundra
#

but if you have a game not a tool kit

#

the things your adding/remoing from save/load is quite low

night venture
#

in my case, by now, only once in game history

#

as im loading the board xD

stone osprey
#

Then go with reflection

#

But...

#

You cant use it directly on entities

night venture
#

i wont use it on entities, but creating entities with those components and data...why it wouldn't work?

stone osprey
#

Because... you need to either use Object components... or still write manual switch cases

#

Theres no "SetComponent(entity, object)" method yet for boxed structs

ocean tundra
#

trust him on this

#

๐Ÿ˜›

night venture
#

no, but i have a manager and i can manager.AddComponentData(entity, component_name_from_file), isnt it?

stone osprey
#

@ocean tundra Yep... trust US, because WE wrote one ๐Ÿ˜„ well i wrote it, but the others helped debugging and saved my ass

#

@night venture Nope

#

Thats not working

#

How should it ? It cant read your json file :p

#

Furthermore the generics are missing

#

You NEED them

night venture
#

i read the file, got the name, cast to class/struct using reflection, and then use it there

stone osprey
#

Hehe

#

good luck

ocean tundra
#

yea sorry that wont work

stone osprey
#

Class is working, struct not

ocean tundra
#

so

#

you will have your struct loaded from file, thats fine
BUT you will have it BOXED into a Interface or Object

stone osprey
#

^ Exactly... it actually makes me "happy" that im not the only one with that problem ๐Ÿ˜„

ocean tundra
#

yea i think lots of people have the same issue

#

ive ran into it a few times

stone osprey
#

But... we have a working solution ^^

ocean tundra
#

but having fought it as hard as you did

stone osprey
#

Not the best... but it works...

ocean tundra
#

went code gen instead

stone osprey
#

@night venture Im no asshole... i had the same problem. My deserialiser returned boxed structs... so i wrote this here with a LOT of help from several other people in here ( Thanks again ) !

https://pastebin.com/siRZcDBi ( You need to use ASMRefs from unity to get acess to the internals of the ECS )

#

The code above provides methods for EntityManager and ECB to add boxed structs to entities

ocean tundra
#

oh nice

night venture
#

ok...what about putting struct inside of class?

#

wouldn't that do the trick?

ocean tundra
#

you lose out on all dots goodness doing that

stone osprey
#

^

ocean tundra
#

class components cant have Burst

#

or be used in Jobs

night venture
#

but im not using them...i just using them to reference struct

#

(altough i cant probably serialize a static)

ocean tundra
#

so how would you add them to a entity?

night venture
#

Myclass.struct

stone osprey
#

...

#

I dont think that this works

#

You still need to use generics in that case

#

Or just use the class... but then, as roycon said, you will lose the advantage of the ecs

ocean tundra
#

i feel like the class thing could work

night venture
#

i wont use the class

ocean tundra
#

but its not too different from the switch

#

you will need to pass the EntityManger into the class

#

and it Adds the component

night venture
#

but the StaticClass.struct

ocean tundra
#

BUT you will need 1 class per struct

night venture
#

yes

#

1 class per component, in fact

ocean tundra
#

so proberbly even more code then the switch

night venture
#

no...just adding a few lines on each component...

#

anyway, im sure u already tested everything and tried all the paths

ocean tundra
#

the switch is like 3 lines per stuct

night venture
#

so at the end, ill have to go code gen

ocean tundra
#

pretty sure a class is at least 3 lines + the method to add component ect

#

depened

night venture
#

whatever, it will be tomorrow xD

stone osprey
#

@night venture Or to use the fancy extensions i posted above... wuuu

ocean tundra
#

if your changing the serialization loads then hyes

night venture
#

@stone osprey already saved to my desktop xD

ocean tundra
#

but honestly once your file format is set, and your components written, how often will you actually be changing it?

night venture
#

i need it in json at least once...

#

remember the objective: define the board in a file

#

at the end, ill define the board in the editor, using background image as reference

#

and save the world

#

but i dont want to surrender so soon!

#

i havent fought more than 2 hours

#

xD

stone osprey
#

Sooo... Sometimes i have the feeling that i design my components too atomic. A item is an entity in my case, i want to list them in the players inventory. So basically each item has a icon, a list item/entry and a name. Therefore i have following structs... Item{ bool stackable, int amount, FixedString32 name }, Sprite{ short spriteInDatabaseID }, Mesh{ short meshInDatabaseID } Is this too detailed ? Does it make sense to split into three components, one for sprite and one for mesh ? I thought about reusing them ^^ What do you think ? Or should i just merge them all into the item struct ? What do you guys think ? ^^

frosty siren
#

It's so much pain to try to use companions and SortingGroup component...

pliant pike
#

@stone osprey think about how you are going to use the data, like are you going to need to iterate through a single for maximum efficiency are you going to need to calculate some of it together

#

it doesn't really matter though you can easily change it later on as you figure things out and want to optimise

safe coral
#

Hey, how far from usable/stable is the new deterministic physics system? And, is there a more mature fixed point physics solution (doesn't have to be DOTS, actually probably better if it's not)?

hollow sorrel
#

@safe coral it's not multi-platform deterministic yet, should be same-platform deterministic, but even unity devs are giving mixed responses on the forums about that so prob need to run your own tests

#

unity physics devs: it is deterministic on same platform and we have tests to ensure this
unity burst devs: burst is not guaranteed deterministic even on same platform

safe coral
#

Okay, so completely useless to me

#

haha

#

I want cross-platform replays

#

Man, why are they working on a fixed point system if it's not cross-platform deterministic?

odd ridge
#

does DOTS have sprite sheet animations? If I have a sprite sheet animation object with a convert to entity script on it, will it run fast or still use the slow game object attached to an entity?

hollow sorrel
ocean tundra
#

@odd ridge No it dosnt

#

@safe coral Yea new physics its not deterministic

#

and buest is confirmed NOT deterministic right now

#

which is very confusing as it has previously been said it was

safe coral
#

Ah cool. Okay well that's disappointing. I was just thinking how great if would be if there was a generic number type in C# so you could parameterize the whole system (as you might in Rust for example)

ocean tundra
#

well someone has converted Physics to use Doubles

#

but its a ton of work

safe coral
#

Undoubtedly

#

Ah well, maybe I'l investigate a third party library or just drop this idea of cross-platform replays

ocean tundra
#

my networking library will have cross platform replays

#

nice side effect

#

what sort of game you building tho?

safe coral
#

Yeah, we use Photon Quantum for a multiplayer game, and it has its own FP physics engine.

#

But this game is single player, it's a "turn based bullet-hell roguelike"

#

https://rhys_vdw.itch.io/enter-the-chronosphere

#

Just scoping out options for how we might expand it

ocean tundra
#

yea probably too "twich" based unfortuanly

safe coral
#

for which?

ocean tundra
#

sorry my networking library is aimed mostly at RTS/Management type games, if the game is too fast passed it probably wont work well

safe coral
#

Ah, right.

#

All I need is 2D raycasts and collisions

ocean tundra
#

theres a ton of c# 2d physics library

safe coral
ocean tundra
#

could you grab one of those and implement that

safe coral
#

Still WIP, but it might be enough.

#

It's just a question of whether i want to rely on something that isn't under active development for a polish feature like replays

ocean tundra
#

are replays so important?

safe coral
#

Thanks for clarification though @ocean tundra, I appreciate your time.

#

No, they're not, but if there was a stable physics lib that gave them for free then I'd take them.

ocean tundra
#

ah yea makes sense

safe coral
#

It actually would be very cool to have replays

#

Because the game turns are real time, but the gameplay input is turn based

#

So you could get a very cool unseen real-time replay of the action

gusty comet
#

can your entities contain arrays of other entities?

heady vortex
#

To multithread navmeshquery, I need to pass all of the data from main thread into the job, and then the job will give me a position or some other good info to apply in the main thread, right?

#

and is my main thread supposed to wait for the job while the job does its calculations?

zenith wyvern
gusty comet
#

can I set entities to be child of other entities (and so their position and rotation would be updated)

or do I need to manually update their position and rotation, and theres no parenting?

ocean tundra
#

@gusty comet check the docs

#

There's a whole built in transform systems

#

And if you use the conversion flow you will get it all automatically

#

Definitely aim to use the conversion system, you can use prefabs and gameobjects for authoring

#

And unity have confirmed it's to be the recommended way to use DOTS

gusty comet
#

i have no need for prefabs i think

ocean tundra
#

You can use dots via pure code

#

But I don't really think it's worth it

#

I don't know if there's a helper method yet for code based transforms

#

But it's all listed in the docs

#

You need a specific combination of components to get it working

ocean tundra
minor cove
#

Hey guys, I want to do a project and utilize a little bit of ECS (and probably dots physics).

Can I access dots in the long term support Unity client or do I sadly have to download the beta instead?

slim nebula
#

you mean 2020.2?

#

2020.2 has dots in it yup

#

well supports dots packages

minor cove
#

@slim nebula thank you so much

#

yea my net is pretty slow; i was just worried i'm gonna waste time downloading a client that won't work

karmic pilot
#

has anyone tried to use the serialization package low level API in jobs to deserialize a lot of strings containing json ?

verbal pewter
#

How viable is a pure DOTS approach for procedural mesh generation right now? I remember people talking about it about a year ago and saying that there are more performant ways to go about it. Is that still the case?

zenith wyvern
night venture
#

it makes sense to have component composition? (a component which causes entity to inherit/have 2 components)
eg: component cat, implies component animal, implies component livebeing ?

verbal pewter
stone osprey
#

@night venture You would normally do something like this : "Entity{ Cat, animal, livebeing}" each of them is its own component. But there many solutions... You can also have something like : "Entity{ Livebeing, Animal{ type:cat}"

#

It depends on what you want and how detailed ^^

#

Theres no right and false

#

As far as i know thats what archetypes are for... There no automatic including for other components yet... I think

night venture
#

ok. no component composition xD

#

btw @stone osprey do you remember i was struggling how to get the components of an entity and so? i achieved that (the easy part)

zenith wyvern
#

What you were describing wasn't composition, it was inheritence

night venture
#

@zenith wyvern not really, cause im not inheriting anything, but "adding a few subcomponents" whe adding one

#

anyway, ill add each one individually by now

#

going back to my try to serialize entities adventure...

zenith wyvern
#

eg: component cat, implies component animal, implies component livebeing ? You're describing an inheritance tree

#

Components are completely self contained from one another, their relationship is only described by the systems that operate on them

night venture
#

can i serialize NativeArray<ComponentType> ?

safe lintel
night venture
#

@safe lintel probably true...but i want to do it just once! xD

#

do you have a test working code to de/serialize NativeArray?

#

and...where's "Unity Bugs.zip" ?

safe lintel
#

Roycon might know more, he gave me loads of helpful ideas on serialization ๐Ÿ™‚

night venture
#

that's using SerializeUtilityHybrid, which might be similar to SerializeUtility. both save the world

#

furthermore, i only want to deserialize xD

turbid sundial
#

@zenith wyvern I saw in your blockworld repo that you end up creating gameobjects for each chunk - did you try doing this with hybrid renderer? How come you went in that direction?

gusty comet
#

how do you do

#

transform direction in dots

zenith wyvern
# turbid sundial <@!155490373123178497> I saw in your blockworld repo that you end up creating ga...

Originally gameobject rendering was significantly faster than hybrid renderer for any kind of dynamic mesh, just due to the overhead of ECS managing the RenderMesh shared components for each unique mesh. When I profiled it recently hybrid renderer was at least on par with gameobjects for rendering large numbers of dynamic meshes. In my "version 2" branch I did try it with the hybrid renderer and it worked well. Was much simpler and didn't perform any worse than the gameobjects from what I could tell

turbid sundial
#

I'm hitting a similar bottleneck to one you mentioned around the actual instantiation - using hybrid renderer - mainly because of the main thread

#

I almost want to be able to spread instantiation over frames (e.g. like the way coroutines work) because it's not immediately necessary

gusty comet
#

oh the rotation is quaterninon

#

i need vector3 hm

zenith wyvern
#

Greedy meshing or whatever it's called

turbid sundial
#

Yeah I was looking into that as well

zenith wyvern
#

The less data you have to upload the faster it will be

turbid sundial
#

Can you actually spread over frames in ECS?

zenith wyvern
#

Not in any fancy built in way like a coroutine, but you can track when your jobs are completed (jobHandle.IsComplete) and only upload so many meshes within one frame

#

It's a lot of work to build a framework to track all that but it's certainly possible

turbid sundial
#

Got it- thanks for your thoughts ๐Ÿ™‚

sturdy rune
#

wouldn't rejecting meshes not in view and etc also help wit that?

#

pre-culling rejection, might reduce number of meshes you actually are loading

#

but I am definitely a newb at this point, just learning megacity optimization

gusty comet
#

do you guys mainly use entity authoring

#

or pure ecs

karmic basin
#

the first one

#

latter one would be mainly for learning purposes

sturdy rune
#

pure ECS is also pretty painfult og et started

#

as a fellow beginner, I learned some pure ecs, took a course, and then finished by reading through ECS documentation which enforces that authoring is the direction unity will go. tiny will be pure ecs

north bay
#

I think a lot of people are mixing pure dots up with the authoring workflow.
Even tiny uses gameObject based authoring and conversion.

The only time I saw unity mention the term pure dots was when referring to a project that doesn't make use of any systems outside the DOTS ecosystem.

gusty comet
#

oh i see yeah i heard the same, that authoring is the way to go

turbid sundial
#

@zenith wyvern have you looked into the new mesh api? Wondering if there's any gains to be made there ๐Ÿค”

zenith wyvern
turbid sundial
#

That's interesting

zenith wyvern
#

I've found it easier to just stick with keeping your data as Native Arrays and uploading via the MeshData APIs which is an okay middle ground

sharp flax
#

So I was testing some performance stuff I was curious about with jobs, but found something unrelated to what I was looking, that I recall to have seen before in this channel, is it normal that the **overall ** time that a job takes to complete can be like x4 times higher when doing it in parallel than running it in a single thread?

zenith wyvern
turbid sundial
#

Cool, thanks

#

@sharp flax there is some overhead to jobs - so it depends on the size of the work and number of jobs you have to iterate through to decide whether or not it's worth jobifying

karmic basin
#

But yeah also remember a forum thread where the additionnal cost of multithread was insanely unexpected

sharp flax
#

Not doing entities stuff, just isolated jobs testing. I just watched a talk from Scott Meyers talking about cache memory that was recommended by one of the Unity blogs somewhere and started to wonder "what would happen if...". Still don't know much about the most low lvl stuff but this has been revealing. I always knew that processing a few items wasn't worth to parallelize, but didn't expect such difference

#

It's not few elements either, like 250k but just adding numbers

olive kite
#

is anyone else getting "A Hybrid Renderer V2 batch is using a pass from the shader "HDRP/Lit", which is not SRP batcher compatible. Only SRP batcher compatible passes are supported with the Hybrid Renderer."

gusty comet
#

ArgumentException: GetComponent requires that the requested component 'PlanetData' derives from MonoBehaviour or Component or is an interface.

#
PlanetData planetData = GetComponent<PlanetData>();
#

how do you kinda refer to the authred IDataComponent via code

ocean tundra
#

@gusty comet you cant

#

the way its code generated makes it impossible to reference

#

make it manually instead

night venture
#

hey @ocean tundra do you have 5 minutes?

ocean tundra
#

probably ๐Ÿ˜›

night venture
#

achieved to find NativeArray<ComponentType> types = manager.GetComponentTypes(tiles[i, j], Allocator.Temp);, so I can iterate trough components each tile has

#

can NativeArray<T> be serialized?

ocean tundra
#

hmm you could always loop it and manually write it

gusty comet
ocean tundra
#

but ive never tried any serialization librarys on native collections

gusty comet
#

i know i can do it in OnStart() but i wanted to do it in editor

night venture
ocean tundra
#

@gusty comet rephrase what your trying to do and answer the following:
How are you converting your GOs? SubScenes? ConvertToEntity?
Why are you trying to access the Authoring Component?
and WHERE are you trying to do that? (System? Monobehaviour?)

#

@night venture Same but in reverse,
You could use the File API and manually construct the struct and then add to a native list
But that seams like a bit of a pain
I would gather your types, and convert into a managed List<T>, serialise/serialise that

gusty comet
ocean tundra
#

i see so in editor nice

gusty comet
#

yes but not manually(by hands) it must be via code

ocean tundra
#

yea so first you will need to manually make the authoring class, then you can either use a custom inspector or custom window using the normal editor tooling

#

you cannot access any entity stuff from that

#

as at that point its all still authoring

#

which is Monobehaviour

night venture
ocean tundra
#

yea that would be the easyiest

#

you can probably use Unitys built in Json stuff

night venture
#

jsonutility seem to suck (even more for 2d arrays)

ocean tundra
#

is it the same IComponent or a bunch of different ones?

#

yea it does suck ๐Ÿ˜›

gusty comet
#

how can custom inspector achieve it?

night venture
#

i have spent a few hours trying to do it

night venture
ocean tundra
#

@gusty comet Custom inspector can be written to support multi editing, so you can have that enabled, and a button which does your code/data set

gusty comet
#

i need to set data from monobehaviour tho

ocean tundra
#

@night venture oh thats harder, i would build a "Model" class, a root class containing all your lists/components, avoiding the serialization of Interfaces

#

@gusty comet inspectors operate on MonoBehaviours?

#

and you can still select a specific MB to edit it

gusty comet
#

you can do multi editing manually anyway

#

in current inspector

#

afaik

night venture
#

@ocean tundra look what I got so far:

Debug.Log("L1:");
List<IComponentData> l = new List<IComponentData>();
l.Add(new Tile());
l.Add(new DriveLeftToRightComponent());
foreach (IComponentData c in l) {
    Debug.Log(c.ToString());
}
Debug.Log("L2: " + JsonUtility.ToJson(l));

//otuputs
L1:
Tile
DriveLeftToRightComponent
L2: { }

but I was expecting something like { "Tile", "DriveLeftToRightComponent" }

ocean tundra
#

your expected output wont be valid

#

more like

#

[{Tile: {TILEDATA}, {DriveLeftToRightComponent: {DATA}}]

#

but also unitys json sucks

#

so i dont think it will work with interfaces

night venture
ocean tundra
#

it will DEFINITLY have no clue how to deserialize types

#

yea

#

theres a package somewhere for it

#

and make sure you configure typed serialization

night venture
#

no clue what you talking about...but let me ask, before goind down the rabbit hole

ocean tundra
#

or build the model class and have lists of concrete types

#

๐Ÿ˜›

night venture
#

does it make sense what im trying to do? each tile is a set of components, i want to edit a json with tile[x,y]={types} and to load it at runtime to create the map/board

ocean tundra
#

maybe...

#

๐Ÿ˜›

#

depends on your requirments

#

i want mods so im building simlar tools

night venture
#

i just want to edit a json for the map...

ocean tundra
#

but you could use SerializeUtility and have a map editor in game

night venture
#

saving "world"

#

in binary format

ocean tundra
#

the advantage of a text format is its super easy for anyone to edit

#

binary format (that world serialize utilily) is much faster and probably easier to code

#

BUT you would need tooling in game to make the map

#

oh and text format you dont need to build the map tooling

night venture
#

can i use SerializeUtility to get a text format?

ocean tundra
#

no

#

from what i can tell its a exact memory extract of the whole world

night venture
#

so, to sum up:
json.net to make json<->code conversion easier/better

#

and somehow, perhaps using json.net the serialization of nativelist would even work

ocean tundra
#

im not sure about native collections

#

maybe...

night venture
#

well...at least native->list->json would work xD

ocean tundra
#

yupp

night venture
#

the guy responsible for json in unity...is the boss son?

ocean tundra
#

so json.net is just so you can deserialize child types of IComponent

#

what??

night venture
#

i mean...unity json sucks...

ocean tundra
#

yea

#

hence the json package

#

@night venture WAIT

#

your going to have issues

#

the deserialized data will be Boxed

#

you wont be able to add it to a entity

night venture
#

...

#

i just installed the asset, alt+tab and booom! your message

ocean tundra
#

๐Ÿ˜›

#

sorry

#

the boxing thing is super annoying and easy to forget

#

you can still get it to work

#

just more round about

night venture
#

please, please, please....tell me I'll be able to do it

#

xD

ocean tundra
#

some example Code:

IComponent test = new Translation(){SET POS}

#

so that is Boxing translation into IComponentData

#

when you try to use EntityManager.AddComponentData it wont let you

night venture
#

interfacing'

#

cause i need an specific type, isnt it?

ocean tundra
#

yup

night venture
#

so...?

#

reflection to get typeof?รง

ocean tundra
#

OR you reverse the EntityMangaer dependancy

#

na reflection dont help

night venture
#

add(manager, icomponent) ?

ocean tundra
#

yea

#

make a interface all your serializable components use

#

that has a method like that

#

use that interface instead of IComponentData

#

sorry it will be Add(EntityManager)

night venture
#

you mean...struct a: Myinterface and IMyInterface : IComponentData?

ocean tundra
#

i wouldnt have your IMyInterface a child of ICOmponentData

#

but otherwise yes

night venture
ocean tundra
#

yea sturcts can

night venture
#

let me draft...

ocean tundra
#

just personal preference

night venture
#

seems json.net broke the project...ยฌยฌ

ocean tundra
#

how did you add it?

#

you need to use Unitys package

night venture
#

used asset store...

#

Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included or the current platform. Only one assembly with the same name is allowed per platform. (C:/unity/Library/PackageCache/com.unity.nuget.newtonsoft-json@2.0.0-preview/Runtime/Newtonsoft.Json.dll)

ocean tundra
#

yea dont think that will work

#

sounds like you already have unitys package

night venture
#

new project?

ocean tundra
#

it may be a dependancy of Entities somewhere

night venture
#

its a dependency, but i cant undo the mess

ocean tundra
#

?? just delete the folder json.net came in

night venture
#

nah...creating a fresh project xD

night venture
#

@ocean tundra fresh 2d project created xD

did u mean this?

using Unity.Entities;

[GenerateAuthoringComponent]
public struct Tile : ISerializableComponent {
    public void addComponent(EntityManager manager, Entity e) {
        manager.AddComponentData<IComponentData>(e, new Tile() { });
    }
}
ocean tundra
#

almost

#

manager.AddComponentData(e, this);

#

and entity manager might have to be passed via ref

#

not sure

night venture
#

ok...and that to make json work and store properly...right? xD

ocean tundra
#

maybe

#

test it

#

make a Tile and box it into the interface

#

then call addcomponent

#

it should work

#

๐Ÿ˜›

night venture
#

current json+namehandling:

{
  "$type": "System.Collections.Generic.List`1[[ISerializableComponent, Assembly-CSharp]], mscorlib",
  "$values": [
    {
      "$type": "Tile, Assembly-CSharp"
    }
  ]
}
#

lets see how it handles reading it back

ocean tundra
#

oh no i meant

#
test.AddComponent....```
warm panther
#

Question:
What causes a converted Entity to get:

  • a Scale component
  • a Rotation component
    < versus >
  • a CompositeScale component
  • a CompositeRotation component?

And can I prevent them from getting either?

ocean tundra
#

i didnt know there was a composite rotation

night venture
#

there is

ocean tundra
#

somewhere in the transform conversion systems i guess

warm panther
#

Yeah and I noticed that some of my entities have one or the other.

night venture
#

@warm panther if you are converting gameobjects, instead of creating them

#

the object has a few components "by default"

warm panther
#

Seems like the root parent" entities have composite... SOMETIMES.

#

I want to know why they have one or the other.

night venture
#

depends of the object type

warm panther
#

Such as?

night venture
#

cube->traslation+rotation

#

rendermesh, renderbounds

#

...

#

so i suggest, instead of converting, knowing what you are doing "manually", to better understand

#

eg:

#
manager.AddComponentData(myEntity, new Translation {
    Value = new float3(i, 0f, j)
});
manager.AddComponentData(myEntity, new Rotation {
    Value = quaternion.identity
});
Material material = new Material(Shader.Find("Standard"));
material.color = Color.white;
manager.AddSharedComponentData(myEntity, new RenderMesh {
    mesh = mesh,
    material = material
});
warm panther
#

But how do I do that in a IConvertToEntity?

night venture
#

im not converting...you can ask for each object components

warm panther
#

I really need visual editing so I want to base it off of a gameobject, but some of the intrinsic things it does are weird. I mean I could author as plain prefabs and then convert in my own conversion system.

#

but that feels like a huge drag at this stage of the project.

night venture
#

how does that affect you?

ocean tundra
#

whats the issue with the composite ** types?

night venture
#

you want to select/filter only some of the entities? both?

warm panther
#

The objects have multiple hierarchies and hierarchies of authoring components.

warm panther
ocean tundra
#

ohhh i see

#

advanced usage ๐Ÿ˜›

warm panther
#

This is my port of Unity's originalc ode.

#

And I want to clean it up. It could also be made branchless.

#

And because my system is rather specific, I would like to only deal with objects that I want to deal with, meaning - if I know what components they have, I can get rid of most of the branching even before it needs to be calculated.

night venture
#

sorry. out of my league :S

warm panther
#

(but it could also be written branchless, and I wonder why they didn't do that - they have a todo in the code waiting for Function Pointers in Burst)

#

I noticed that some of my objects weren't being transformed as expected, and that's because they have unexpected scale and rotation components on them. ๐Ÿ™‚

ocean tundra
#

i would just leave it as unitys code for now

#

they will come back to it at some point

#

and if you need the optmization later you can either copy theirs or write your own depending on if they are done

warm panther
#

Yeah, right now the optimization is complexity.

night venture
#

@ocean tundra so...tiles was an entity[,]...i was able to iterate trough it and, for each tile get their components
IIRC, the idea was to add them to a List<Component> and then serialize as json. wasnt it?

#

after that, i should have a file containing aproximately

{
  "$type": "System.Collections.Generic.List`1[[ISerializableComponent, Assembly-CSharp]], mscorlib",
  "$values": [
    {
      "$type": "Tile, Assembly-CSharp"
    }
  ]
}
ocean tundra
#

yea

night venture
#

manager.GetComponentTypes returns NativeArray<ComponentType>...how to cast to List<ISerializableComponent> ?

ocean tundra
#

Component Type is not the components

#

is the definition of a componet

#

ummm think of it as reflection metadata

#

but not for reflection

night venture
#

...lost

#

xd

ocean tundra
#

im not really sure how getComponentTypes will help with serialization

#

i guess you could take the compoennt type and build a entity query...

night venture
#

u mean to loop by myself

ocean tundra
#

but then you need generics to get the ToComponentDataArray....

#

i dont think you can...

night venture
#

...all that time....? xD

ocean tundra
#

the api is really not setup for untyped access

night venture
#

so...going back to basics...

#

json file describing tile [x,y]={list of components}

#

i want to read it and setup entities with those components

ocean tundra
#

yea all the entityquery ToComponentArray methods are generic sorry

#

you can just make the entity querys yourself

#

like for your inital file creation couldnt you just manually write it?

night venture
#

...no...xD

ocean tundra
#

deserialization should be fine

#

?? how many compoents do you have?

night venture
#

deserialization is the only thing i need

#

xD

ocean tundra
#

i guess just manually write the json file then

night venture
#

but how?...i mean

ocean tundra
#

or you could write some 1 off code to generate one

#

?? just use Visual studio and edit it

night venture
#

...dont know what "strings" have to write in order to deserialization understands what it has to do.

ocean tundra
#

so easist way is to write some code to manully save

night venture
#

json file describing tile [x,y]={list of components}
i want to read it and setup entities with those components

ocean tundra
#

which is one off

#

yea so you want a List of a model class (Tile)

X;
Y;
List<serilzedComponent> components
}```
#

then use 2 for loops for X and for Y to create your inital grid (5 by 5?)

#

and add them all into the list

#

then serialze that

night venture
#

i cant loop through entity[,] ?

ocean tundra
#

boom you will have a nice 'template' json

#

if you serialzie a 2d array you will have to also serilze the width and height

#

im honestly not sure how json handles 2d arrays

night venture
#

?...sorry...im exhausted...

#

look, this is what i got when serializing 1 entity:

{
  "$type": "Unity.Entities.Entity, Unity.Entities",
  "Index": 42,
  "Version": 1
}
#

in other words, nothing

ocean tundra
#

yea no you cant serialzie a entity

#

sorry i think im missing what you want

#

end goal is a josn file defining your 'grid' of tiles?

night venture
#

yes, each tile being an entity

ocean tundra
#

ok and you dont want to manually write that file

night venture
#

entity being a set of components

#

i can write it manually, since the moment i have a pattern

#

but, as im using entities, i dont have one

#

using oop (not ECS) that could be fine

#

but i want to save "an entity"

#

(and in json format, not binary) ๐Ÿ˜›

ocean tundra
#

yea ignore dots/oop/data orientated. you just need to get saving/loading working

#

thats just adding complexity

night venture
#

ok...how i save an entity? xD

ocean tundra
#

ok so you have a inital grid?

night venture
#

atm, made by hand, set of entity[10,10]

ocean tundra
#

ok

#

so make a new system

#

and have some trigger (like input.getkeyup...

#

on that trigger

night venture
#

aham...

#

(i can invoke it ondestroy, its simpler)

ocean tundra
#

you want to have a entity query with all your CURRENT tile components in it

night venture
#

already

ocean tundra
#

then for every tile component you want to call ToComponentArray

#

you now have many arrays of your components

night venture
#

ok...hold a sec.

ocean tundra
#

next you need to loop x and y and construst a list of SerializedComponent

#

and grabbing out your tile compoents from those arrays and putting it into that new list

#

now your in memory data is close to your target json

#

and i 'think' you should be able to just feed that list into json.net and have your output

night venture
#

would Entities.WithAll<Tile> do the job?

ocean tundra
#

personally i would resturcture it so your not serializing a 2d array, instead a single long list of tile (which has X Y and component)

#

no

#

thats for Entities.Foreach

#

you need to be manually creating entity queries for this

#

GetEntityQuery()

#

but a single query with just Tile will probably work

night venture
#

but why foreach wont do the job?

ocean tundra
#

you could probably just use EntityManager.Has/Get component for all your other components

#

i guess you could... you will have to use run and without burst

#

its just it generates a ton of 'magic' behind the scenes, for this you dont really need any of it

#

yea sorry, this is one off code, we are not caring about performance
you dont need entity query or for each

#

just For X and Y of your entities[x,y] array

#

and use EntityManager.GetComponent or HasComponent

#

and built the 'per tile' output lists of serialziedcomponents

night venture
#

you mean manager.GetComponentData?

ocean tundra
#

sorry my default for dots is to try follow best pratcices and write for performance ๐Ÿ˜›

#

yea

#

and HasComponent if you have optional components (components only on some entities)

#

so sudo code:

night venture
#

you are running too fast for my asleep mind.

ocean tundra
#
for y //Loop over your entitys
entity = array[x,y]
maintilecomponent = EntityManager.GetComponentData<Tile>(entity)
AdditionalComponet1 = EntityManager.GetComponentData<AdditionalComponent1>(entity)

serizlaedtypesList = getListFor(x,y) //get the list for this entity/tile position

serizlaedtypesList.Add(maintilecomponent)
serizlaedtypesList.Add(AdditionalComponet1)

//a optional component
if (entityManager.HasCompoinent<Optional1>(entity)
serizlaedtypesList.Add( EntityManager.GetComponentData<Optional1>(entity))

#

sorry does that make more sense?

night venture
#

manager.GetComponentData is typed, hence it will return only one component. inst it?

ocean tundra
#

yea sorry, missed some generices

night venture
#

so the only way of getting all components would be manager.GetComponentTypes ?

ocean tundra
#

honestly forget about that

#

you dont need it

#

how many components do you currently have?

#

5? 10? 20?

night venture
#

some tiles 4, others 8

ocean tundra
#

exacly

#

just code the 8 manualy

night venture
#

depending on tile

#

no way man....

ocean tundra
#

why?

#

this is ONE OFF code

night venture
#

we have been dealing with this for a while...

ocean tundra
#

your only using it to generate your inital json file

night venture
#

oooh, ok

ocean tundra
#

after that you edit/copy your json file for everything

night venture
#

hold a sec

ocean tundra
#

your requirement was for deserialization (loading) more then serialalization (saving)

#

this will give you the inital template and patterns and then you use that instead of this

#

it may help to generate a few different sizes initially

minor sapphire
#

quick interjection: what is the appropriate job type for looping over elements in a list, e.g. NativeArray or hopefully NativeHashSet?

#

thought IJobForEach but it's obsolete now?

ocean tundra
#

i think that was for entities...

minor sapphire
#

Oh yes indeed

ocean tundra
#

IJobParallelFor

#

i think

night venture
#

damn

#

these components are tags

ocean tundra
#

so??

night venture
#

Get component data can not be called with a zero sized component.

ocean tundra
#

oh

#

of course

#

so

#

instead

#

for the tag components

#

use HasComponent

night venture
#

and just add a new Tile?

ocean tundra
#
for y //Loop over your entitys
entity = array[x,y]
maintilecomponent = EntityManager.GetComponentData<Tile>(entity)
AdditionalComponet1 = EntityManager.GetComponentData<AdditionalComponent1>(entity)

serizlaedtypesList = getListFor(x,y) //get the list for this entity/tile position

serizlaedtypesList.Add(maintilecomponent)
serizlaedtypesList.Add(AdditionalComponet1)

//a optional component
if (entityManager.HasCompoinent<Optional1>(entity)
serizlaedtypesList.Add( EntityManager.GetComponentData<Optional1>(entity))

//for tags
if (entityManager.HasCompoinent<Tag1>(entity)
serizlaedtypesList.Add( new Tag1())
#

heres some updated sudo code

#

๐Ÿ˜›

#

you should probably write at least 1 component that contains data

#

so you have it in your template

night venture
#

buf....seems it worked

#

what a crappy workaround

ocean tundra
#

all manual serialzation is terriable atm

#

unity are very strict about what they open on the entity manager, they DO NOT want us to have any methods that are 'slow'

night venture
#

ok...first thing i notice is it seem its not properly serialized

ocean tundra
#

lets see some code and json output?

night venture
#
List<ISerializableComponent> l = new List<ISerializableComponent>();
for (int i = 0; i < tiles.GetLength(0); i++) {
    for (int j = 0; j < tiles.GetLength(1); j++) {
        if (manager.HasComponent<Tile>(tiles[i, j])) {
            l.Add(new Tile());
        }
        if (manager.HasComponent<RoadComponent>(tiles[i, j])){
            l.Add(new RoadComponent());
        }
    }
}
Debug.Log(JsonConvert.SerializeObject(l, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }));

results in:

{
  "$type": "System.Collections.Generic.List`1[[ISerializableComponent, Assembly-CSharp]], mscorlib",
  "$values": [
    {
      "$type": "Tile, Assembly-CSharp"
    },
    {
      "$type": "Tile, Assembly-CSharp"
    },
    {
      "$type": "Tile, Assembly-CSharp"
    },
    ...
  ]
}
ocean tundra
#

yea ok

#

so yor first line List<ISerializableComponent> l = new List<ISerializableComponent>();
you need to make a new one of these PER tile

#

so its actually
List<ISerializableComponent>[,]

#

other then that looks right

#

you could probably play with TypeNameHandling setting

#

you may be able to remove the highest level one (the list) but keep all the others

#

another tip i would recommend is to have a containing model class instead of a direct list

#

thats mainly a webdev json rule

night venture
#

too many suggestions per paragraph xD

ocean tundra
#

but its helpfull if you want to add a 'top' level setting of some sort

night venture
#

ok, so looking at the json, seems its working

ocean tundra
#

yea you just need to break apart the serilzedtype list to be per tile instead of a single massive one

night venture
#

simplified using handling=objects:

[
  [
    [
      {
        "$type": "Tile, Assembly-CSharp"
      }
    ],
    [
      {
        "$type": "Tile, Assembly-CSharp"
      },
      {
        "$type": "RoadComponent, Assembly-CSharp"
      }
    ],
...
ocean tundra
#

nice

night venture
#

so....now to load this crap

#

tomorrow?

ocean tundra
#

๐Ÿ˜›

#

you should just be able to do the reverse

#

then you will need to loop x and y

#

and do the following steps:
1 EntityManager.CreateEntity()
2. Loop over every component
2a. call component.AddComponent(Entitymanager, newEntity)

night venture
#

hmmm...like this? :

string txt = JsonConvert.SerializeObject(l, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });

List<ISerializableComponent>[,] l2 =JsonConvert.DeserializeObject<List<ISerializableComponent>[,]>(txt, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });
for (int i = 0; i < l2.GetLength(0); i++) {
    for (int j = 0; j < l2.GetLength(1); j++) {
        tiles[i, j] = manager.CreateEntity(archetype);
        foreach (ISerializableComponent c in l2[i, j]) {
            c.addComponent(manager, tiles[i, j]);
        }
    }
}
ocean tundra
#

yea that looks right

night venture
#

today u deserved a beer, coke or whatever

ocean tundra
#

it works?

night venture
#

haven't tried yet, but looks promising

#

(and furthermore when undesrtanding what it does) ๐Ÿ˜›

ocean tundra
#

let me know how it works

#

also this is why im so into codegen ๐Ÿ˜›

night venture
#

it sucks half the problem is jsonutiliy...

#

building

ocean tundra
#

yup

night venture
#

ArgumentException: Unknown Type:Unity.Entities.IComponentData All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

ocean tundra
#

implement IComponentData directly on your structs?

night venture
#

probably at c.addComponent(manager, tiles2[i, j]);

ocean tundra
#

not via a parent interface

night venture
#

but then, how it know it has to implement addComponent?

ocean tundra
#

you can have 2 interfaces

#

well unlimited inerfaces as 'parents'

night venture
#

ok, i forgot xD

ocean tundra
#

and can you show me the code for your addComponent

night venture
#
using Unity.Entities;

[GenerateAuthoringComponent]
public struct Tile : ISerializableComponent, IComponentData {
    public void addComponent(EntityManager manager, Entity e) {
        manager.AddComponentData<IComponentData>(e, this);
    }
}
ocean tundra
#

yea thats wrong

night venture
#

xD

ocean tundra
#

manager.AddComponentData(e, this);

#

should work

#

but also this is a tag component...

#

you may have to use manager.AddComponent<Tile>(e) instead

#

but for non tags i think its right

night venture
#

....so....? xD

ocean tundra
#

so

#

try this first manager.AddComponentData(e, this);

#

if that dosnt work

#

then try this manager.AddComponent<Tile>(e);

night venture
#

on my way

ocean tundra
#

if that still dosnt work then no clue ๐Ÿ˜›

night venture
#

should ISerializableComponent implement IComponentData ?

ocean tundra
#

probably not

#

it shouldnt matter if your main struct inplements both

night venture
#

seems it works

ocean tundra
#

nice

night venture
#

211 entities on analyzer

#

100 per board+trash

ocean tundra
#

but 10 * 10 = 100

#

ok cool

#

๐Ÿ˜›

night venture
#

2am in the morning here...

ocean tundra
#

๐Ÿ˜›

#

good luck

#

im off to cook food

night venture
#

ok...a couple of things

#

first: THANKS

#

second: see u tomorrow xD

minor sapphire
#

entities 18 is taking its sweet time ey? ๐Ÿ˜„

#

curious what'll be in it

safe lintel
#

im hoping it brings a whole slew of updates to every other package too.

#

also want an easier to use dots audio package

#

and navigation

minor sapphire
#

I have been keeping away from dots audio so far

#

is it usable?

#

or should I keep away a while longer ๐Ÿ˜„

ocean tundra
#

@minor sapphire its very usable

#

but all the 'side' bits are missing

velvet oxide
#

is there an alternative to using .Equals on structs? I keep getting a Burst error saying my IBufferElementData does not contain IEquatable<object> even though I do have it implemented.

Burst error BC1002: Unable to find interface method `System.IEquatable`1<object>.Equals(!0)` from type `DotsPhysics.PhysicsHitBuffer`
ocean tundra
#

can you show the component code?

velvet oxide
#
public struct PhysicsHitBuffer : IBufferElementData, IEquatable<object>
    {
        public FixedString64 name;
        public PhysicsPositionData positionData;
        public PhysicsHitData hitData;
        public PhysicsDebugData debugData;
    }
ocean tundra
#

i wonder if .equals is doing some sort of boxing

#

oh of course

#

its to object

#

also shouldnt there be a equals method?

velvet oxide
#

I tried doing my own Equals as well and still got the burst error

ocean tundra
#

IEquatable<object> change object to the actual type

#

objects = class which wont work in burst

#

and im pretty sure you need to implement the interface

velvet oxide
#

lol thanks no idea why its workign now but it is. I swear i tried this before

#

thanks again @ocean tundra

ocean tundra
#

all good

velvet oxide
#

I must of had some other burst error junk before

minor sapphire
#

If I do

Dependency = Job1.Schecule(Dependency);
Dependency = Job2.Schecule(Dependency);

Will job2 always run after job1, or only if there is actually something in job1 that job2 reads/writes?

ocean tundra
#

yea job 2 will be after job1

minor sapphire
#

I'm trying to schedule these two to run at the same time

ocean tundra
#

yea ok

minor sapphire
#

but it keeps hating me when I try lol

ocean tundra
#
var initialDependency = Dependency;

var job1D = Job1.Schedule(initialDependency );
var job2D = Job2.Schedule(initialDependency );


Dependency = JobHandel.Combine(initialDependency , job1D , job2D );
minor sapphire
#
JobHandle handle1 = new Job1().Schedule(count1, Dependency);
JobHandle handle2 = new Job2().Schedule(count2, Dependency);

JobHandle.CombineDependencies(Dependency, handle1);
JobHandle.CombineDependencies(Dependency, handle2);
#

Ok so this produces error:

InvalidOperationException: The system System1 reads DynamicBuffer1 via System1.Job1 but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.
#

so I thought, I must do
Dependency = Job1.Schedule...

ocean tundra
#

no at the end

#

where you combine

#

you need to assign back to Dependency

#

**Dependency = **JobHandle.CombineDependencies(Dependency, handle2);

minor sapphire
#

Damn, stupid mistake

#

thanks ^^;;

ocean tundra
#

structs

#

๐Ÿ˜›

minor sapphire
#

sigh lol

#

I'm still not used to dependency management really

#

been doing it for ages but it still catches me

ocean tundra
#

yea me too

minor sapphire
#

ctrl f on CombineDependencies to check all usage lol

#

ok good I did get it right in other places haha

frigid quarry
#

Hi guys, is there a way we can manual control culling in ecs/ hybrid rederer? I have some object have shader that changes position, find the current culling system doesn't work on that

ocean tundra
#

@frigid quarry im not sure which system(s) control it

#

but you should be able to find them. copy them into your project

#

and disable the original systems

sullen mason
#

is this tutorial still relevant?
https://www.youtube.com/watch?v=BNMrevfB6Q0

having some trouble replicating the behavior shown ๐Ÿค”
more specifically, it seems like their bullets are converted to entities, but still use the update function... am I missing something here, or is this tutorial just skipping crucial parts of information?

In this video, learn about what's involved in migrating existing game code to the new Data-Oriented Technology Stack (DOTS), which comprises the C# Job System, the Entity Component System (ECS), and the Burst Compiler. You'll also gain an understanding of the performance benefits you can expect from these systems. Finally, you'll learn when it m...

โ–ถ Play video
ocean tundra
#

havnt seen it

#

but at a guess no

#

oh i was at that session

#

๐Ÿ˜›

#

definitely not relevant

#

the ideas and concepts will still apply

#

but any code will be long obsolete

sullen mason
#

got it. got any recommended tutorials to follow? been pulling my hair out over this for the past few days...

ocean tundra
#

umm just the offical docs really

#

i dont know any up to date tutorials

#

i think unity learn has something

#

but not sure its for the latest

#

the problem is its still very work in process

#

so not much offical unity focus on docs

#

and anything the community makes gets out of date fast

sullen mason
#

right, definitely seems that way after the tonne of tutorials ive been trying to follow ๐Ÿ˜‚

ocean tundra
#

the core concepts should all be the same

#

and then look up the same 'thing' in the entities doc

#

and see the current way of doing it

#

EG any tutorial that has you writing a job manually to loop over your entities

#

you should use Entities.Foreach for that

#

and theres a massive doc page on that

#

and feel free to ask here, most people are happy to help

sullen mason
#

any chance you could link me to said entities docs? ๐Ÿค”

ocean tundra
#

its all in the pinned messages

#

top right

sullen mason
#

ah, sweet. Thanks ๐Ÿ™‚

sullen mason
#

WARNING
Do not use the Build and Run menu "File > Build and Run" to build DOTS projects. It might work in some cases but this approach is not supported. You must build your project using the Build or Build and Run buttons at the top of the Build Configuration Asset Inspector window.

In particular, entity subscenes are not included in builds made via the Build and Run menu and will fail to load with the following error message showing up in a development build: "Could not open <path>/<guid>.entityheader for read".)

#

what exactly does this mean? i cant find any "Build Configuration" inspector window...

ocean tundra
#

its another package

sullen mason
#

Standalone Builds
Making standalone builds of DOTS projects requires installing the corresponding platform package for each of your target platforms:

com.unity.platforms.android
com.unity.platforms.ios
com.unity.platforms.linux
com.unity.platforms.macos
com.unity.platforms.web
com.unity.platforms.windows
After installing the platform packages you need, create a "Classic Build Configuration" asset for each platform (via the "Assets > Create > Build" menu). The properties of that asset will contain a "Scene List", which is the only way of adding subscenes to a standalone project. Make sure you add at least one scene or that the "Build Current Scene" checkbox is toggled on.

#

speaking for this?

ocean tundra
#

yea those

sullen mason
#

aight, ive got an error when installing those packages... will reinstall and post here

#

Library\PackageCache\com.unity.entities@0.16.0-preview.21\Unity.Entities.Editor\LiveLink\StartLiveLinkWindow.cs(370,39): error CS0104: 'Platform' is an ambiguous reference between 'Unity.Build.Platform' and 'Bee.Core.Platform'

ocean tundra
#

sounds like you need to rename 'Bee.Core.Platform'

#

annoying

sullen mason
#

so i should rename the "Platform" that these errors are referencing

#

to "Bee.Core.Platform"?

ocean tundra
#

what no

#

'Bee.Core.Platform' is the wrong one

#

never heard of that

#

name that something else

sullen mason
#

i have no idea what that is either ๐Ÿ‘€

#

or where to find it to rename it

#

๐Ÿ˜‚

ocean tundra
#

it must be something you added in your project

sullen mason
#

the only packages ive installed, with ... 5-6 small scripts?

#

none of which have the namespace "Bee"

ocean tundra
#

whats your code namespace?

sullen mason
#

DotsTest

ocean tundra
#

weird

sullen mason
#

fairly sure Bee.Core is part of the "windows platform" ive just installed