#archived-dots

1 messages ยท Page 86 of 1

left oak
#

Game tiles are generally very good candidates for ECS, @tardy locust

tardy locust
#

Not doing great at it

#

xD

left oak
#

Yeah, I prefer square grids cause hexes are hard to grok, at first

#

There are definitely some clever programmatic ways to generate hex grids

tardy locust
#

I know

#

I wanted to try and follow this page

#

They use Cube coordinates

#

Or prefer to, any way

left oak
#

I'll check it out, after coffee - I'd like to know how to hex, too, haha

tardy locust
#

That is a pretty complete resource on how to do hex grids

#

Everything from how the math is supposed to work, how to think about coordinates, etc.

#

If you can translate it to whatever you are using

#

You will have a solid grid

left oak
#

Very cool. What interests me is how isometric tiles, done a certain way, are identical to hexes

#

The column-row arrangement of hexes is easily translated to a NativeHashMap<int2, Entity>

#

The tricky part is just getting the even-odd offsets right, I guess?

tardy locust
#

That is covered too

#

I think there are 4 different kinds

left oak
#

What are you specifically struggling with, at the moment?

tardy locust
#

Oh right now I wasn't really trying

#

Just to see if I could make two rows underneath each other

#

But I couldn't so

#

I'll look into that another time

left oak
#

Haha, fair enough! I'm interested in 3d-grids, so thanks for these resources! They will certainly prove useful.

tawdry tree
#

Hex grids are just square girds where every second row (or column, depending on perspective) is offset.
And I see you've already linked to red blob, which is good.

frosty siren
#

I work exactly with hex grids and use this guide. So i can tell that it's very simple and once u implement coordinates casts (Cubic <=> Offset <=> Index) u will work with grids very comfortable

left oak
#

I'm curious if this would be a legitimate use-case of SubScene: as my content-delivery container for user-generated content. It's stored in binary, so I can easily keep in AWS simple storage, or something like that. What kind've contextual constraints come with loading a SubScene remotely into a client at runtime? SubScenes convert their objects into entities on load, right? Or can they only be prebuilt in the editor?

left oak
#

I see now that the SubScene is only converted when you rebuild the entity cache in the editor. However, each SubScene has its own EntityManager, which gives me hope that I can use it at runtime for remote content delivery.

left oak
#

All that said, Blobs will probably be much easier to work with, I imagine ๐Ÿ’ฉ

dull copper
#

wonder why they bumped Burst to 1.2

#
## [Burst 1.2.0-preview.1] - 2019-09-09

- Fix assembly caching issue, cache usage now conservative (Deals with methods that require resolving multiple assemblies prior to starting the compilation - generics).
- Fix Mac OS compatibility of burst (10.10 and up) - fixes undefined symbol _futimens```
#

changelog is quite tiny

#

but they must have their reasons

coarse turtle
sacred tundra
#

regarding the convert script, using "convert and destroy" like in the link really does destroy them. they disappear. changing it to "convert and inject" does not do anything. ball remains hanging in the air

dull copper
#

@sacred tundra did you try the physics samples first?

#

you need hybrid renderer for the converted objects I think

sacred tundra
#

no. this guide is all i did

#

hybrid renderer eh? makes sense. because the simulation is running, i can see that in debug view

dull copper
#

well, you can probably get away without hybrid renderer but you can then only use like collision shapes and rigidbodies that haven't been linked to meshes

#

I recommend looking those up as they give practical samples for a lot of these things

sacred tundra
#

hybrid renderer made it work pepo_hype

#

can i use hd render pipeline combined with this? ๐Ÿค”

safe lintel
#

yes

dull copper
#

yes

#

not sure about built-in renderer but both LWRP and HDRP both should work

sacred tundra
#

buildtin is what i am having right now. so it works :p

dull copper
#

ah

#

then it's all good

#

you can't use HDRP's DXR with hybrid renderer atm

#

just putting that out there in case that's any interest to anyone

#

(I know I would want that)

safe lintel
#

ahh that might explain my crashing earlier

dull copper
#

it doesn't crash for me, but raytracing totally breaks around the hybrid renderer's objects

#

like, just get pitch black objects or some weird artifacts around the objects

safe lintel
#

oh. well at least it i know its generally incompatible

dull copper
#

Unity's RT dev said on the #archived-hdrp that hybrid renderer hasn't been tested at all with DXR

#

I'm sure they'll sort it out eventually

#

but it seems like these are two separately developed systems atm

#

DXR support is super early anyway

safe lintel
#

i was impressed i could run your sponza proj on a 1070

#

but after enabling dxr in my project, unity refuses to open without a good crash

dull copper
#

@safe lintel are you on beta 2?

#

at least a12 was super crash happy with DXR for me

#

betas are better but they've also fixed some of the crashes on SRP also

#

I dunno which version you downloaded, I updated the dxr sample repo a while ago for newer HDRP master

#

or staging, can't remember which it was (I mainly pick one that's newest from the two)

safe lintel
#

b1 was doing that for me, havent tried with b2 yet

#

got other dots woes just eating away at my time

analog horizon
#

Hm does anyone know a way to use reflection probes with RenderMesh's?

mystic mountain
#

I have this werid thing I'm not sure if I've managed to create myself, or something that is within ECS or the multiplayer system. I spawn a ghost entity, parent another ghost entity to it. But the Translation component of the child in the debugger seems to be showing world space instead of local space.

#

The child is just offset 6 units from the parent.

mystic mountain
#

nvm, I think I just parented on one side. So the values I look on is on server, so that's why it looks correct, but I'm actually displacing it in my parenting code.

amber flicker
#

I have a NativeArray bob and for each entity I iterate in a system I access the data via an entity reference (otherEntity). e.g. someData = bob[otherEntity.Index];. This random access is pretty painful performance wise. As it's very predictable - are there any cunning tricks to getting this data into cache with the other component data? Like a component that has a pointer into the NativeArray or something?? waves hands about vaguely

vagrant surge
#

@amber flicker store the index directly

#

caching it

amber flicker
#

not sure I understand - for clarification, it's not otherEntity.Index that's time consuming, it's bob[idx]

vagrant surge
#

not much you can do about it, really

#

but just accessing the stuff from linear (on the index thing) shouldnt be an issue

#

the cpu can prefetch those kind of accesses fairly well

amber flicker
#

hmm I need to work on a simple example but pretty sure with 100k iterations (which is a lot), that read alone adds about 1-2ms

vagrant surge
#

have you thought of having that array on a per-chunk basis?

#

that way instead of having a 100k long array, you have many of them, and they are chunk-local, so memory is less spread

amber flicker
#

hmm... I was wondering if there was a way to e.g. associate a buffer with a chunk (I know there's chunk data) so it would be loaded in on a single cache line (or I'd hope) but I'm not sure that's possible

vagrant surge
#

thats what stuff like chunk data is for

#

you can also have an array of arrays

#

and store the index in the chunk data

idle steppe
#

I'm still pretty new to ECS, and i'm not sure i'm doing this right.

I'm writing a nameplate system; I have 2 different Entities, one being a character entity that has a bunch character components, and the other being a nameplate entity. The nameplate entity exists as a pool of nameplates and one can be fetched and bound to a character entity.

In order to bind the two entities i'd need to have the nameplate entity reference the character entity and get it's Health Component. I'm not quite sure how to structure this relationship.

            var namePlateEntity = GetComponent<GameObjectEntity>().Entity;
            var entityManager = World.Active.EntityManager;
            var healthComponent = entityManager.GetComponentData<HealthComponent>(character);
            entityManager.AddComponentData(entity, healthComponent);

I can't tell if i'm just trying to force object oriented programming here or if there is a better way to have 1 entity reference another's component data or if I should just be adding the nameplate components to the main character entity. I worry that as I build this game the character entities are just going to have hundreds of components.

hollow jolt
#

Im checking out the first example in ECS the class RotationSpeedSystem_ForEach : ComponentSystem inside the function OnUpdate where it uses:

Entities.ForEach((ref RotationSpeed_ForEach rotationSpeed, ref Rotation rotation) =>
...

I kind of get that the first parameter is the component data, but how does it know about the second argument ? Does it automatically scan each RotationSpeedAuthoring_ForEach : MonoBehaviour, IConvertGameObjectToEntity and extracts its rotation value ?

#

What is the optimal way to learn ECS ? I jumped into the examples without knowing anything about it, would it be better to practice ECS without using the ConvertToEntity behaviour ?

silver dragon
#

@hollow jolt RotationSpeed_ForEach and Rotation are components. Entities.ForEach iterates over all entities with the given components, in this case over all entities with both RotationSpeed_ForEach and Rotation.

#

To learn ECS/DOTS: Jump in the examples, docs, and sometimes the source code ๐Ÿ™‚ Ah, and read discord and forums!

hollow jolt
#

ah i see, how could i find out the list of all the components that are present in the Entitie by default ?

silver dragon
#

Hm, you could look at the Entity Debugger

hollow jolt
#

Just noticed the pin and found few articles on the official website will make sure to look into that

#

ok thanks

#

@silver dragon regarding performance wise is it better to reference all the components in a simple foreach loop or is it ok to separate them ? Also what is the limit of the amount of arguments i could use in foreach ?

silver dragon
#

@idle steppe You could add a NameplateRef component to the player entity which holds a reference to a nameplate entity. And a PlayerRef component to the nameplate entity which holds a the player entity.

#

@hollow jolt For performance you should use one IJobForeach and Burst ๐Ÿ™‚ Limits... huh... you have to look at the overloads to find out... i think 5 or 6 components are doable. Additionally a buffer and monobehavior. Not sure...

dull copper
#

I have a question for Unity ECS experts here, what's the most perf efficient way today to sync entities with gameobjects transforms? Right now I just poll the pos and rot from entitymanager each update via component data getter using entity id but is there any more efficient way?

#

example snippet: cs transform.position = entityManager.GetComponentData<Translation>(EntityToTrack).Value; transform.rotation = entityManager.GetComponentData<Rotation>(EntityToTrack).Value;

#

hybrid renderer would be nice but it doesn't play ball with DXR atm and it has some other limitations as well

mint iron
#

Not an expert by any means but ill throw in some thoughts. There is some overhead in the checks in EntityManager.GetComponentData that adds up doing it one by one. So if you could grab all the pos/rots and targets that need updating in advance and process them together it could see improvements.

dull copper
#

yeah, when polling one by one just feels it could be faster

mint iron
#

Another idea i've been meaning to look into is using the UnityEngine.Object m_CachedPtr. Since the c# classes like for Transform are just wrappers for fixed layouts on the native side it should be possible to figure out the layout and update the pos/rot manually from a burst job with direct memory access, but obviously you've got a can of worms with that one.

dull copper
#

it could also mess up with some of the internal optimizations they do as we don't know everything that happens on their side

#

last time I asked the staff of being able to access transforms from native api (I can see the access points on IL2CPP code), I got warned it could screw up their GC etc

#

but you can also set the gameobject transforms in jobs too, so if you can somehow get these things in some list / array etc from entity side, it could be a lot faster

#

last time I looked into that was when I was trying to optimize bullet physics transforms for Unity GO's

mint iron
#

yeah, its an interesting area that i've seen very little around. I was thinking about it facing the lack of MaterialPropertyBlock support in the current renderer. Having to replace the material currently is a huge problem.

dull copper
#

I'd really really want to use the raytraced reflections, I don't really care that much of the rest of DXR (but could also use the shadows as they are nice)

#

but right now it might take anything from half a year to year+ for Hybrid Renderer to get compatible with DXR, I seriously doubt it's happening with 2019.3 at least

mint iron
#

The other option is to stuff all your GameObjects into a dictionary and look them up by Id, which is what im doing for all my UI elements. So the menu panels can get switched by ECS side events. The instanceID is stored during the ConvertToEntity process when it has access to both the GameObject and Entity.

pliant pike
#

is there a reason why you cant access public const variables externally in an CompSystem?

mint iron
#

do you mean from within a job?

pliant pike
#

well its a public variable in a jobcomponentsystem

#

I can access an ordinary float using GetExistingSystem<system>.somevariable

#

but I cant access it when its defined as a public const

tawdry tree
#

Uh, constants are static meaning you acces them by the Class directly, not an instance

#
class SomeClass{
  public const int Constant = 1;
  public int Variable = 1;
}

//Accessed like:
SomeClass.Constant;
var instance = new SomeClass();
instance.Variable;
pliant pike
#

Oh yeah I see now, thanks Hodhandr

idle steppe
#

Is it an acceptable design pattern to have entities referencing other entities and pulling components from their references? Seems like im doing something bad.

amber flicker
#

@idle steppe very common - using ComponentDataFromEntity? Of course nice if you can design things to avoid it in an ideal world but often necessary.

idle steppe
#

Ahh interesting - that was the call I was looking for. Thanks @amber flicker . A way to fix this coupling is I could just add all these nameplate components to the character entity instead - i'm worried a few months from now i'll have hundreds or thousands of components on that entity - is it better to break things up into smallers entities when possible?

amber flicker
#

Hmm... it's always a balancing act and there aren't many general rules you can apply. If you have a character entity with 100 components, yes you likely would be better off changing some of the design I'd say. Could probably offer more specific advice for a more specific problem.

idle steppe
#

Imagine a character with buff and debuff slots like a mmo - each debuff / buff bound to the character could add multiple components to the entity on top of the already thick stack of determining factions, level, health, mana, etc. These buff/debuff slots could have no limit to how many there are.

A large chunk of systems would just be running on the same character entities but with their own unique queries. It starts to look like object oriented programming to me at that point.

amber flicker
#

I think broadly you can go one of three routes (off the top of my head): 1) (my choice I think), debuff & buff Buffers per entity - essentially an array of buffs, 2) entity per buff/debuff with a reference to your character entity, 3) a NativeList or something independent of an entity but per character storing buffs/debuffs

#

but if they are buffs/debuffs it's actually probably a lot more complicated as to the best architecture - I guess they have durations, perhaps exclusive conditions and so on? - might be worth seeing if anyone else here has worked on a similar system

vagrant surge
#

with unity model, its a great idea to split into multiple entities

#

the model generally doesnt like super-fat entities

#

for buff slots, multiple entities works better than you would think

idle steppe
#

How would you maintain that reference? a CharacterReferenceComponent on each of the buffer entities?

vagrant surge
#

yeah

idle steppe
#

How would you store that reference in a IComponentData? the index of the entity?

vagrant surge
#

yeah, the entity ID

amber flicker
#
{
    public Entity Character;
}```
idle steppe
#

seems weird but i'll go for it - thanks for the help!

amber flicker
#

any idea what kind of numbers you anticipate? characters & buffs?

idle steppe
#

1000s

amber flicker
#

of both?

idle steppe
#

yes

vagrant surge
#

absolutely entities as buffs then

#

the thing is that buffs are likel to have components like buff type, buff damage, buff time, etc. And adding/removing components is expensive

#

so better to leave the player entity mostly alone

#

and just "attach" entities to it

amber flicker
#

hmm... I'm thinking buffers would be better @vagrant surge ? I'm having to refactor a huge bunch of stuff that's per entity to buffers because at those numbers the out of cache really hurts?

vagrant surge
#

with buffers its not so flexible for the buffs themselves

#

you can have it 2 sided

#

characters have a Buff component

#

that holds an array of entity IDs

#

of buffs affecting

#

and buff points to character

#

thats somewhat how i was doing it for a MMO pirate server i was prototyping

amber flicker
#

I guess it quickly gets into the realm of what data do the buffs need to access and where does that sit etc

idle steppe
#

thats the scary thing about buffs - a designer will try and make it access everything and nothing in the same breath.

vagrant surge
#

thats why you might want them as entities

#

so they are configurable

#

can add more effects by adding more comps

idle steppe
#

I haven't been able to touch buffers yet. what's the limitations of that path? And why opt for a 2 sided approach when prompted?

vagrant surge
#

just an array as a component

#

the 2 sided approach is so when the character dies you delete his buffs

idle steppe
#

ahh - makes sense.

#

Would all of these need to be in the same chunk? the coupling of entities seems to break what unity described as this magical place where everything sits tightly in memory.
ie. Should a entity with a component referencing another entity be in the same chunk.

vagrant surge
#

nah

#

the buffs will be split into different chunks

#

by their type

#

so basically all "fire DOT" buffs will be on one chunk

#

all "ICE debuff" in another

#

etc

safe lintel
#

@dull copper wouldnt it make sense to use copytransformtogameobject component? any entities transforms are synced within a burst job

idle steppe
#

gotcha!

#

Thanks again!

dull copper
#

@safe lintel there is such component? ๐Ÿ˜„

#

or you mean I should make one?

safe lintel
#

there is one ๐Ÿ™‚

#

both CopyTransformToGameObject and CopyTransformFromGameObject

dull copper
#

is it used by the old gameobjectentity?

safe lintel
#

no need to use gameobjectentity

dull copper
#

no I mean, is that used internally by it

safe lintel
#

no

dull copper
#

I don't see ECS sample repo using either of those things

#

they do the naive component data getters there

#

which is why I asked in the first place

safe lintel
#

i dont really understand the usage of gameobjectentity in the physics samples when they want people to use convert

#

i see the proxy still exists for them if you wanted to use that

dull copper
#

the reason on physics samples is partially because they want to show how people can still use that from monobehaviours I think

#

if you look at the physics vehicle sample, most of the vehicle code is in single monobehaviour

#

which is totally unoptimized as well

safe lintel
#

you can still get the entity by way of conversion though

dull copper
#

not sure where you are going with that?

safe lintel
#

you can get the entity that a gameobject gets assigned from conversion, so I dont see why they still use gameobjectentity

dull copper
#

they don't

#

or at least I don't remember seeing any sample that does that there

#

but my memory also sucks ๐Ÿ˜„

safe lintel
#

the entity to track thing does i thought

dull copper
#

nah, they store the entity id to monobehaviour and poll entity manager for component data with that cached entity id

safe lintel
#

anyway com.unity.entities@0.1.1-preview\Unity.Transforms.Hybrid\CopyTransformToGameObjectSystem.cs or CopyTransformFromGameObjectSystem.cs has the usage of those components

dull copper
#

it doesn't use gameobject entity

#

yeah, I'm looking at those now here, thanks for pointing out those exist ๐Ÿ˜„

#

quick google got me into discussion which pointed out that those CopyTransform functions only work with GameObjectEntity?

safe lintel
#

no, it just needs to be added manually(unless you intend to use the proxy equivalents)

dull copper
#

so need to feed in the GO ref manually?

#

well, I'll look into files, should be more clear then

#

this is what I dislike on these new autogenerated docs

#

I'd prefer the old style Unity docs with proper descriptions and sample snippets

safe lintel
#

So if you have the ConvertToEntity script with ConvertAndInject selected, it should auto add the transform

#

yeah me too, do you know if they plan for docfx to replace the original manual at some point? i also dislike the narrower appearance

dull copper
#

no idea but since most are going for packages, it's not a bright future for us

#

I totally get it's easier to keep the up-to-date this way

#

but this is #1 reason why competitors game engine docs are so subpar on API docs

safe lintel
#

and theres like virtually zero actual documents for any of the conversion or hybrid stuff so not really sure what the long term plans for how this all works is

dull copper
mint iron
dull copper
#

that's cool tho

coarse turtle
#

@mint iron nice

dull copper
#

wonder how likely that is to break when they change things ๐Ÿ˜„

mint iron
#

haha, yeah

dull copper
#

so this kinda works in opposite direction which I'd need myself ๐Ÿ˜„

coarse turtle
#

btw, for the CopyTransform stuff, this is really all I did to sync the translation/rotation -> the gameObject transform

        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) {
            if (CopyToTransform) {
                dstManager.AddComponentData<CopyTransformToGameObject>(entity, default);
            }

            if (CopyFromTransfrom) {
                dstManager.AddComponentData<CopyTransformFromGameObject>(entity, default);
            }

            if (CopyInitialFromTransform) {
                dstManager.AddComponentData<CopyInitialTransformFromGameObject>(entity, default);
            }

            if (CopyScaleToTransform) {
                dstManager.AddComponentData<CopyScaleToGameObjectTag>(entity, default);
            }
        }
#

for scale, I just wrote my own system to apply a Uniform/NonUniform scale back to the gameObject

dull copper
#

@coarse turtle oh, that's simpler than I thought

#

I don't really care about scale at all

#

all I need to do is to sync dots physics to GO side

coarse turtle
#

yea the scale thing was my own stuff, unity doesn't have that, just an FYI

dull copper
#

I'm kinda fighting something totally different right now, I want entities package to show up in projects solution but it just refuses to pop up there

coarse turtle
#

If you're on windows, you can try to leave it in ILSPY

#

the entities package

#

at least that's what I do so I can quickly view its references

dull copper
#

I know I can get it there if I manually move the entities package from library/packagecache -> packages but it's PITA to update when next version comes

#

there's this editor setting that should gen all project files automatically

#

but it's not working, not sure if it's 2020.1 alpha issue ๐Ÿ˜„

coarse turtle
#

ooo you're on the alpha haha

dull copper
#

yeah, for no good reason tho, I'll try again on 2019.3

coarse turtle
#

haven't looked into that yet, im still on 2019.3b lol

dull copper
#

was just testing 2020 and figured I'd check this there

coarse turtle
#

good pt

dull copper
#

there really isn't any good reason to jump to 2020.1 for me right now

#

will see if they add some feats soon that I can't do without

mint iron
#

if all the proj files have been generated i've just used add project to temporarily put it into the solution, it gets removed again whenever you restart unity but for that debug session it then lets you step through the code etc.

dull copper
#

the issue is that this doesn't do those csproj files for most packages

#

it's like it just ignores that editor preference setting fully

#

it's same result as without the toggle

mint iron
#

hmmm, sounds like a 2020 thing then

coarse turtle
#

@mint iron that's a good tip ๐Ÿ‘

dull copper
#

I even wiped the library and let it process again

mint iron
#

entities is in packages for me now because i got mad at all the private/internal methods and did a find-replace to make the entire thing public.

coarse turtle
#

same goes for me with the transport layer

dull copper
#

well, it's not working on 2019.3 either for me on this project

#

so I guess I'll just more the package again

#

it was so nice when this worked tho

safe lintel
#

"all I need to do is to sync dots physics to GO side" oh you will need to make your own mini system for this ๐Ÿ˜„ the CopyTransformToGameObject system uses localtoworld, which unity physics ignores(uses translation,rotation)

dull copper
#

lol

#

well, thanks for the headsup

coarse turtle
#

oh, that's a good to know lol

dull copper
#

well, this starts to make more sense then

#

like, that must be the reason why they just poll the entitymanager for the translation and rotation data on physics samples

#

I'm sure they'll come up with more elegant setup out of the box at some point

#

those copy components, they were initially used in GameObjectEntity right?

#

I have faint memories of using those a long time ago

coarse turtle
#

yes, the proxies/componentdatawrappers

safe lintel
#

in conjunction with the proxies

#

yeah

dull copper
#

and GameObjectEntity is going to get removed,right?

safe lintel
#

some of the conversion stuff uses part of gameobjectentity under the hood so ๐Ÿคท

dull copper
#

ah, I just noticed that the samples moved away from it, so took that as a sign

coarse turtle
#

dunno, afaik joachim said that should be going away "soon", but the conversion workflow will stay for a few more years on the forums

dull copper
#

yeah, conversion workflow will be made production ready according to him

#

or at least that's what I remember reading

mint iron
#

physics also completely ignores any child-parents you setup manually in code outside of a prefab Hierarchy ๐Ÿ˜ฆ that was a complete pain in the ass for me.

safe lintel
#

probably just get rolled into the converttoentity script but i remember trying to replicate some functionality from it a while ago and found the dependency

dull copper
#

I'm kinda sad that ecs editor took steps back

#

not fan of the conversion setup

#

I'd just want hybrid components and then editor support for the both sides ๐Ÿ™‚

vagrant surge
#

when Entitas is a thing

#

the clunk and jank on conversion looks like shit

safe lintel
#

i just want more dots compatible packages, i kinda dont mind the state of the editor(except for maybe the physics joint workflow)

dull copper
#

missing proper editor is quite limiting workflow wise

#

especially runtime debugging is pain

#

it's just going back in usability, removing nice things we've used having

vagrant surge
#

its why people think ECS is hard

#

if it was like entitas it would get a lot more usage

dull copper
#

I'm sure they'll cover this topic at Unite to some extent

vagrant surge
#

lets see

#

because it seems they are going even more into conversion workflow

#

given that Tiny editor got abandoned

#

what i wonder is why is it so hard

#

cant they just do what Entitas does? make a component that displays the ECS components on the hybrids

dull copper
#

I don't think the tiny editor was fully dumped

#

like current version of it maybe

#

hmmmm reading the tiny thread again

#

well, if they can make the conversion workflow so that you still see the entities in the hierarchy, that's fine

#

apparently the hierarchy is kinda issue with ECS data layout tho

vagrant surge
#

yeah they want to flatten

#

cant they add folder type stuff ?

dull copper
vagrant surge
#

a visualization beetween "gameobjets" and entitities would definitely be useful

#

in such a case, then the game object editor is kinda the "edit only" mode?

#

and then you can link the GO with entity to see the entity vals

dull copper
#

@safe lintel @coarse turtle just putting ConvertToEntity to "Convert and Inject GameObject" and adding that CopyTransformToGameObjectProxy to the same GO does update my DOTS physics rigidbodies

#

so, maybe they've changed that on physics package since?

#

I looked at the tranform copy system and it still copies the data from LocalToWorld

#

it also uses that TransformAccess that works on updating GO's on jobs

safe lintel
#

the translation is being updated by the gameobject?

dull copper
#

it's updated by the copy tranform system(?) not sure if you asked that tho. all I want now is this to be updated by physics sim and mirror the rigidbody transfrom to GO transform

#

it seems to do that out of the box

#

so wonder what's the deal with the physics samples not doing it this way

#

oh wait, when I added the copy proxy, it adds GameObjectEntity there automatically ๐Ÿ˜„

safe lintel
#

well if its working its working ๐Ÿ™‚ my experiences were a windy road

dull copper
#

well, I get a nag about having GameObjectEntity now ๐Ÿ˜„

#

it basically says it will be ignored since the conversion script is there already

#

but the copy component requires it

#

which is inheriting it from ComponentDataProxyBase

coarse turtle
#

hmmm, maybe i'll just write my own version if its doing that lol ๐Ÿ˜…

dull copper
#

yeah, it should be doable

#

but if this works, I'm totally fine by it nagging it on the inspector ๐Ÿ˜„

#

they will update Entities package soon anyway and chances are that custom things will break again

safe lintel
#

well if you wanted to use the converttoentity i would add like

    public class CopyDotsTransform : MonoBehaviour, IConvertGameObjectToEntity
    {
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            dstManager.AddComponentData(entity, new CopyTransformToGameObject());
        }
    }
#

if you wanted to ditch the proxy stuff

coarse turtle
#

Oh yeah I did the same, I think I misunderstood previously lol

dull copper
#

that works

#

so considering it's that simple

#

why doesn't Unity use this on samples?

coarse turtle
#

tech debt ๐Ÿ™ƒ

#

most likely

dull copper
#

yeah but they probably put more effort on the current scripts there

coarse turtle
#

yeah...I think unity is just in that phase where they might be a bit everywhere and need to show something visually that 'works'

dull copper
#

hmmmm, apparently "convert and inject to go" doesn't work with dots physics compound colliders

#

if I add collider to the same object with the conversion script it works

#

but if it's child go, it gets ignored with this setting

frosty siren
#

For what purposes we have ExclusiveEntityTransaction? There is no comments in code(

rancid geode
sand cypress
#

Ok, Sorry sir.

low tangle
#

@dull copper personally I created a clone of the copy to / from systems and a new set of components to work independent

#

this gave me way more control and until TransfromaAccessArray goes away this wont go anywhere

#

then you only pay for the number of total transforms you sync per frame

#

I think I have no problem up till 50k transforms but I'd need to recheck as its been a looooong time

dull copper
#

Makes sense, right now there is no interpolation for physics either so could build a system that does it as well

low tangle
#

yep, once you pay for the transformaccess copy once, just do absolutely everything else in ecs and life is good

amber flicker
#

@frosty siren can't help much except to say Joachim, verse 14: "ExclusiveEntityTransaction is more for streaming large amounts of data on a seperate world."

wary anchor
#

I'm trying to perform some calculations on vertex data and I'm wondering whether it's worth bringing the vertex data into a job-friendly format to try to parallelise the work, then take it back out to the main thread at the end to piece together the final mesh.

#

A summary of what I'm trying to achieve:
for all atoms (tens of thousands), check every vertex and triangle for intersection with another atom.
Save vertices and triangles which are not intersecting to a surface mesh.

There's some tricksy details buried in there but that's the overall gist of it

#

I have been using the hybrid renderer with batched RenderMeshes which is great for performance, but doesn't allow me to do a few things I really need to do. Thinking I may have to take the final rendering step outside of ECS but use jobs to do all of the up-front calculations that need to be done

#

Does this sound like a sensible approach?

amber flicker
#

It sounds ok to me - what's your main concern? Is this on-load of a castep file or something?

wary anchor
#

I think the issue I'm concerned about is that I'll be completely separating out the (previously batched) meshes into what could end up being a massive single mesh

#

But I guess that's probably just me not wanting to give up having 33k objects drawn on screen with just 4 verts and 2 tris ๐Ÿ˜„

#

I would save the mesh data within a component as well as I'll be using the verts later for things like calculating possible spawn positions

#

Thanks for the sanity check @amber flicker going to push on to a first version and see what it's like ๐Ÿ™‚

amber flicker
#

yea... struggling to reply with something useful. Are a bunch of instanced geo'd meshes more performant than a giant mesh? Almost certainly. Would you gain perf from jobifying & bursting vertex checking stuff? Yes - although gpu's also a consideration depending on the task I guess. As to what you're trying to achieve from a higher-level perspective - not sure ๐Ÿ™‚

wary anchor
#

Currently my level is a collection of spheres (atoms). Previously in my OOP implementation, I generated a surface mesh for each atom with a voxel-type calculation then morphing the mesh to effectively shrink-wrap the atoms. That meant I could then select surface atoms (those with surfaceMesh.vertices.Count > 0) and find spawn points for procedural stuff that way.
I'd like very much to have a smoother surface - less obviously-just-a-bunch-of-spheres (without going into raymarching, probably!), and also have access to what is on the surface and what isn't within the job structure. My levels are protein structures from public databases - I don't have control over the structure so need to work out what the surface is just from the atomic coordinates.

#

Now everything is super lean in ECS I definitely don't want a bunch of gameobjects with meshes on, and now that Unity has made meshes capable of holding more than 65535 verts, my options are a little better than when I did my first OOP implementation. Assuming a single large mesh is viable, but I can play around with the geometry to make it all right I think.

amber flicker
#

๐Ÿ˜… can't add anything useful but good luck - it sounds fun ๐Ÿ‘

wary anchor
#

ouch!

mint iron
#

its probably quite stressful right now organizing the event and everything that goes on.

low tangle
#

sheeeit

#

@wary anchor not too familiar with how you are going about the smoothing

#

how big is the data set?

wary anchor
#

In other news, my gravity/collision system is finally working nicely

low tangle
#

the mesh vertexes

#

awesome!

#

I'm about to make a sphere simple gravity system soon for my game for details on characters

#

should be pretty fun

wary anchor
low tangle
#

oooo pretty

wary anchor
#

I can't believe how fast it runs! No colliders or physics helps

low tangle
#

no smelly slow monobehaviours as well :)

wary anchor
#

yup!

#

So my plan is coming down to this:

1) get pairs of intersecting atoms as collection
2) for each atom, calculate vertices by scaling then translating a template 'mesh' (vertex positions scaled to 1f around the origin, eg an icosahedron or similar)
3) check each vertex to see if it's inside any of that atom's intersection partners via collection from step 1
4) write verts to master list (need to think about whether I can do this step in parallel or combine at the end?)

The tricky bit is number 4 as I will save all triangles where at least 1 vert is not intersecting another atom, then add in the other 1 or 2 verts to keep that triangle in the final mesh. Then transform the position of those 2 would-have-been-deleted verts to a shared position with the neighbouring intersecting atom's equivalent would-have-been-deleted verts (possibly deleting one set and sharing the verts at this point).
There will be another issue when at the intersection point of 3 or more atoms, I need to think on this a bit more.

low tangle
#

makes sense

#

its going to be tricky with the ordering of what needs to happen before x and if you need to verify something

#

you might want to try doing it over a few systems and stages to make it more sane (with sync points)

#

then figure out how to remove the sync points later on

wary anchor
#

That's a good point, yes, syncing could be an issue

low tangle
#

the complexity is a big jump from single threaded where you can confirm that something is done before other thing, but multi its very very hard unless you do everything always even if its not needed

#

I would look at this problem as not exactly within ecs bounds though,

#

think of it more of using the ecs world / data to run a process, that churns though some large data sets, with temp memory shared all inside of standard jobs

#

that way you can just focus on a to b

#

a chain of standard stock jobs should be much easier to manage, but still off the main thread, and still able to be burst compiled

wary anchor
#

yes, I was thinking probably keep it in a single system for now: I have the atom list data from my previous system so that gives me all the coordinates and scales I need. I can ensure sync points and sharing of data like in the boids example that way

low tangle
#

use some native array temp memory inside and just work though what you need in that small tight area

wary anchor
#

sounds like a plan!

#

now comes the easy bit

#

๐Ÿ˜„

low tangle
#

haha

#

time for more coffee goodmorning

wary anchor
#

hellz yeah. Thanks @low tangle

#

quick question, because I don't know up front how many verts I'll be dealing with, I think I need a resizeable collection like NativeList - is it best to use this while generating the data then for later access by other systems store it into a NativeArray of the appropriate size? Or is that microoptimisation. I've not use a NativeList yet, but I know they're slower due to the lack of up-front allocation

amber flicker
#

you can cast NativeList to NativeArray

wary anchor
#

I suppose if I brute force it, I know the max number of entries I'll need: template mesh verts * number of atoms. Might be wasteful though

low tangle
#

@wary anchor do the quick math

#

what size of component?

#

how many elements

wary anchor
#

I'm thinking... the key step is how to structure the data of triangles mapping to verts mapping to atoms

low tangle
#

well, mostly talking about the size of the data last question

#

doing the math on say, tons and tons of float3's

#

how large is the template mesh, and how many atoms do you expect to load

#

you mentioned it was a icohedron?

wary anchor
#

If i have an icosahedron and 33k atoms, that's going to be a total possible size of ~ 390k

low tangle
#

390k verts?

wary anchor
#

I think that's right isn't it?

#

12 verts on an icosahedron

low tangle
#

only 12?

#

yeah let me do the math then

#

11 megabytes

wary anchor
#

yeah that's about where I got to

low tangle
#

verts 12 float3
triangles 12 int32
normals 12 float3s

float3 = 12 bytes
int32 = 4 bytes

288 for verts and normals
48 bytes for triangle indexs

336 per ico

336 * 33k = 11,088,000
#

always fun to calculate data size

#

so yeah, brute force away, 11mb is nothing for ram

#

hell you can ask malloc for that in one go for no time at all

wary anchor
#

the real fun part comes later after brute forcing that in culling the unused data. Anyway I'll worry about that when I get there!

#

I hate keeping track of mesh data

low tangle
#

I'd say to, don't cull or chop the data

wary anchor
#

Not a strong suit for me

low tangle
#

instead figure out whats inside vrs out

#

by passing over the data and marking it

#

then pass over that and take your final set and fix the triangle indexes (which you actually dont need to bother with till the end)

#

heh

#

you basically doing 3d minesweeper

wary anchor
#

hah yeah I guess it is kinda similar

low tangle
#

if the verts were on a grid, you would just be selecting all that have at least one missing side

wary anchor
#

or rather, nuking all that have exactly 3 missing verts

low tangle
#

something to think about

wary anchor
#

It will take me a while for sure. Structuring the data as it goes into the jobs is still something that I really have to ponder ๐Ÿ™‚ I'm getting faster at it

#

but still

low tangle
#

all good

#

by taking that step and really thinking about your data first

#

makes all the difference when it comes to actually solving the problem at hand

wary anchor
#

yes I realise that is absolutely the crux of working in ECS.

low tangle
#

I find I spend far more time being forced to think about my logic and data process than actually writing it

#

which honestly is a nice side effect

#

can't really hack it

wary anchor
#

yes, it makes sense when you take a step back and look at game dev in those terms! The actual implementation should be fast if everything is planned right

low tangle
#

100%

#

I had to finish up a chunk of my games animations and IK back in monobehaviour land

#

and it made me miss ecs stuff so dang much

wary anchor
#

๐Ÿ˜„

low tangle
#

but even then I was able to write my monobehavour like a ecs system with components that were nothing but data

#

its weird at first but strangely still fast as well?

#

it also made the logic super dang compact

wary anchor
#

that's how I started getting into ECS. I needed to refactor, so I decided to de-monobehvaiour everything possible and do proper unit testing

#

then I discovered ECS and was like... hang on

#

that's a much cleaner way of doing it

low tangle
#

worth it

#

so fucking worth it

#

I've been doing it for 6 months now since unity first released it

#

not a single regret

#

wait

wary anchor
#

but oh my god the mental remodelling required to get even slightly competent with ECS has been HARD!

low tangle
#

its been a year now I think

#

oh yeah I remember when you came in here

wary anchor
#

yeah sorry about that

low tangle
#

its fuckin hard brain remodeling

wary anchor
#

๐Ÿ˜„

low tangle
#

I went though it too

#

its like hold up, back to babys first programing, plus theres like a billion new things to learn about

#

but thankfully everything is just a simple claw hammer, does only one thing, but does it well

wary anchor
#

I quit my previous life nearly 4 years ago so have been re-training my brain solidly since then. I kinda didn't want to have to forget all that I'd learned, but it's not really like that, it's just extending my skillset and that is always always worth it

low tangle
#

humans are always works in progress, so are our skills

#

I never intend to stop learning, I love it too much

#

change is good

wary anchor
#

Yup, couldn't agree more!

#

Although I can't see what's past my current goal: getting players to play a game I made running around a protein whose structure I solved! That is going to be epic. When I get there ๐Ÿ˜„

low tangle
#

hell yeah ๐Ÿ˜

wary anchor
#

combine my former life with my new one ๐Ÿ˜„

low tangle
#

I want to see you finish that game!

#

you got this

wary anchor
#

at least now I have a clear idea of what the game will be. but it is slow working on your own, at least I am slow working on my own

low tangle
#

it comes in bursts for me

wary anchor
#

SO MUCh ^^^

low tangle
#

slow skull dragging for awhile, then massive gratifying jumps

wary anchor
#

I've always been like that, back when doing lab work too, I'd have one epic week and get all my results, then 3 weeks of apparently nothing

#

Speaking of which, I have a good feeling about this mesh code. Thanks so much for the advice and the chat! Both really appreciated. I'm going to smash this today if it kills me ๐Ÿ˜„

low tangle
#

haha I was about to say the same, I'm gonna get back to it :)

#

good luck

wary anchor
#

and you ๐Ÿ™‚

mystic mountain
#

Hey! So I have entities in the world (spawnPoints) marked for two teams by a Faction component. There can be multiple spawn points for each faction, and they can be occupied. (lets say marked by a occopiedTagComponent) I have an entitiy that triggers a spawn with a Faction component and what should be spawned. Is it possible to jobbify this code since I need to mark spawnPoints "taken"?

low tangle
#

yeah, but you would have to use a hashmap to keep track of who took what, or a large linear array but I'm not sure exactly how to lock / use a semaphore for the atomic flipping of the bool to mark it as used

#

I haven't really used any normal multi threaded stuff so far with jobs, usually trying to find a different way to do it with jobs works

#

usually I just use a hashmap like a locking hashset to check if its been taken at this index

mystic mountain
#

Ok ,I haven't used hashmaps in ECS yet, so I'll have to look that up : )

low tangle
#

also I finally got around to make visual studio snippets for ecs stuff

newjobsystem 
//which expands to this, placing cursor at end
class NewJobComponentSystem : JobComponentSystem
    {
        end

        protected override void OnCreate()
        {

        }

        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {

            return inputDeps;
        }
    }

newsytem 

class NewComponentSystem : ComponentSystem
    {
        protected override void OnCreate()
        {

        }

        protected override void OnUpdate()
        {
            end
        }
    }


newcomponent 
     struct NewComponent : IComponentData
    {
        end
    }

ForEachEntity 

Entities.With(query).ForEach((Entity ent) =>
            {
        end
            });
#

Documents\Visual Studio 2019\Code Snippets\Visual C#\My Code Snippets

#

they go into this directory

mystic mountain
#

That's neat, I use ScriptTemplates : )

low tangle
#

I've been suuuper lazy for a long time

#

wrote every single lambda and system, all 120 of em

#

oh they add the unity usings at the top as well

#

Unity.Entities + jobs for the job system

mystic mountain
#

Those are neat : ) Just add to a ScriptTemplates folder * : ) I use a lot of Settings when prototyping ^^

low tangle
#

also documents?

mystic mountain
#

How do you mean?

low tangle
#

never used script templates

#

oooh I see

#

those are fuckin neato

mystic mountain
#

That's ForEach version I use as well since I prototype a lot

low tangle
#

I usually end up with like 3-4 systems in one c# file for a strain of logic so I'll probably get a lot of use out of the expand ones I made.
but really thank you for the templates as well, starting off with those is nice

#

this is going to save so much time I wish I did it a year ago

mystic mountain
#

Haha yep ๐Ÿ˜›

wary anchor
#

Hmm struggling a little with the best collection to use for storing intersecting pairs of atoms.

I struggled with NativeMultiHashMap because it turns out that my entityQueryCount squared was too big for the capacity (that would be the maximum possible number of intersecting atoms). Can do it with a smaller max capacity but it's being a bit slow.

conceptually I see it as a variable-length list associated with each atom, but that isn't very job friendly...

#

maybe I should instead just reference the atom which the vertex was inside when storing the temporary mesh data

low tangle
#

refrences are good

#

lots of linear arrays are good too, can you maybe do a max local sized native array/list?

wary anchor
#

I just always seem to be fighting against the possible data types!

low tangle
#

theres probally a reasonable limit for each one of how many it can be inside?

#

totally get that

wary anchor
#

yeah there's definitely a reasonable limit, but it irks me that I will have to hard code that

low tangle
#

nativehashmaps and running them in a bursted job is super fricken cumbersome

wary anchor
#

I tried writing every intersecting pair of atomID (int) to a NativeMultiHashMap in parallel. To be fair, that could be sped up if I reinstate my spatial hash code

low tangle
#

I feel like the atoms / intersecting verts code is more of a volume flood filling kind of problem

#

I wonder if there is a better way to think about the problem

wary anchor
#

then later I'm thinking it's easy to get the collection out relating to each atom of interest as it'll all be listed in that hashmap

#

hmm goo dpoint

low tangle
#

I wonder if you could create a SDF from the atoms (they are kinda like metaballs) and then mesh that surface instead of overlapping and overdrawing icos

wary anchor
#

it is very much a volume filling problem isn't it

#

I can see it now. I'm going to have to learn how to write shaders to make a raymarching shader to display them. ๐Ÿ˜„

low tangle
#

its actually super super easy

#

but you might be able to solidifiy those meshes

#

but then the meshes uvs is a intresting problem

#

if you want them textured

wary anchor
#

nope

low tangle
#

oh easy then

wary anchor
#

either flat shaded with a beautiful low-poly as-equilateral-as-possible mesh (LOL yeah right with no experience!) or just simple shaded. The colour will come from placeables and when I get there grass -like shaders

mystic mountain
#

Quick question, can I add a GameObject prefab to a job?

low tangle
#

not exactly no

#
Zero Wind :: Jamie Wong

One of the techniques used in many demo scenes is called ray marching. This algorithm, used in combination with a special kind of function called "signed distance functions", can create some pretty damn cool things in real time.

wary anchor
low tangle
#

yep the bunnys one is good too

wary anchor
#

I've been reading up and watching videos about ray marching. It looks amazingly useful and very very appropriate, but it's not something I have any experience of in practice yet

low tangle
#

yeah its a whole different can of worms compaired to ecs and stuff

#

the funny thing is you could very much make these and trace them in a ecs system

#

I wrote a full path tracer in ecs w/ jobs

wary anchor
#

I can see it from the shader perspective (no need to modify any meshes to get nice smoothed joins)

low tangle
#

burst was stupid fast

#

yep

#

basically you cover both your high quality rendering, and the inital how do I even render this data in one go

wary anchor
#

and if it's already in the job system, it also gives me easy access to surface point data per atom which I can use for environment spawnpoints and the like

low tangle
#

hm

#

oh, the atom data is also a point cloud too

#

I've seen stuff on meshing point clouds

wary anchor
#

Hmm is exactly what I've had written on screen for a bit

low tangle
#

thats totally marching cubes

#

oooh this one looks promising

#

oooh I need to save this for myself for later

wary anchor
#

so before I get overwhelmed with the magnitude and complexity of the task ahead of me...
I haven't done any C++ for a very long time. How possible is it to come up with something within C#/ECS to do this kind of job? Do I actually just need to take a couple of weeks out to learn how to write shaders first?

low tangle
#

its pretty easy to transfer c++ logic to c#

#

almost trival

wary anchor
#

though it'll all be on the CPU rather than GPU of course

low tangle
#

yeah, but its mesh generation, so the final result doesn't have to change

wary anchor
#

true

low tangle
#

I can't tell you if its a good idea to go with that kind of route at all

wary anchor
#

unless it's not mesh generation and I just go all in for the raymarching for rendering as well

low tangle
#

I would personally attempt to make either marching cubes (which I have before) in ecs and try to mesh that voxel data

#

yeah, you pay for that in having to learn all about shaders, sdfs, raymarching, and the performance you now have as a baseline on the gpu

#

that second one has way better surface results than marching cubes, but its much more complex

#

poisson surface

wary anchor
#

I did something before in OOP which I now think may be close to marching cubes... I made a voxel grid around the protein, then marked each voxel as being inside or outside an atom, then worked out which face of that voxel was an in-out boundary, then made a mesh on that face, then distored the mesh to match the nearest atom surfaces

low tangle
#

I'm also not sure on how high res your voxel data

#

yeah thats pretty much a simple voxel mesher

wary anchor
#

it was the product of me working without guidance for a long time, but it seemed to work well. I'm sure it's VERY basic compared to the more sophisticated things out there. It wasn't without errors when I ramped up the resolution

#

although it did give me a continuous surface

low tangle
#

yeah you could basically continue that with guidance if you would want to?

wary anchor
#

Okay I need to read up on SDFs and how to generate/structure/use them. I can't put this off any longer I think. Thanks again @low tangle . Every time I come here you challenge me indirectly to learn a whole chunk more stuff than I'd originally planned to learn. It's great. ๐Ÿ™‚

#

Oh I would LOVE to have guidance ๐Ÿ˜„

low tangle
#

sounds good ๐Ÿ‘๐Ÿป

wary anchor
#

I've been working alone in my dining room on a piano stool for the last nearly 4 years

#

I mean, I've had toilet breaks

low tangle
#

haha

#

well I'm always here to help

wary anchor
#

k awesome, thanks again. I'll need to read more just now so I understand precisely what it is I'm trying to achieve.

low tangle
#

sdf / sphere ray marching to directly view the atoms on the gpu or
mesh the atom structure by treating it as voxels, or a point cloud, producing a mesh

wary anchor
#

you mentioned you wrote a path tracer in ecs with jobs, is that somewhere between the two?

#

I mean clearly it's not #1 tho

low tangle
#

not exactly related but related to raymarching

#

it replaces the unity renderer

wary anchor
#

Hmm. Yeah I'm going to need the unity renderer for most things, but for the atom structure a shader that uses raymarching would be the best possible solution. Whether I can achieve it would be another matter

#

but then that would beg the question, how do I actually achieve what I set out to: a set of surface data within ECS that I can use for gameplay purposes

low tangle
#

voxel mesh it imo

wary anchor
#

I can do that.

#

No reason why I couldn't later add in a ray marching shader and use that instead for rendering, but still use the meshed data for gameplay with ECS. Yes. Makes sense!

low tangle
#

very true

#

might even be able to use it as a proper mesh collider too

#

it would be a enclosed volume

wary anchor
#

Ooh because I would have the SDF

frosty siren
#

Ahgh, so hate memory layout changing after Create/Destroy entities. I really want to have a method that just return next Entity and schedule create/destroy.

public static void FakeMemory(Entity entity, MemoryType memoryType, int factionIndex)
{
    //Memory access
    var memoryCategoryEntity = GameInfo.entityManager.GetBuffer<MemoryCategory>(GameInfo.factionsECS[factionIndex])[(int)memoryType].entity;
    var memoryBuffer = GameInfo.entityManager.GetBuffer<Memory>(memoryCategoryEntity);
    var memoryArr = memoryBuffer.AsNativeArray();

    var index = IndexOfMemory(entity, memoryArr);
    if (index != -1)
    {
        //Instantiate entity and write returned entity to memory
        var fakeEntity = GameInfo.entityManager.Instantiate(entity);
        memoryArr[index] = memoryArr[index].Faked(fakeEntity);
    }
}

This code cause an error that said that native array is deallocated because memory layout has changed.

mint iron
#

AsNativeArray maintains the same safety as the original and points to the same data so you're not gaining anything here by using it.
EntityManager.Instantiate creates a sync point and so all jobs are completed and all arrays are invalidated. If you want to still use that array you could use ToNativeArray(Allocator) and then you're working with a copy of the data. That strategy works fine if you're only reading it but since you're updating it, you'd have to copy put it back into the DynamicBuffer.

#

GameInfo.entityManager.GetBuffer<Memory>(memoryCategoryEntity)[index] = memoryArr[index].Faked(fakeEntity); should be able to write with a new buffer wrapper after the sync

mystic mountain
#

Is it a valid approach to have like lookup HashMaps through singletons to find entities through IDs(integers)? My problem is regarding networked objects to parent and other things.

mint iron
#

curious how are you storing them on the singletons? in a component or buffer or something else?

vagrant surge
#

@mystic mountain very common thing to do

#

hashmap from YourID to EntityID

frosty siren
#

@mint iron i read somewhere that accessing through NativeArray is better for burst or something.

mint iron
#

iv'e heard that too, supposedly there are additional optimizations that are hardcoded on burst compiler if you're using a NativeArray. Worth considering when you're at the stage of needing to optimize burst jobs.

coarse turtle
#

hmm, does anyone know where Unity declares the size of the chunks?

prisma anchor
#

Is there a way to say this inside a job?


            if (EntityManager.HasComponent<FirearmData>(data.FirearmEntity)) {
                var firearmData = EntityManager.GetComponentData<FirearmData>(data.FirearmEntity);

                firearmData.IsFiring = Shoot;

                EntityManager.SetComponentData(data.FirearmEntity, firearmData);
            }
frosty siren
#

@prisma anchor u can use chunk.Has<T> inside IJobChunk. If your problem is using HasComponent<T>(Entity)

prisma anchor
#

Well yea, its using the entitymanager in a job. which is a ref type. ok ill give that a go.

frosty siren
#

List of changes for Job
EntityManager.HasComponent<T>(Entity) -> Chunk.Has<T>()
EntityManager.GetComponentData<T>(Entity), EntityManager.SetComponentData<T>(Entity) -> Chunk.GetNativeArray(ArchetypeChunkComponentType) and then work with it; ComponentDataFromEntity<T> for randomly access

prisma anchor
#

Thanks! Tony!

frosty siren
#

I didnโ€™t fully look through your code, so I made changes to the text, sorry for that

mint iron
pliant pike
#

interesting thanks, I've been wondering about using splines with jobs for a future project

mystic mountain
#

How does blobAssetsReferences work? Could I have for e.g. lists n' reference types within one?

coarse turtle
#

Yes

#

I believe so

frosty siren
#

Why JobComponentSystem doesn't have PostUpdateCommands?

coarse turtle
#
struct ListRefWrapper {
  public IList<some_type> WrappedList;
}


// Create a BlobAssetReference<ListPtr> for a naive implementation
struct ListPtr {
  public BlobPtr<ListRefWrapper> Ptr;
}

@mystic mountain

#

@frosty siren, I think their design methodlogy is to use EntityCommandBufferSystem that belongs to your respective UpdateGroup and create a EntityCommandBuffer to playback yourself (you can always playback the command buffer on the main thread too)

amber flicker
#

to add to that - I think it's because you'd have to wait for the job to be complete and thus you'd have no idea when it would execute.. so by using a command buffer you can be explicit

frosty siren
#

yeah i know, but PostUpdateCommands is comfortable

#

@amber flicker ok, this is what I did not think about

#

EntityCommandBuffer.Concurrent always returns null Entity when call Instantiate. Am i right?

amber flicker
#

I'm not sure (I haven't checked) but I could believe it. May possibly have to fill a nativequeue instead. That or add an additional component to created entities (I use this) that a system processes.

#

then at end barrier remove the component (bulk change to archetype = v cheap)

frosty siren
#

yes, i'm going to set components and use reactive systems but the little problem is i need access the same data twice this way and accessing is not so fast

amber flicker
#

possibly fill a nativequeue instead then I Iguess

#

then you can deque, instantiate and set what you need to

frosty siren
#

Doesn't matter what to use it's means that i will need to access data twice. I store categories in dynamic buffer which is entities that represents an arrays of some data (also implemented with dynamc buffer). Accessing data looks like
DynamicBuffer<Data> dataDB = category_BFE[categoryEntity][categoryIndex];
To minimize using BufferFromEntity i map all i need to NativeMultiHashMap. When i iterate through hashmap i want sometimes create/destroy entities and always need to modify dataDB (Data contains entities). And of course i want to use it inside parallel job. So using deffered create/destroy entities leads to iterate through hashmap in mainthread.

amber flicker
#

but if you want to create/destroy entities then no matter what you do, that needs to happen on the main thread right?

#

all command buffer or postupdate is doing is delaying until it runs on main thread

#

perhaps I'm misunderstanding something

frosty siren
#

Yes, work with entitiy must be on the main thread, but i want so much mechanism that will just return the valid Entity inside job)

#

to avoid all this extra data flow

amber flicker
#

I'm not sure I understand... it couldn't know in the job what the entity that was going to be created is right? Also, populating a nativequeue is pretty much a similar amount of code to writing to the command buffer no?

frosty siren
#

Yes, but after entity creation i just need to write returned Entity in dynamic buffer, that's it. And only to do it i need to populate queue/schedule ecb/use reactive system. I mostly complain, hoping that I donโ€™t know any easy way

amber flicker
#

Question about buffers - is the only way to write to a buffer to use BufferFromEntity? I was operating under the assumption that an entities buffer and it's contents will be loaded into the cache line when processing an entity but this makes me wonder - does anyone know?

safe lintel
#

there are IJobForEach with buffer variants

amber flicker
#

Re-reading the docs it does look like the memory is reserved in the chunk. Iโ€™ll take a look at ijobforeach and see what it uses (Iโ€™m using Ijobchunk)

#

At least the initial size anyway

mint iron
#

The default reserve amount is quite low, but if you add the attribute and set it explicitly then you can make things fit in the chunk. Otherwise, when it overflows it allocates elsewhere on the heap and the component just has a pointer out to it.

#

BufferFromEntity is essentially a wrapper for the typeIndex, version and safety. When you use it, it follows the pointer into EntityComponentStore. Which is basically the same as using EntityManager.

So I'd be curious to learn more about how cachelines work because that sounds to me like every access is jumping through at least a few methods/pointers, and doing a costly second type lookup for IndexInChunk (looping through every component type) then calculating the needed offsets. But it doesn't sound in the same ballpark as iterating a sequential block of data like in an array.

amber flicker
#

Hmm a lot of my refactoring is to avoid the cache miss - at least for very small sized buffers - if it fits within the chunk I hope it's avoiding some rand access?

vagrant surge
#

@amber flicker you dont have to overexcess so much that everything is perfectly cache friendly

#

even if stuff is a bit out of order, if your data is all in contiguous arrays and its predictable, it will be fairly fast

amber flicker
#

hmm.. I think it is actually hitting my perf quite bad. If I iterate e.g. 100k items my system takes e.g. 1ms. If I add in a line that indexes a NativeArray, that jumps to about 4ms. My assumption was that was due to the cache misses. I can't think of any other reason indexing a float in a NativeArray would add so much time?

vagrant surge
#

well man, 100k is a LOT of items

amber flicker
#

for sure

vagrant surge
#

have you thought of paralelizing it more, or just dont calculate 100k every update? like one quarter every update

#

but 100k indexes into a native array are slow. maybe the safety features are hitting you?

amber flicker
#

It's not that it's too slow, it's that I think it could be like 3x faster

vagrant surge
#

im pretty sure ive done random access into one array from indices in other array much faster than 100k per 3 ms

mint iron
#

you could try to access the buffers from an IJobChunk

    public struct MyChunkBufferTest : IJobChunk
    {
        public ArchetypeChunkBufferType<SelectionBufferData> SelectionBufferDataType;

        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var bufferAccesor = chunk.GetBufferAccessor(SelectionBufferDataType);
            for (int i = 0; i < bufferAccesor.Length; i++)
            {
                var buffer = bufferAccesor[i];

                for (int j = 0; j < buffer.Length; j++)
                {
                    var bufferItem = buffer[j];
                }
            }
        }
    }
vagrant surge
#

so something is amiss?

amber flicker
#

yea accessing like that works but you can't write using a buffer accessor right @mint iron ?

mint iron
#

i havent tried to write with it, but it gives you a DynamicBuffer<T> for the entity so i dont see why not

amber flicker
#

@vagrant surge take those numbers as very approximate - they're actually for looking up a nativearray<struct> where the struct has a few floats and a bool in

#

@mint iron the accessor seems write only to me when I try

#

*readonly

vagrant surge
#

even if its random access, the cost looks too big i think

#

what are you doing once you access it? the cpu can pipeline the memory access if its array into array

amber flicker
#

well.. I comment in/out the line and those are the differences I see in a build attached to editor

vagrant surge
#

im guessing all of the burst build options and the like are enabled?

amber flicker
#

yea

vagrant surge
#

then i dunno

amber flicker
#

I can try and make a simple repro

#

but I'm not that surprised tbh

#

a lot of speed comes from the linear memory layout and cache right? If I add a random access in every loop...

mint iron
#

it passes the readonly setting from the ArchetypeChunkBufferType, so i'm thinking u can do GetArchetypeChunkBufferType<T>(false). Guess i could test it.

vagrant surge
#

@amber flicker not really. Lots of it come from predictability and instruction caching

#

each CPU core is pipelined inside itself

#

it can overlap memory loads and other operations

amber flicker
#

hmm maybe it's not that I can't write and that I'm just not sure how to set an element? haha... I can buffer[i].Add() but I can't seem to do buffer[i][n] = ..

#

Cannot modify the return value of BufferAccessor<myBufferElement>.this[int] because it is not a variable

coarse turtle
#

maybe not the best idea, but maybe memset might be able to do? I imagine you can just grab the ptr address, increment it and then set it using that call

mint iron
#

yeah because it returns a copy/value you'd need to buffer[i] = new or use the ptr to make a ref

amber flicker
#

hmm but Property or indexer BufferAccessor<myBufferElement>.this[int] cannot be assigned to -- it is read only so buffer[i] = new doesn't work

#

bit surprised to have to use memset? Is it safe (other than the usual NativeDisableParallel and being sure to never write to the same index obviously)

mint iron
#

just a sec, ive got the example working

amber flicker
#

oh nice

mint iron
amber flicker
#

hmmm... this is an asset to be sold.. was really hoping to avoid having to set a project to support unsafe

mint iron
#

๐Ÿ˜ฆ

amber flicker
#

wait.. the 'Normal assignment' works for you?

mint iron
#

yep

#

i checked in entity debugger the count was going up

#

and no exceptions

amber flicker
#

I need to get my head around something... doesn't that for(int i = 0; i < bufferAccessor.Length; ++i) belong within a for (int i = 0; i < chunk.Count; ++i){} loop?

#

oh wait hang on let me re-read

mint iron
#

yeah its a bit confusing, i was thinking the same thing, its because its the same pattern as GetNativeArray<T>() where it grabs the whole chunk.

#
    [BurstCompile]
    public unsafe struct MyChunkBufferTest : IJobChunk
    {
        public ArchetypeChunkBufferType<MyData> SelectionBufferDataType;
        public ArchetypeChunkComponentType<Translation> Translations;
        public ArchetypeChunkEntityType Entities;

        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var entities = chunk.GetNativeArray(Entities);
            var bufferAccesor = chunk.GetBufferAccessor(SelectionBufferDataType);
            var translations = chunk.GetNativeArray(Translations);

            for (int i = 0; i < entities.Length; i++)
            {
                var entity = entities[i];
                var translation = translations[i];
                var buffer = bufferAccesor[i];
                var bufferPtr = buffer.GetUnsafePtr();

                for (int j = 0; j < buffer.Length; j++)
                {
                    // do stuff.
                }
            }
        }
    }
amber flicker
#

yea - I got there ๐Ÿ™‚ thanks!

amber flicker
#

@vagrant surge in my small repro it looks like you're right - not that big a difference... shoot... I need to investigate more.

#

Small aside.. how come I can write ```[BurstCompile]
struct TestJob : IJobForEachWithEntity<...>
{
public NativeArray<TestData> testData;

  public void Execute(Entity entity, int index, ref ...)
  {
           testData[entity.Index] = new TestData() { Test1 = index };
    }

}without testData requiring a [NativeDisable...] attribute? I've been using IJobChunk most places but does IJobForEach provide something extra for parallel writing? Or more likely have I misunderstood what it's actually doing? When I doreturn new TestJob()
{
testData = testData,
}.Schedule(query, inputDeps);``` that's not by copy right?

mint iron
#

it does copy something like 20-30 bytes for the ptr, length, allocator label safety etc but it doesn't copy the actual array data, that stays exactly where it was.

amber flicker
#

cool.. just checking I'm not crazy... any ideas on why it's safe to write to it in parallel? in IJobChunk I'd usually have to add the [NativeDisableParallelForRestriction] tag

mint iron
#

nah not sure ๐Ÿ˜ฆ but IJobForEach is effectively sugar on top of an IJobChunk so you'd think it would behave the same!

amber flicker
#

er maybe I just had the burst safety checks off and that's the difference ๐Ÿ˜…

dire frigate
#

anyone know if there's been updates to the workflow to getting the update method to run in fixedupdate?

coarse turtle
#

none so far

#

that I know of

safe lintel
#

hopefully unite will bring something new

frosty siren
#

Can i store CDFE/BFE inside another struct like and use attributes?

struct SomeJob : IJob
{
    public CDFE_Container;

    public void Execute() {...}
}
struct CDFE_Container
{
    [ReadOnly]
    public ComponentDataFromEntity<C> C_CDFE;
    [NativeDisableParallelForRestriction]
    public BufferFromEntity<B> B_BFE;
}
prisma anchor
#

Does it take several seconds to press play when using Unity Physics v0.2.2 for anyone else?

merry oasis
#

hi all, we're doing some collision detection and resolution a were wondering if Jobs has some sort of Multiple Producer Single Consumer process that we can easily use

#

the goal being that collisions will be processed by the consumer thread as the collisions are being calculated instead of just being thrown in a collection and calculated afterwards

safe lintel
#

@prisma anchor just as fast as it was in previous versions to enter play for me

prisma anchor
#

Hmm. Not doing an accurate count, its like 15 secs for me to actually get in.

#

I just upgraded another project's Physics from 0.2.0 -> 0.2.2. There is a noticeable slow down.

safe lintel
#

all i can suggest is try to delete the library, if that doesnt work sounds bug report worthy

slow epoch
#

Is there any site to check for ecs changes?

#

It's been a while since i've used it and i dunno what changed

dull copper
#

oh wait the samples changelog doesn't really tell much for the ECS changes anymore

#

it used to be super informative about changes in past

slow epoch
#

The first one works, thanks!

dull copper
#

learning from this, I added the DOTS package changelogs to the pinned message on this channel

gusty comet
#

Hello, I started today with ECS and there is something that I dont undestand. If know that I can have x entities, with theis own parameters, but in the moment of the behaviout wont they work the same? Since the system tell to all to do the same

#
    [SerializeField] private Material material;
    private void Start()
    {
        EntityManager entityManager = World.Active.EntityManager;

        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(LevelComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(MoveSpeedComponent)
            );

        NativeArray<Entity> entityArray = new NativeArray<Entity>(5, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entityArray);

        for (int i = 0; i < entityArray.Length; i++)
        {
            Entity entity = entityArray[i];

            entityManager.SetComponentData(entity,
                new LevelComponent { level = UnityEngine.Random.Range(10, 20) });

            entityManager.SetComponentData(entity,
                new MoveSpeedComponent{ moveSpeed = UnityEngine.Random.Range(1, 10) });

            entityManager.SetComponentData(entity,
                new Translation{ Value = new float3(UnityEngine.Random.Range(-8f, 8f), UnityEngine.Random.Range(-8f, 8f), 0) });

            entityManager.SetSharedComponentData(entity, 
                new RenderMesh {mesh = mesh, material = material });
        }
        entityArray.Dispose();
    }```
#

For example with that, they just move up and down

#

how you can tell to one entity to move to the right without doing it to all

mint iron
#

@gusty comet you would know which entity you want to change, and instead of looping through every entity, just do stuff for the ones u want to change... You could isolate an entity by making it have a component that the others don't have. Then you can use GetEntityQuery() to make a query that lets you filter just to entities matching a specific set of components.

tawdry tree
#

Does anyone know of a public game of life/cellular automata sample?
I feel like the techniques used for that would be somewhere in the intermediate range, where we lack good samples.

mint iron
tawdry tree
#

I have already suggested tower defense to several people as a game/genre to try for getting into ECS, as it's mechanically simple.

#

But I was asking specifically about ECS game of life/cellular automata as a sample, becuase I have an idea which would use a lot of the same mechanics

mint iron
#

yeah, and u could ramp up the projectiles/effects the towers shoot and the nubmer of enemies which would be cool

tawdry tree
#

Still not made in Unity ECS, and that's what I'm looking for

#

I have implemented the game of life before

#

Just.... translating that to ECS...

mint iron
#

oh sorry i misunderstood, i thought u were intending on creating some examples

tawdry tree
#

Ah, no, I was asking if anyone knew of an existing one. Though if I do stop putting it off and actually sit down to make something in ECS, I'll be sure to make the repo public

vagrant surge
#

i dont think game of life makes any sense in ECS

#

you implement it on a bitmask usually

#

good use case for Burst tho

grave turtle
#

Hello, what's the proper way to associate an array of matrices with an IComponentData (DynamicBuffer? BlobArray?). The size won't change but I need to read/write from jobs

safe lintel
#

i would assume you would want dynamic buffers for most situations needing arrays

junior moon
#

I'm following some tutorials and in it you make an entity using EntityManager.CreateEntity, but mine returns an error, do we now always need Archetypes?

pliant pike
#

what's the error message?

junior moon
#

'World' does not contain a definition for 'EntityManager' and no accessible extension method

pliant pike
#

how are you using the EntityManager? what's the code?

junior moon
#

it should be the same as the tutorial but its from a few months back so I guess the tut is outdated

pliant pike
#

weird it should work fine like that

junior moon
#

i even tried restart unity ๐Ÿ˜ข

safe lintel
#

are you up to date for your entities package?

junior moon
#

yeah, 0.0.12?

safe lintel
#

latest is 0.1.1

junior moon
#

wait how come I can only see up to 0.0.12?

#

oohhh, nvm...

wooden canopy
#

@prisma anchor in the forums they explained that the slowdown after updating unity physics, is due to the burst jobs used for collider generation being compiled on start instead of on demand, this should improve when they release an updated version of burst that cache compiled jobs

prisma anchor
#

Lol. @wooden canopy That was me who asked the question. Thanks for the follow up!

wooden canopy
#

ups ๐Ÿ™‚

slow epoch
#

Is there any way to load data to an entity like an image or sound without being a gameObject and converting it to an entity?

#

Or being referenced from a singleton monobehaviour

coarse turtle
#

For audio you can store clips in a blob asset, also I'd take a look at their DSP Audio, for images you can also store images too in blob assets

slow epoch
#

Is there any docs about blob assets? I haven't heard of them

unborn bear
#

Does making a job dependent on another freezes the main thread ?

safe lintel
#

@unborn bear that doesnt sound right. @slow epoch theres nothing official afaik, only stuff in the forums if you search or from going through the package code. i think physics might have some good examples, also a file called BlobificationTests.cs might have some info

unborn bear
#

weird, I made a mesh slicer where jobs share the same NativeArray, and for some reason I am having some spikes whenever I perform a cut

coarse turtle
#

@slow epoch take a look at BlobificationTests.cs in the package, it goes over the basic way on how to construct a BlobAssetReference<T> which you can store in a struct as an IComponentData

pliant pike
#

what's the best way to destroy a bunch of entity's? Destroy 1 roughly every 0.2 seconds or wait till they build up and destroy a bunch say every 5 seconds?

safe lintel
#

i think the most efficient way is to destroy using entitymanager taking an array of entities - but whether you really need to go this far for optimizing is another thing entirely

pliant pike
#

yeah I'm using an EntityManager in a component system, I'm destroying entity's when they reach a waypoint individually. So it could happen quite frequently

#

It doesn't seem to be impacting performance that much so I guess it shouldn't matter that much

unborn bear
#

What is the correct way to wait on a job to finish ? I am using a coroutine but it just feels wrong

pliant pike
#

JobHandle.Complete()?

unborn bear
#

that would freeze the main thread because it would force it to wait until job completion

coarse turtle
#

if you need a flag, there's an IsCompleted field

pliant pike
#

yeah if you use the Iscompleted with JobHandle.Complete I think that's probably the best way

#

I don't think it freezes the main thread or anything it just jumps to the main thread

coarse turtle
#

.Complete forces the thread to immediate evaluate

unborn bear
#

Yes, I know that flag. What I mean to ask is: How do you guys wait on a job to complete ? Do you guys use a coroutine OR something else ?

pliant pike
#

yeah you can use it to force the job to only run once or just make sure its completed before doing something else

coarse turtle
#

I just schedule the Job and let Unity's job system handle the completion

#

There's a brief section abt 'Scheduling early and completing late.'

unborn bear
#

then you are basically "freezing" mainthread aren't you ? If you make a job a call complete right after it, you did not run anything a parallel

#

you just processed stuff with a job

coarse turtle
#

me, i very rarely call JobHandle.Complete()

#

I only need to call it if I absolutely need to evaluate something immediately

unborn bear
#

You using jobs with ECS ?

coarse turtle
#

Yes

unborn bear
#

Then that is probably why you have a different perspective. I am using only the job system, no ECS.

coarse turtle
#

Ah, that makes sense - I never really used the JobSystem outside of ECS yet

unborn bear
#

I see. The only way I can think of waiting on a job to complete is whether polling it on an Update function (bad in my opinion) or using a coroutine to do that (better but dirty)

#

I noted some weird gotchas like, making IJobs share the same NativeArray (in other words, make an IJob depend on the completion of another IJob) freezes the mainthread apparently (maybe they call '.Complete' internally ?)

coarse turtle
#

yea, since the entity manager is the one handling the jobs (I'd imagine), they just call Complete() on the job

for (int t = 0; t < m_TypeCount; t++)
    {
        ((JobHandle)(&m_ComponentSafetyHandles[t].WriteFence)).Complete();
        int readFencesCount = m_ComponentSafetyHandles[t].NumReadFences;
        JobHandle* readFences = (JobHandle*)((byte*)m_ReadJobFences + (long)(t * 17) * (long)sizeof(JobHandle));
        for (int r = 0; r != readFencesCount; r++)
        {
            ((JobHandle)((byte*)readFences + (long)r * (long)sizeof(JobHandle))).Complete();
        }
        m_ComponentSafetyHandles[t].NumReadFences = 0;
    }
dull copper
#

that's apparently some vertex skinning for DOTS on HDRP

light sage
#

back at it again, and straight back to ECS at that. Has been a while, did we get Boolean functionality yet or still just using byte vars?

amber flicker
#

Bool is cool now ๐Ÿ˜

low tangle
#

@dull copper oh my god yes

#

might be switching to hdrp

gusty comet
#

Should we avoid using ComponentDataProxy<IComponentData> (is it going to be deprecated, or is there some negative impact on performance)?
I know there's a bunch of different ways you can create entities - I've been using IConvertGameObjectToEntity

low tangle
#

going to be deprecated,
yes
or is there some negative impact on performance
kindof, it didnt scale well in performance or development complexity

#

conversion workflow is the future, its also getting some love soon from what I hear

coarse turtle
#

ooh that's very nice to hear, I'm curious as to what new things they'll add lol

low tangle
#

same

#

I want it

#

please more dots stuff

#

cant get enough

honest dirge
#

Conversion workflow needs a lot of love before it's viable.

vagrant surge
#

but what about being able to... yknow.. click on an object in the editor view and seeing its params

pliant pike
#

or a system being able to see its variables while running would be nice

coarse turtle
#

doesn't the entity debugger already do that? if by variables you mean entities

vagrant surge
#

but you cant find an entity easily by clicking on it in viewport

honest dirge
#

You could write a system that does that if there is a graphic component

#

In theory

tawdry tree
#

As long as it has a position, you could make a crude ray-marching/tracing 'what did I just click at' system

#

Some stuff like that should be standard, I think. Maybe not part of the base package, but a package with some helpful tools for debugging and/or general development of ECS wouldn't be a bad idea.

vagrant surge
#

thats something that baffles me

#

there is tons of stuff they can do that would make ECS usable for development right now

#

but they dont

#

makes me think that the ECS team is just Mike Acton and 2 friends

low tangle
#

hey man I've built my whole game on ecs

#

its rough but doable

#

that debugger is more than enough info imo

#

but its getting worked on, just gotta wait another week for their anouncements

tawdry tree
#

What kind of game is that by the way? Like, genre and stuff. ECS fits certain types of games better than others...

low tangle
#

vr sandbox

#

user ran content

safe lintel
#

im surprised they dont have rough data modifying on the entity debugger

#

really need some enterprising individual to make an asset store ecs inspector ๐Ÿ™‚ get in on that early user cashflow!

coarse turtle
#

lol, potentially get hired by unity to build the editor ๐Ÿ˜‰

safe lintel
#

win win scenario

low tangle
#

too much work otherwise I'd be making more ecs stuff

#

I'm looking to just open source all my stuff in the end though

#

ecs is too good not to share

coarse turtle
#

same except just a module of it

#

been working on making a 'primitive' UI system cause uGUI is a bit jittery

low tangle
#

yeah UI is one I really want to port to ecs soon

#

I've gotta make it vr friendly though, in world

#

so far the two ecs UI's I've seen were 2d in screenspace

#

uGUI sucks imo

coarse turtle
#

ah, which UI's were they, if you still remember?

coarse turtle
#

ah very cool, I'll look into it for a bit

low tangle
#

๐Ÿ‘Œ๐Ÿป

light sage
#

most still doing hybrid, or is pure more feasible yet?

#

guessing a lot has been moved behind the scenes on a lot more of the standard tools/compilation and especially the newer packages

wanton girder
#

Hi, I have a question about what is destroyed when a gameobject is destroyed. Suppose I create an instance of a non-monodevelop class in a component (therefore create with new), then store a reference to that instance in a second component. If I destroy the first component that created that instance, would it destroy the instance as well?

#

My suspicion is that in this case only references to the created instance would be destroyed in the destroyed component and it would be GCed later if there were no references to it. Just need confirmation from the enlightened.

dull copper
#

I removed hybrid for now, it is always breaking with bleeding edge HDRP api changes and it doesnt work at all with DXR

mint iron
#

i can understand your frustration, im using hybrid with LWRP and its broken in a different way with pretty much every editor version since 2019.3.0a8 (like 8 versions ago). There's always packages trying to access editor API functionality that no longer exists or doesn't exist yet.

#

so you have to trial and error to find the magical package version soup that works, but then each package brings its own bugs that mess you up in other ways.

dull copper
#

I can fix the HDRP API changes from the hybrid package (done that many times), but fixing raytracing is like totally another level thing ๐Ÿ˜„

#

that could like require engine level changes

mint iron
#

@wanton girder a non-UnityEngine.Object class exists independent of where it was created, so generally it will be kept alive as long as there is a reference to it somewhere. I say generally because unity's garbage collector is different than normal .net GC. I am not certain it won't do something weird like take a while to figure out it can dispose of it.

If you have a GameObject that has 2 components, both referencing the same instance of foo; then you remove the first component. It will still exist because the second component holds a reference to it.

UnityEngine.Object derived classes act a little differently in that the class will start resolving to Null when it gets destroyed on the Native side regardless of if you have references to it.

worn stag
#

anyone has an example of conversion scriptable object to blobAsset?

coarse turtle
#
public class Bucket : ScriptableObject {
  // some data here
}

public struct BucketWrapper { public Bucket Bucket; }

public struct BucketPtr { public BlobPtr<BucketWrapper> Ptr; }

public struct BucketBlob : IComponentData { public BlobAssetReference<BucketPtr> Blob; }

// The func that will create the blob
public void ConstructBlob() {
    var builder = new BlobBuilder(Allocator.Temp);
    ref var root = ref builder.ConstructRoot<BucketPtr>();

    ref var wrappedBucket = ref builder.Allocate(ref root.Ptr);
    wrappedBucket.Bucket = some_scriptable_object_of_type_bucket;

    var blobAsset = builder.CreateBlobAssetReference<BucketPtr>(whatever_allocation_type_you_want); // Mostly you'll want a persistent one instead
    builder.Dispose()
    return blobAsset;
}
#

when you destroy the entity with the blob, you'll likely want to release the blobassetreference too unless you're managing the ptr yourself externally

worn stag
#

thank you

prisma anchor
#

Hi Everyone, I had a question. If I want to represent a ring buffer of IComponentData, how do I represent that? i.e

SnapShot : IComponentData {
int tick;
int[] createEntityIDs;
int[] updateEntityIDs;
int[] deleteEntityIDs;
}```

on the client & server i need to store an array of these 'Snapshots`. Would I make another component simply storing this data?
coarse turtle
#

You can likely store them in DynamicBuffers, b/c you can't store managed types in IComponentDatas

mint iron
urban rivet
#

Where are we with ECS these days? Is it likely to be changing much from this point?

slow epoch
#

You should wait a bit for the copenhagen

#

It's the next week

#

And i'm sure they'll announce new features

trail burrow
#

@urban rivet you going to unite? ๐Ÿ™‚

trail burrow
#

@dull copper i see ur going to unite

#

how did you get ur fancy tag?

dull copper
#

it has instructions

#

are you going too?

trail burrow
#

i am

#

so now i have to spend 4 days trying to avoid you... ish ๐Ÿ˜„

#

โค

dull copper
#

yeah, we've talked online for like 6-7 years without any IRL contact, why ruin it now ๐Ÿค”

trail burrow
#

@dull copper exactly

#

there we go

#

someone gets it

#

๐Ÿ˜„

dull copper
#

to be serious tho, I'm kinda worried about not being the anonymous guy, I like keeping some distance to my online "personality"

trail burrow
#

@dull copper yes same

#

i prefer to stay in the shadows ๐Ÿ˜„

low tangle
#

its weird at first but its nice after the inital wears away

#

at least you already have something in common :^)

urban rivet
#

@trail burrow couldn't make it this year. Unity was really kind to extend an invite too

trail burrow
#

ah ๐Ÿ˜ฆ

#

sadface

urban rivet
#

I probably won't come until I've got some headway done on my game out of sheer procrastinatic embarassment tbh

#

haha

#

can't turn up red faced without a decent demo!

low tangle
#

wheres that game ;)

tawdry tree
#

Clearly not here, since hippo's nowhere to be found ๐Ÿ˜›

low tangle
#

๐Ÿšถ๐Ÿป ๐Ÿ’จ

pliant pike
#

I dont suppose anyone knows why if I use the below code then the whole system just dissapears or destroys itself

#
public class CountRobotsatWaypoint : ComponentSystem
{
    public Entity countent;

    protected override void OnCreate()
    {
        if (!EntityManager.Exists(GetSingletonEntity<CountRobots>()))
        {
            countent = EntityManager.CreateEntity(typeof(CountRobots));
            EntityManager.SetName(countent, "CountRobots");
        }
        else
        {

        }
    }
tawdry tree
#

Systems will disable when they have no more 'targets', if that's the entire system then they'd detect 'oh well, nothing more for me to do here' and disable it.
I think it was [AlwaysUpdateSystem] which stops that behavior. The ondisable or whatever method can be useful for figuring out when it happens.

pliant pike
#

that's not all the code I have a foreach loop as well, which seems to activate after but then the whole thing just disappears

#

its not even disabled its like the whole system is destroyed, its really weird behaviour

#

and using AlwaysUpdateSystem doesn't work

safe lintel
#

is there anything in the update loop for the system to actually work on?

pliant pike
#

yep, I'll post the whole code maybe that will help

safe lintel
#

also if you stick something in like Debug.Log("test"); before the update foreach does it force it to run?

pliant pike
#
[AlwaysUpdateSystem]
public class CountRobotsatWaypoint : ComponentSystem
{
    public Entity countent;

    protected override void OnCreate()
    {
        //if (!EntityManager.Exists(GetSingletonEntity<CountRobots>()))
        //{
            countent = EntityManager.CreateEntity(typeof(CountRobots));
            EntityManager.SetName(countent, "CountRobots");
        //}
        //else
        //{

        //}
    }

    protected override void OnStartRunning()
    {       
        //if (!EntityManager.Exists(GetSingletonEntity<CountRobots>()))
        //{
        //    countent = EntityManager.CreateEntity(typeof(CountRobots));
        //    EntityManager.SetName(countent, "CountRobots");
        //}
       
    }
    
    protected override void OnUpdate()
    {

        Entities.WithAllReadOnly<ToCurrentWaypoint>().ForEach((ref ToCurrentWaypoint dude) =>
        {
            if (dude.value == 1)
            {
                if (HasSingleton<CountRobots>())
                {
                    var countem = GetSingleton<CountRobots>();
                    countem.value += 1;
                    Debug.Log("Why is this not working");
                }

            }

        });
    }    
}```
tawdry tree
#

Does any entities with ToCurrentWaypoint exist?

pliant pike
#

yep

tawdry tree
#

Hm, weird

#

And the force update...

#

Sounds like you might have struck a bug, or at least a edgecase that should have a warning or documentation

pliant pike
#

I have to have some way of checking that CountRobots exists because if I did it in Onrunning then it created 2

safe lintel
#

i mean stick the debug before the ForEach and if it shows in the debugger as running, double check that the system does or doesnt have entities to process

tawdry tree
#

Theoretically those entites could lose their components or be destroyed, though, are they still in the entity debug menu thingy?

amber flicker
#

just to say, the way it looks to me, if (HasSingleton<CountRobots>()) should be outside the Entities.WithAll anyway no? You wouldn't want to check it for each entity

#

unless you create it in the loop or something I guess

tawdry tree
#

That's a good point too, a singleton check should definitely be outside of any loops (unless, as you said, the singleton might be created/destroyed in the meanwhile)

pliant pike
#

yeah good point

#

and the DebugLog works, it slows it down like hell

tawdry tree
#

Then it sounds like aggressive optimization from the system-system (whatever keeps serial killing innocent systems)

amber flicker
#

It might just be a lambda thing they don't yet support?

pliant pike
#

yeah I'll post it as a bug for the Unity devs see what they say

coarse turtle
#

You can also do RequireSingletonForUpdate<T> in OnCreate

pliant pike
#

It seems like I've found another bug, for some reason OnStartRunning is run twice

#

its effecting another system, making it run way to long and not in the way I want

#

I don't know if I'll use a singleton you have to use SetSingleton to set it and I'm not sure if that works for what I want

mint iron
#

you have to be careful with OnStartRunning because every time a system is not run because of RequireForUpdate or from the queries used it will cycle both OnStartRunning OnStopRunning again. So you really can't use it for initialization. I've been bitten by that numerous times.

pliant pike
#

the trouble is I cant use OnCreate either as the Gameobjects don't exist or the other system doesn't exist

hollow sorrel
#

it's weird how oncreate runs before monobehaviours, but onupdate runs after monobehaviours

#

or other way around

#

i forget

mint iron
#

i know what you mean, its messed me up where singletons from ConvertToEntity i needed hadn't been created yet in OnCreate ๐Ÿ˜ฆ gets frustrating.

pliant pike
#

yeah I can kind of get around it but the Systems really are confusing how they are run

#
protected override void OnStartRunning()
    {
        if (MoveWaypointslist.Length != WaypointGameobjects.Length)
        {
            WaypointGameobjects = GameObject.FindGameObjectsWithTag("Waypoints");
            for (int i = 0; i < WaypointGameobjects.Length; i++)
            {
                var tempwaypoints = WaypointGameobjects[i].GetComponent<Transform>();
                var someotheval = (float3)tempwaypoints.position;
                MoveWaypointslist.Add(someotheval);
            }
        }

    }```
#

that seems to fix it for now

coarse turtle
#

hmm just my curiousity

#

is it possible to just have a gameobject with a list of points, convert it and add the list of points to a buffer on an entity

#

is it possible to just have a gameobject with a list of points, convert it and add the list of points to a buffer on an entity

mint iron
#

yep

pliant pike
#

yeah of course

coarse turtle
#

I think the caveat is you'd have to write some scene view tools if you wanna edit them in editor time

mint iron
#

yeah it woudl be more complicated if you wanted to keep them in sync or edit the entities directly from handles or something

pliant pike
#

that's what I'm basically doing except they are separate gameobjects and I'm adding them to a list instead

coarse turtle
#

yea, jw

pliant pike
#

Does anyone else here use Rider? Does anyone know if it's worth using?

coarse turtle
#

I tried it for a bit, it's certainly nice with a ton of features

#

local history view seems to be really nice for a lot of ppl

#

but the problem I had was that it slowed down a lot for me trying to query a lot of things i just ended up sticking with omnisharp + vim

pliant pike
#

leahT I guess its worth trying, a guy is giving out free promo codes for six months

coarse turtle
#

haha yea, i'd certainly give it a shot, it takes some time getting used to the hotkeys it has

pliant pike
#

if anyone else is interested

amber flicker
#

@pliant pike just in case you didn't know, in OnCreate you can use GetOrCreateSystem<> and if the system doesn't exist at that point, it will create it then and there. If you require that system to have run, then possibly you want your second system to require a Created component or something to be present on the entities you want to change. There are also [UpdateInGroup] attributes to specify order of systems where needed.

pliant pike
#

Oh ok, thanks @amber flicker

gusty comet
#

Edit: Figured it out, problem with other system, not with input system

coarse turtle
#

Might be this issue here

PlayerInput input = inputs[j]; <- this might be a copy of inputs[j] which means that you're not modifying what's in the chunk
gusty comet
#

yea but in the end I'm writing to inputs[j]

coarse turtle
#

oh totally didn't see that

gusty comet
#

so basically that's the only line I'm confused about, since the debug.log is firing correctly when there is input

coarse turtle
#

hmm, it's the only system modifying the input right? you dont have a separate system zeroing it out immediately after I assume

gusty comet
#

I have another system which is ReadOnly accessing it

#

This is not using a job, so I'm less familiar with how to handle it

coarse turtle
#

same here ๐Ÿค”

gusty comet
#

maybe there's some sort of timing issue going on, since the other system is using a job

#

๐Ÿคท

coarse turtle
#

GetArchetypeChunkComponentType<PlayerInput>(false); <- false means you can read/write right?

gusty comet
#

yea

coarse turtle
#

hmm, ๐Ÿค” yea i wouldn't know till I try it out, srry

honest dirge
#

Does anyone have any thoughts why modifying Translation component before CopyToGameobject runs would cause so much jitter?

prisma anchor
#

@coarse turtle & @mint iron thanks for the info

gusty comet
#

@coarse turtle I figured out what was happening.
The Input system was doing it correctly and the chunk was updating.
In my movement system, I was switching from Translation + Rotation to LocalToWorld. However, I had left the old Translation and Rotation archetypes in the code (I had added LocalToWorld to the query as well), and there's a catch
https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/transform_system.html
User code may write directly to LocalToWorld to define the transform for an instance, if no other transform components are associated with the same entity.So after I completely removed the Translation and Rotation archetypes from the query and job, everything started working (it's confusing, since you can still see those types on the entity in the entity debugger....)

#

I guess the documentation means you can write to LocalToWorld as long as no other transform component is part of your query/job

coarse turtle
#

Ah makes sense

slow epoch
#

I have a design question, if i'm working in a Console system with commands and stuff. I suppose the Console itself is a system and the commands are IComponentData, but where is the logic shared with a given command?

#

Can a component store logic and that logic be executed by a system?

mint iron
#

a component could contain logic, but its sort of against the concept of having a clear data/logic separation.

slow epoch
#

What about having a delegate in the Component and executing that delegate inside a system?

mint iron
#

Sounds dubious, can you tell us more about what you're trying to accomplish?

slow epoch
#

A Console system like CSGO where you write commands and does stuff

#

And i still get problems designing for ecs

#

I don't know if it's about not having enough tools still for ecs or that i don't know how to approach it

mint iron
#

I assume you'll have a lot of different commands, so having a different system for each command would not be practical. Leaving you with switching somehow within a single system.

#

You could do a different component per command, or have a type within a command component.

#

The logic is still in the system, the component contains whatever info is needed to complete the command.

slow epoch
#

Yeah, the game is gonna be based on the console and i can end up having hundreds of commands

#

So a system per command is not an option

mint iron
#

A simple approach would be to have a different component for each command, and different IJobForEach<MyCommand> for each one. Then the job becomes the container of your command specific logic.

#

But im not sure how that will scale if you're having hundreds of them.