#archived-dots

1 messages ยท Page 32 of 1

rotund token
#

it's just an IRateManager

#

that you can attach to a system group

#

just like how FixedStepSimulationSystemGroup works

whole gyro
#

Is there any way to query for entities that have a disabled component?
I know we can use EntityQueryOptions.IgnoreComponentEnabledState to ignore the enabled bit, but can we query specifically for the entities that have the component disabled?

rotund token
#

yes

#

use the EntityQueryOptions.IncludeDisabledEntities in the query

#
            {
                All = new[] { ComponentType.ReadOnly<MeshLODComponent>() },
                None = new[] { ComponentType.ReadOnly<RootLODWorldReferencePoint>() },
                Options = EntityQueryOptions.IncludeDisabledEntities | EntityQueryOptions.IncludePrefab
            });```
#

some random example (also querying prefabs)

whole gyro
rotund token
#

oh

#

well exactly what i said

#

except IgnoreComponentEnabledState

#

๐Ÿ˜„

#

well hmm

#

it will be boht disabled/enabled

#

do you just want disabled ones?

whole gyro
#

yeah exactly

#

just the disabled set. I know its a weird thing to ask, but wondering if it is possible

rotund token
#

sorry haven't really played with it enough yet (at all) to know

#

i know you could totally check the state yourself easy enough in a ijobchunk

viral sonnet
#

i didn't find this out either. haven't needed it but just a question that cropped up

#

tertle, from docs: var tick = GetSingleton<NetworkTime>().ServerTick;

whole gyro
#

yeah I was wondering that. Thought I saw something about IJobChunk having to check enabled flags yourself. I don't use IJobChunk myself, but I guess I could. Mainly wondering if it is possible in an IJobEntity or just a manual EntityQuery.

rotund token
#

that's the new singleton for tick rate (you used to have to get the systemgroup to read it, one of my pain points of updating)

viral sonnet
#

do you know how netcode handles tick? is it in a singleton?
that was my question ^^

rotund token
#

oh i thought you wanted to know how it actually ticks

#

not how to read the settings

viral sonnet
#

interesting that they use a singleton. that's really the new thing now. previously it was just a field in a ClientSimulationSystemGroup/SimulationSystemGroup

rotund token
#

yeah but they don't exist anymore

#

and well obviously don't work well in ISystem

#

netcode has always been about the singletons though

#

so many of them

viral sonnet
#

netcode is really the best project to see all changes in action ๐Ÿ˜„

#

i have stopped with netcode 0.6

#

kind of want to wrap my head around the unity dev statement to sometimes use static in favor of singletons. i don't really see it ^^

#

at least not with ISystem and Burst ๐Ÿ™‚

#

is there a faster version than my 2 lines? ```state.EntityManager.CreateEntity(typeof(LoadSpells));

var loadSpellEnt = state.EntityManager.CreateEntity();
state.EntityManager.AddComponent<LoadSpells>(loadSpellEnt); ``` first line uses ComponentType[] which doesn't work with burst

rotund token
#

well the archetype version is going to be better

#

if you cache the archetype in oncreate / outside burst

viral sonnet
#

ok. do you know why typeof in general is not supported for burst?

#

is it because it can't make sure that the type is unmanaged?

rotund token
#

typeof returns Type
Type is always managed

#

public abstract class Type : MemberInfo, _Type, IReflect

viral sonnet
#

oh never realized

drowsy pagoda
#

Not quite sure what's going on here. Bug?
I have a simple Physics Shape dynamic body that spawns on top of static physics shape "floor". The physics works as expected. However, when I go to click on anything in the Entities Hierarchy, the dynamic body "slips" below the floor and starts falling into the abyss. This happens with and without Live Baking turned on.

rotund token
#

seems to be a common complaint in forums

#

do you have subscene open?

#

i believe it's probably because the physic colliders is created in the baking systems not from bakers

drowsy pagoda
#

Woah for real? That's annoying. Yes, I have subscene opened, and I have both dynamic and static bodies authoring GOs loaded with PhysicsShapeAuthoring and PhysicsBodyAuthoring.

#

Is there a common solution to this as well? Or this just a bug waiting for patch?

rotund token
#

close your subscene is really only solution as far as i'm aware

#

which isn't really a solution

drowsy pagoda
#

yeah...

rotund token
#

that said i pretty much never open my subscenes at runtime which is why i never had this issue

#

and wasn't sure for ages what people were complaining about

#

tried to repo it all sorts of ways

drowsy pagoda
#

lol

#

can you send me the link for the forum where this is mentioned? I'd like to jump on that train ๐Ÿ˜‰

rotund token
#

in 0.51 i actually had a script that would not let me enter play mode if a subscene was open

#

broke things - but i finally worked around that

rotund token
drowsy pagoda
#

thx

brave field
#

@proud jackal How to extend idomatic foreach parameters limit without using aspect?

gusty comet
#

If a system does stuff like Raycast queries against PhysicsWorldSingleton, does that system have to have an attribute like [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]? My systems are randomly getting "nothing hit" for raycasts, and they update in the normal Simulation group

rotund token
#

They do not

#

But realise it will only update in fixed step simulation

gusty comet
#

Thank you. Any idea why raycasts would randomly fail despite succeeding with barely different start and end points? I have a system constantly raycasting from y=500 to y=-500 with a huge flat cube 1 unit tall and 100 on each side, located at y=0

#

The cube has a Physics Body, and its PhysicsCategoryTags match that supplied to the raycast

#

Hmm, are there serious consequences for using CollisionWorld rather than PhysicsWorld or even just PhysicsWorldSingleton?

rotund token
#

PhysicsWorldSingleton just has a reference to PhysicsWorld and CollisionWorld

gusty comet
#

Please excuse the flurry of questions, but also is neglecting to set GroupIndex an issue?

rotund token
#

it should be 0 unless you want to do special things

gusty comet
#

Thank you. I'll keep looking for clues

rotund token
#

this means if your fps > fixed update and you create new objects in update, it might take multiple frames before they enter physics world

#

alternatively if you destroy an entity it might still exist in physics world for multiple frames

gusty comet
#

Useful info! Thanks. I'll keep that in mind

#

In other news, there's this weird behavior where clicking on the "Entities Hierarchy" tab causes the next Raycast to fail

rotund token
#

with open subscenes?

gusty comet
#

Yes

rotund token
#

probably same issue as things falling through ground

gusty comet
#

Ah. So I just close the Subscene/stop editing them before playing?

rotund token
#

yes

#

shouldn't be an issue with closed subscene

#

you can still click them it'll just be entity representation instead

gusty comet
#

Thanks, I'll give it a shot

rotund token
gusty comet
#

Welp, that fixed the issue. Problem is, all the Entity names have reverted to "Entity (x:y)" and since the Subscene takes 1 or 2 frames to load, some of my systems that rely on singletons from that Subscene throw an exception or two

#

Thanks a ton tertle for your support

rotund token
#

i have a script to handle this

#

it basically in OnCreate stops the simulation/presentation systems running

#

until subscenes you've marked as required have loaded

#

then starts running world

#

most people and unity would probably just put RequireForUpdate<T> on the system though

#

but i really dislike that everywhere

#

for a once off wait

gusty comet
#

Thanks again. I think it's better if I brush up on Subscenes first before flooding this channel with questions

#

And yeah I'll try the RequireForUpdate check

deft pilot
#

hmm i feel like i'm missing something from my understanding of how a buffer gets disposed of

#
            Entities.ForEach((in EnemySpawnTag enemySpawnTag, in EnemySpawnComponent enemySpawnComponent, in DynamicBuffer<EnemyPathElement> enemyPathTags) =>    
            {
                var secondTileWorldPosition = enemyPathTags[1].Value.WorldPosition;
                var spawnPosition = enemySpawnComponent.Value.WorldPosition;
                var enemyPrefabs = EntityManager.GetBuffer<PrefabGroup>(prefabGroupQuery.GetSingletonEntity(), true).Reinterpret<Entity>();

                var newEnemyEntity = EntityManager.Instantiate(enemyPrefabs[0]);
                // EntityManager.SetArchetype(entity, this.enemyArchetype);
                EntityManager.AddComponentData(newEnemyEntity, new EnemyPathStepComponent() { value = 1 });
                EntityManager.AddComponentData(newEnemyEntity, new MoveToWorldPositionComponent() { Value = secondTileWorldPosition });
                EntityManager.AddComponentData(newEnemyEntity, new Translation { Value = spawnPosition });
                var buffer = EntityManager.AddBuffer<EnemyPathElement>(newEnemyEntity);
                buffer.CopyFrom(enemyPathTags);
            }).WithStructuralChanges().Run();
#

whats causing the buffer here to throw?

#

ObjectDisposedException: Attempted to access BufferTypeHandle<TowerDefenceECS.Components.EnemyPathElement> which has been invalidated by a structural change.

rotund token
#

any structural change

#

will invalidate all existing buffers

deft pilot
#

but i cant' see one

rotund token
#

var buffer = EntityManager.AddBuffer<EnemyPathElement>(newEnemyEntity);

#

invalidates
in DynamicBuffer<EnemyPathElement> enemyPathTags

deft pilot
#

why would it?

rotund token
#

because it's a structural change

#

any structural change
will invalidate all existing buffers

deft pilot
#

oh wait

#

literally all

rotund token
#

yes

#

all

deft pilot
#

not just that buffer

rotund token
#

Structural changes not only require a sync point, but they also invalidate all direct references to any component data. This includes instances of DynamicBuffer and the result of methods that provide direct access to the components such as ComponentSystemBase.GetComponentDataFromEntity.

deft pilot
#
            Entities.ForEach((Entity entity, in EnemySpawnTag enemySpawnTag, in EnemySpawnComponent enemySpawnComponent) =>    
            {
                var enemyPathElements = EntityManager.GetBuffer<EnemyPathElement>(entity);
#

so this should technically solve it?

rotund token
#

no

#

it will still be invalidated

#

you would have to make a copy in a native array

#

ToNativeArray()

deft pilot
#

wait i'm confused now

#

does getbuffer not get me a pointer to it?

rotund token
#

which is invalidated

#

as soon as you call any EntityManager.Create/Destroy/Add/Remove methods

#

because those methods

#

might move the buffer

#

to a new location in memory

#

therefore it is invalidate

deft pilot
#

and get buffer doesn't point to the new location when its called?

rotund token
#

to stop blowing yourself up, unity forcefully invalidates them all

deft pilot
#

i see...

#

so getbuffer is a cache of pointers

#

for like that frame or something

#

or job?

rotund token
#

getbuffer just gets the current pointer to the data

#

which is valid until you make a structural change

#

the TIL here is, don't use entitymanager, use a local command buffer
play it back after the job

deft pilot
#

i'm trying to find out how often get buffer is "refreshed" with new pointer

rotund token
#

or, copy your buffer to a nativearray

deft pilot
#

hmm k

rotund token
#

EM.getbuffer

#

just gets the current pointer to the current location of the buffer

deft pilot
#

i'll look into command buffers afterwards i guess

#

for now i'll just use native arrays and manually dispose of them

rotund token
#

you don't need to use a command buffer system

#

just do a var ecb = new EntityCommandBuffer(allocator.tempjob); before the job

#

then use that instead of EM

#

then after job call

#

ecb.PlayBack(entitymanager)

#

ecb.dispose

#

it just defers all the structural changes till after the job has run

deft pilot
#

i see, whats the draw back?

brave field
#

How to extend idomatic foreach 8 parameters limit?

rotund token
deft pilot
#
            var entityCommandBuffer = new EntityCommandBuffer(Allocator.TempJob);
            var enemyPrefabs = EntityManager.GetBuffer<PrefabGroup>(prefabGroupQuery.GetSingletonEntity(), true).Reinterpret<Entity>();

            Entities.ForEach((in EnemySpawnTag enemySpawnTag, in EnemySpawnComponent enemySpawnComponent, in DynamicBuffer<EnemyPathElement> enemyPathElements) =>    
            {
                var secondTileWorldPosition = enemyPathElements[1].Value.WorldPosition;
                var spawnPosition = enemySpawnComponent.Value.WorldPosition;
                
                var newEnemyEntity = EntityManager.Instantiate(enemyPrefabs[0]);
                // EntityManager.SetArchetype(entity, this.enemyArchetype);
                entityCommandBuffer.AddComponent(newEnemyEntity, new EnemyPathStepComponent() { value = 1 });
                entityCommandBuffer.AddComponent(newEnemyEntity, new MoveToWorldPositionComponent() { Value = secondTileWorldPosition });
                entityCommandBuffer.AddComponent(newEnemyEntity, new Translation { Value = spawnPosition });
                var buffer = entityCommandBuffer.AddBuffer<EnemyPathElement>(newEnemyEntity);
                buffer.CopyFrom(enemyPathElements);
            }).WithStructuralChanges().Run();

            entityCommandBuffer.Playback(EntityManager);
            entityCommandBuffer.Dispose();
#

welp lets see if this works

rotund token
#

.WithStructuralChanges() - you shouldn't need this

#
          var newEnemyEntity = EntityManager.Instantiate(enemyPrefabs[0]);
#

you're still breaking it here

deft pilot
#

ahh yes

#

okay thats pretty cool that works

#

thanks

#

too bad i can't try this on 1.0.0

#

since ForEach is no longer recommended

rustic rain
#

It still works

rotund token
#

for now

deft pilot
#

you can?

rotund token
#

seems silly to write new code you're doing to have to rewrite anyway

deft pilot
#

i think you misread my comment lol

rotund token
#

you can just do the same thing in IJE

deft pilot
#

who knows when they support TileMaps in 2022.2

#

it took forever in the past to port stuff

#

with 2d physics

rotund token
#

I don't think 2d is high on any priority

deft pilot
#

yeah

#

oh well

rustic rain
#

For 2d you gotta reimplement tons of stuff

#

Sadly

tepid radish
#

System.IndexOutOfRangeException: Index {0} is out of range of '{1}' Length.
This Exception was thrown from a job compiled with Burst, which has limited exception support. .....

This occurred less on Unity 2019.
But on 2021 it occurs more frequently.

May this be a known issue?
Could anyone help me please?

rustic rain
deft pilot
#

if you wanted to destroy all entities with a certain tag and also act on them is it better to do something like:

E.Foreach((Entity entity) =>
{
  // do processing
  ecb.Destroy(entity);
};

// vs

E.Foreach((Entity entity) =>
{
  // do processing
};

ecb.DestroyEntitiesForEntityQuery(someEntityQuery);
spice vale
#

The variants taking a query will always be faster, because then the operation can be done at chunk level, rather than doing it one entity at a time.

rustic rain
#

or also because manual per entity iteration requires to save each entity

#

and some meta data for ECB

deft pilot
#

i was thinking that was the case

#

just wasn't sure if the run of the query again

#

was a big enough overhead or not

spice vale
#

For example adding a tag to a query will simply mark the chunks that they have the tag

deft pilot
#

alright now to figure out how to sync entity component data to UI display

#

guessing this is gonna be weird

dense crypt
deft pilot
dense crypt
#

Yeah unfortunately that's the case, but if you do all calculations in dots it's kinda a miniscule overhead

deft pilot
#

can't you technically do something like

#

make an gameobject to an entity

#

that has a script that takes in the value

#

but not sure if you can even do that with entity components

#

haven't tried

dense crypt
#

You could also just expose an array in a system and grab data from that

deft pilot
#

O.o?

dense crypt
#

Yeah, if you have a persistent NativeArray or similar and get a reference to your system from EntityManager.GetOrCreateSystem then all you have to do is grab whatever you need from it. Assuming you "store" the data in said array

rotund token
#

Personally I think you should be doing it in reverse

#

Make a system write to the ui

deft pilot
#

wait how does a system write to the UI

#

what

#

does it just write to a static value

spice vale
#

Use a SystemBase instead of ISystem

rotund token
#

I personally have 1 system per panel that owns the element

#

I find this nicer with ui toolkit because then you don't even need to touch monobehaviour

#

And it highlights the benefit of this approach

deft pilot
#

crap i think i might've had a false assumption

#

that you can't touch unity mainthread stuff

#

in systems

#

outside of the job translation stuff

rotund token
#

You can touch anything in update

#

You just can't touch it inside a job off main thread

deft pilot
#

shit...

#

okay time to refactor

rotund token
#

(At least not without considerable effort)

deft pilot
#

time to rip out all of these monob's

#

i was like how the hell do people deal with this coupling

#

of monob data vs entity data

rotund token
#

I have no monobehaviours

#

Outside of authoring

deft pilot
#

yeah i must've mis read about not being able to do that in jobs

#

meaning not being able to do it at all

#

ughh

#

i rewrote all my pathfinding to be stateless

#

just because i thought this was true

#

you know how stupid the code looks ughh

rotund token
#

Learning experience! You probably learned something new while doing it!

deft pilot
#

i learnt i'm never doing that again

#

Lol

#

in all honestly

#

its easier to restart this project

#

i might just archive this one

#

and start a new one

#

refactoring starting from now is abit too crazy

deft pilot
#

or is this specifically whatever UI toolkit is

#

aka it can draw UI's via code

rotund token
#

Ui toolkit is unitys new ui (probably) replacing ugui

deft pilot
#

yeah reading up on it

#

gives me some wpf vibes

rotund token
#

You don't have to use it and you can stick with the existing ui system if that's what you're comfortable with

#

But it's nice because you can just load the panel and manipulate it direct in the system

#

The only thing you have up solve is getting a reference to the ui document

deft pilot
#

i basically hate frontend

#

so i'll probably stick with the old UI system cause i know abit about it

rotund token
#

So it's just 1 single single pocket in the scene to deal with instead of 100s of elements

#

Fair enough, I too do not overly enjoy front end

#

Which is why I assign all those tasks to other people at work ๐Ÿ˜†

deft pilot
#

i'm a backend only developer at work

#

so don't even need to delegate ๐Ÿ˜›

rotund token
#

Our studio historically has not been big enough to have such fixed roles

deft pilot
#

ahh i sold my soul to normal business coding couldn't stomach working for a game studio

#

cause of pay unfortunately

rotund token
#

And while generally most front end work would end up with same people, at some point you just need to step up and get a job done

#

Yeah I'm sure I could probably make more elsewhere

#

But then I'd hate myself ๐Ÿ˜†

deft pilot
#

but bills mortgage and shit

#

not sure how i'd live on half my salary

rotund token
#

(I actually don't care that much for making games, I just enjoy game architecture)

deft pilot
rotund token
#

Well if you're going down the ugui root

#

Your going to have to write yourself a presentation layer

#

On monobehaviours to expose to your systems

deft pilot
#

that still begs the question how does the system have a reference to the monobehaviour

rotund token
#

However you want

#

Bind it to a component during baking

#

Make it a singleton you read at runtime

#

Search for it in a scene

deft pilot
#

i see

rotund token
#

Load it from addressable from your system

deft pilot
#

okay thanks

#

this should be enough for me to start

rotund token
#

Really depends how extensive you want this to be

#

And how much effort you want to put into it

deft pilot
#

i more trying to understand ECS

#

so making a super extensible frontend doesn't really matter to me right now

rotund token
#

Debug to console them ๐Ÿ˜„

deft pilot
#

rofl

#

you joke but thats what first C# programs are

#

basically Console.WriteLine

rustic rain
#

๐Ÿค”

#

how entities for each lambda captures managed locals?

rotund token
#

what do you mean

rustic rain
#

without burst

#

I wonder if I can do the same with IJobEntity

proud jackal
#

Managed fields in IJobEntity are not allowed, but Managed Components are as long as you call .Run :3

rustic rain
#

๐Ÿค”

viral sonnet
#

@rotund token did you manage to make your UI systems, ISystem and burst compiled too? (for the most part)

rustic rain
#

๐Ÿค”

#

why Material int is 6

#

and Mesh is 3

#

while arrays are both [3] size

#

and it always returns null

#

bruh

rustic rain
#

๐Ÿฅฒ

#

rip selection tool

stone osprey
#

Currently implementing my health mechanic... a health component totally makes sense.
However some entities should be destroyed upon death, others should respawn... So i thought about marking an entity as dead instead of checking its health everytime. Does this make sense ? Are there actually rules for when we should use tag components and when not ?

viral sonnet
#

not really rules. with enabled components this makes a lot sense now, having a IsDead or IsAlive tag

#

but even without. there is change filtering so you don't need to check every health all the time, only when the health is changed. (not individually, you still need to check the whole chunk)

#

it's a bit more involved though than just tags

stone osprey
#

Thanks that sounds great ^^
Yeah the lack of "rules" or patterns kinda distracts me... i often sit here and think myself : "Should this feature be an entity event, a component, a tag or even just a read operation from an existing component ?"

rustic rain
#

one way I see it: make a pipeline of damaging

#

so every you change health

#

you also check for dead state

stone osprey
#

That makes sense and in that system where i change the health i just enable/disable the "IsDead" component right ? This would atleast save one extra system which more iterations

rustic rain
#

well, allthough it helps avoid structural changes

#

tbh I'm not sure this is the best way

stone osprey
#

I guess theres no "best" way... But i guess it makes sense to have a "IsDead" component since with it we can filter like collision systems or render systems to not iterate over that particular entity since its dead ^^

rustic rain
#

having component

#

allows you to be able to query just for dead

#

but requires ECB on every damage system

#

having it as bit state

#

requires you to have check for dead on literally every system that is not meant to run on dead

#

I'd say it sucks either way ๐Ÿ˜…

stone osprey
#

Damn... i see :/
But this looks like a typical case of : "Just do what you like more" ^^

spice vale
#

But can't that be solved with aspects?

rustic rain
#

I think so

spice vale
#

I haven't looked so much into them, but It feels like it should be possible.

rustic rain
#

I'd guess, if entities meant to die a lot - bit
if they are not meant to die a lot - comp

stone osprey
#

Guess that makes the most sense... with bit you mean tag cmp right ?

rustic rain
#

bit - enabled/disabled tag state

#

comp - whole tag

viral sonnet
rustic rain
viral sonnet
#

ah ok, yeah tagging (add/remove) sucks ๐Ÿ˜„

#

the simplest form is really to just destroy the entity. though that's often a bit problematic with linked GOs or a corpse state where a monster lootable or smth

whole gyro
#

I think an enableable component can work well for these use cases. I've been thinking the same. If you don't want to have to filter IsDead entities out of all normal systems, you could invert the logic and have an IsAlive enableable component that is enabled by default.

#

It seems like using empty IEnableableComponents allows us to do everything that we could do with the old empty tag components, but without incurring the cost of a structural change.

viral sonnet
#

you'd have to filter regardless in IJobChunk. For IJobEntity it's code generated so either comp will work

#

that's, imo, the biggest annoyance with enabled comps. the filtering and the boilerplate that comes with it

#

entity queries basically just return valid chunks. but one entity in a chunk could be disabled or dead

#

that's the upside of adding/removing a tag comp

oblique cosmos
#

Could anyone provide me with further reading regarding:

[...] two containers may not be the same (aliasing).

I think I sorta kinda understand why this might be coming up, but without understanding a bit better what's actually happening in the magical background world I have no idea how to fix it. Is there any documentation on this aliasing stuff? Specifically I'm running into this with ComponentLookup<LocalToWorld>, which apparently overlaps with the TransformAspect I feed into my job. And I'm not entirely clear why or how, because it appears to work fine in a very similar system ๐Ÿค”

whole gyro
balmy thistle
#

<record scratch> hold up

viral sonnet
viral sonnet
oblique cosmos
#

So... is this a bit of a safety misfiring then or should I be concerned about disabling safety restrictions?

#

(Assuming that works, can't check anymore now)

viral sonnet
#

kind of. the safety system can't make sure that you are doing something wrong. if you know what you're doing it's fine ๐Ÿ™‚

#

same goes for example for any ComponentLookup you want to write to in a parallel system. default safety tells you this is not allowed but if you know threads don't write to the same entity, it's totally fine and often needed.

quiet magnet
#

this seems like something simple im missing, i create a job with NativeArray<Type>, i have a public int output, why can't i seem to access output outside the job?

viral sonnet
#

there are more [Native...] tags to turn some kind of safety off. DisableContainerSafety is a catch all tag

#

is it just a public int?

#

or a NativeReference?

quiet magnet
#

ah is nativereference for a variable?

#

hmm there is no nativereference

viral sonnet
#

variable? it's to get the variable by reference and not by value

quiet magnet
#

yes but i cant seem to figure how to do that

viral sonnet
#

if it's just an int, the int will stay local to the thread

quiet magnet
#

im not exactly going to make a nativearray of 1 item

viral sonnet
#

yeah, that's why NativeReference exists

quiet magnet
#

ok so how do i do a job that updates 1 int, and then i get that int outside the job?

#

well i dont seem to have NativeReference, what am i missing?

viral sonnet
#

hm, i'm not sure, it's in Unity.Collections

#

missing the namespace?

#

public int a; from the job turns into public NativeReference<int> a; to access the int then a.Value

quiet magnet
#

god why cant i access this

#

i have collections 1.2.4

#

in the docs its there

#

i only have the usual array/slice

#

it doesnt show a solution either like a missing class

viral sonnet
#

are you in a asmdef?

quiet magnet
#

nope

#

i was thinking why isnt there just a simple Native Reference

#

it does exist, yet it doesnt

viral sonnet
#

hm, i'm stumped too. NativeReference was around long before collection went 1.0

quiet magnet
#

is it only on Net 2.1?

#

just a guess

rustic rain
#

NativeReference?

viral sonnet
#

i have .net Standard 2.1 api level

rustic rain
#

Is that a way to have ref to field?

viral sonnet
#

basically, yeah as it's using a pointer

quiet magnet
#

yes well im trying to do things unity way without direct pointers

#

sometimes i think pointers are just damn easier lol

#

@rustic rain does NativeReference show for you?

rustic rain
viral sonnet
#

2.1 needs Unity 2022.2 btw

#

any 1.x version also has NativeReference

quiet magnet
#

well things like this just stump me

#

is it some dependency?

#

i have never seen NativeReference in all my time with jobs

#

actually i thought it was me being stupid

#

dont think collections was installed haha

#

and yet i can access unity.collections

#

ok dumb moment

#

but yes didnt know native ref existed until now

#

thought jobs always had to be parallel arrays of input and output (ideally they do)

#

ok now how do i convert an int to NR int

#

a .value

viral sonnet
#

ohh, you found it out. yeah some basic version of unity.collections is built in. for nativearray

#

i'll try to remember the pitfall ๐Ÿ˜

#

init in your job struct like this refInt = new NativeReference<int>(0, Allocator.TempJob)

rustic rain
#

wait a second

#

so it's like native array of size 1?

viral sonnet
#

in your job you have public NativeReference<int> refInt;

#

basically ๐Ÿ˜„

rustic rain
#

that's good stuff

#

I hate doing array[0]

viral sonnet
#

the implementation just has a void* and allocates sizeof(T)

rustic rain
#

I'd guess so

#

initially I thought it was actually just a pointer to existing memory

#

which you accessed through ref

rustic rain
#
        void EntitySelectionTool_6C3936B1_LambdaJob_0_Execute(ref Unity.Collections.NativeParallelHashMap<int, int> map, ref UnityEngine.Rendering.CommandBuffer cmd, SpaceTycoon.StarSystem.StarShared curSystem)
        {
            __Unity_Entities_EntityTypeHandle.Update(ref this.CheckedStateRef);
            __Unity_Rendering_MaterialMeshInfo_RO_ComponentTypeHandle.Update(ref this.CheckedStateRef);
            __Unity_Transforms_LocalToWorld_RO_ComponentTypeHandle.Update(ref this.CheckedStateRef);
            var __job = new EntitySelectionTool_6C3936B1_LambdaJob_0_Job{__this = this, map = map, cmd = cmd, __eTypeHandle = __Unity_Entities_EntityTypeHandle, __mmiTypeHandle = __Unity_Rendering_MaterialMeshInfo_RO_ComponentTypeHandle, __localToWorldTypeHandle = __Unity_Transforms_LocalToWorld_RO_ComponentTypeHandle, __rmaTypeHandle = GetSharedComponentTypeHandle<Unity.Rendering.RenderMeshArray>()};
            __query_1983835779_0.SetSharedComponentFilter(curSystem);
            using (EntitySelectionTool_6C3936B1_LambdaJob_0_Job.s_ProfilerMarker.Auto())
            {
                CompleteDependency();
                Unity.Entities.InternalCompilerInterface.JobChunkInterface.RunByRefWithoutJobs(ref __job, __query_1983835779_0);
            }

            map = __job.map;
            cmd = __job.cmd;
        }
#

huh

#

so this is how you can run jobs with managed fields

#

Unity.Entities.InternalCompilerInterface.JobChunkInterface.RunByRefWithoutJobs

#

it's even public

rotund token
#

it's just running main thread so no scheduling involved

rustic rain
#

that was my task though

rotund token
#

you just want a convenient way to query data i take it?

rustic rain
#

yeah

rotund token
#

did you get your selection working again?

rustic rain
#

yeah

#

with normal DrawMesh though

#

but!

#

I figured how to do color conversion on GPU

#

๐Ÿ”ฅ

#
            int _Index;

            fixed4 frag(v2f i) : SV_Target
            {
                fixed r = (_Index & 0xFF);
                fixed g = ((_Index >> 8) & 0xFF);
                fixed b = ((_Index >> 16) & 0xFF);
                fixed a = 255 - (_Index >> 24);

                return fixed4(r, g, b, a) / 255;
            }
#
        private static int ColorToIndex(Color color)
        {
            Color32 color32 = color;
            return color32.r + (color32.g << 8) + (color32.b << 16) + ((255 - color32.a) << 24);
        }
#

oh man, I wish SystemAPI offered getting type handles

#

that auto updated for me

#

๐Ÿ˜…

rotund token
#

but i guess it depends on your game

rustic rain
#

yeah it probably is

#

but for now

#

I just want working solution

#

until I get my project working back at at least 90%

rotund token
#

that's fair enough

viral sonnet
#

i'm currently rewriting a lot of systema to ISystem. get rid of shared containers and handles. i expect a huge fire when i hit play

rustic rain
#

๐Ÿ”ฅ

viral sonnet
#

even BIGGER

#

๐Ÿ„

#

whelp, there's no nuke

#

but let's see how cool singletons and dependencies are

gentle gyro
rustic rain
#

this is shader

gentle gyro
#

Ah, missed that

rustic rain
#

๐Ÿค”

#

so selection tool works with camera A

#

but doesn't with camera B

rotund token
#

Do you mean yours or unitys?

rustic rain
#

my selection tool, yes

rotund token
#

(also what is camera b)

rustic rain
#

camera B is map camera

#

which is pretty much same, but it's static and very far away

#

so when I switch to map, selection tool also does it's job with new camera

#

judging by screenshot from selection drawing

#

nothing is drawn

#

๐Ÿค”

#

meanwhile there's actually 3 draw calls

gusty comet
#

I wrote a script to move an Entity from the DOTS world into the Monobehavior world, but I'm not sure if it's good practice

#
public sealed class Avatar : MonoBehaviour
    {
        public DecisionMaker Brain;
        public Toggle Run;
    }

    public static class AvatarActions
    {
        /**
         * Should be only rarely called
         */
        public static AvatarCommandComponent Obtain(Unity.Entities.World world)
        {
            var initializer = world.CreateSystemManaged<AvatarInitializeSystem>();
            initializer.Enabled = true;
            initializer.Update();
            var command = initializer.Command;
            initializer.Enabled = false;
            world.DestroySystemManaged(initializer);
            return command;
        }
    }

    [DisableAutoCreation]
    public partial class AvatarInitializeSystem : SystemBase
    {
        public AvatarCommandComponent Command;

        protected override void OnUpdate()
        {
            Command = GetSingleton<AvatarCommandComponent>();
        }
    }

    public sealed class AvatarBaker : Baker<Avatar>
    {
        public override void Bake(Avatar authoring)
        {
            AddComponent(new AvatarCommandComponent
            {
                Brain = GetEntity(authoring.Brain),
                Run = GetEntity(authoring.Run)
            });
        }
    }

    public struct AvatarCommandComponent : IComponentData
    {
        public Entity Brain;
        public Entity Run;
    }
#

It works, and is necessary to have my InputSystem send commands to Entities, but I'm not sure if there's a better way of doing it

viral sonnet
#

anyone knows a proper way to get a singleton in MB? do i really have to write an entityQuery, get the entity and then GetComp?

rustic rain
viral sonnet
#

huh? i only have EntityManager. rest are ISystems, no direct references

rustic rain
#

EM contains reference to World

spice vale
#

does EntityManager.UniversalQuery.GetSingleton() work maybe? not sure...

viral sonnet
#

yeah, i think that does the trick.

gusty comet
viral sonnet
#

huh, seems like OnCreate of systems doesn't follow the same order as Update. getting errors in a system that wants SingletonRW in OnCreate but then complains there's no singleton created. wonder if i should just set a query instead. but first i try [CreateBefore]

spice vale
#

Have you confirmed this works? EntityManager.UniversalQuery.GetSingleton()

#

otherwise it might be that it needs a specific query

viral sonnet
#

big rewrite. i'll get to it ๐Ÿ˜„

gusty comet
spice vale
#

I see, so does not work

viral sonnet
spice vale
#

I guess for GetSingleton to work the query has to match only one entity.

viral sonnet
#

well, if there's really just 1 entity it'll work

spice vale
#

But universal query is all entities

viral sonnet
#

yeah, that's always the case for singleton entities

gusty comet
#

There's only 1 Entity as verified by the debugger, but the universal query is throwing an exception saying there are 34

rustic rain
gusty comet
#

I see. I'll try this instead: Avatar = EntityManager.CreateEntityQuery(typeof(AvatarCommandComponent)).GetSingleton<AvatarCommandComponent>();

rustic rain
#

they are disposable

spice vale
#

no?

rustic rain
#

yes?

gusty comet
spice vale
#

only when using EntityQueryBuilder

gusty comet
rustic rain
gusty comet
#

It worked, but I might be misusing that method

rustic rain
#

unless you use it in system

spice vale
#

huh, did not know.

rustic rain
#

bad part on Unity - the fact that systems cache queries

#

is like a secret

spice vale
#

but what is the allocation?

#

we don't specify any

rustic rain
#

you specify world

#

in which it gets allocated

spice vale
#

But is it not cached in the world for the next time I would access that query if I don't dispose it?

rustic rain
#

idk

#

the only thing to remember

#

there are limited slots for entity queries in world

spice vale
#

So simply getting a singleton from world is way too complicated atm I feel.

rustic rain
#

it is

#

I use EM extension

#

to get singletons

spice vale
#

Get EM, create query, get singleton from query, dispose query

rustic rain
#
        public static Entity GetOrCreateSingletonEntity<T>(this EntityManager em)
        {
            using var query = em.CreateEntityQuery(ComponentType.ReadOnly<T>());
            var needCreate = query.IsEmptyIgnoreFilter;
            var e = needCreate ? em.CreateEntity(typeof(T)) : query.GetSingletonEntity();
            #if UNITY_EDITOR
            if (needCreate)
            {
                var type = typeof(T);
                var name = new StringBuilder();
                name.Append(type.Name);
                if (type.IsGenericType)
                {
                    name.Remove(name.Length - 2, 2);
                    name.Append(" | ");
                    foreach (var otherType in type.GetGenericArguments())
                    {
                        name.Append(otherType.Name);
                    }
                }

                em.SetName(e, name.ToString());
            }
            #endif
            return e;
        }
#

pretty much

#

tbh, this can be made burst compatible even

spice vale
#

but you don't dispose query ๐Ÿ˜…

rustic rain
#

using

spice vale
#

oh I see

#

right you can use that without braces

rustic rain
#

yeah, pretty convenient

viral sonnet
#

InvalidOperationException: The previously scheduled job ArrayHashMap`2:CalculateBucketsJob writes to the NZNativeContainers.ArrayHashMap`2[System.Int32,NZSpellCasting.ThreatEvent] CalculateBucketsJob.hashmap. You are trying to schedule a new job GenerateThreatValuesJob, which reads from the same NZNativeContainers.ArrayHashMap`2[System.Int32,NZSpellCasting.ThreatEvent] (via GenerateThreatValuesJob.JobData.threatTargetEvents). To guarantee safety, you must include ArrayHashMap`2:CalculateBucketsJob as a dependency of the newly scheduled job. hm, that's exactly what i wanted to prevent with singleton containers. first has RW access, seconds has RO access, yet the job doesn't understand waiting for it. hm

molten flame
#

y'all been able to connect the rider debugger to Unity in 1.0?

#

probably completely unrelated issue to DOTS

rustic rain
#

yeah

#

constantly errors though in specific scenarios

#

have to restart unity frequently

viral sonnet
#

now i could test the universalQuery. uint tick = entityManager.UniversalQuery.GetSingleton<TickSystem.TickData>().currentTick; and yeah, it's not working for some reason :/

#

no idea why UniversalQuery has a singleton method when it doesn't do what it should ^^

spice vale
#

Well, if your game has only one entity, it is perfect. I don't see what you mean ๐Ÿ˜†

viral sonnet
#

haha ๐Ÿ˜„ yeah ...

rotund token
#

why?

viral sonnet
#

haha ๐Ÿ˜„

rotund token
#

it'd be weird if it didn't have one

viral sonnet
#

we have realized ๐Ÿ˜„

#

wanted to use a method to get a singleton without creating a query

late mural
#

hey wondering quickly, which specific package is needed for NativeList?

rotund token
#

collections

late mural
#

ah thanks!

viral sonnet
#

well that's weird that the extension method return 0 entities but other systems can find the singleton just fine :/ ```public static T GetSingleton<T>(this EntityManager entityManager)
where T : unmanaged, IComponentData
{
var query = entityManager.CreateEntityQuery(ComponentType.ReadOnly<T>());
var entity = query.GetSingletonEntity();
var comp = entityManager.GetComponentData<T>(entity);
query.Dispose();

        return comp;
    }```
spice vale
#

are the others system entities?

viral sonnet
#

... yes! thanks

#

damn, that throws me off the 2nd time

spice vale
#

I dont really get why they are excluded by default

viral sonnet
#

i don't understand either. i see no reason

#

hm, do i need a queryBuilder now? i have no idea how to add them with CreateEntityQuery

spice vale
#

use EntityQueryDesc

#

it has options field

viral sonnet
#

right, that would also work. i've already written the queryBuilder

#

lol, that sucks. one of my native containers didn't burst compile because i used a typeof for debug. now that i've removed it. it crashes unity hard ๐Ÿ˜„

#

i never had it crashing before the singleton rewrite. very odd

#

but now it does directly on the schedule

#
        {
            return new ParallelListToArraySingleThreaded()
            {
                parallelList = this,
                array = nativeList
            }.Schedule(Dependency);
        }```
#

wait, what is this? InvalidOperationException: System.InvalidOperationException: Reflection data was not set up by an Initialize() call. Support for burst compiled calls to Schedule depends on the Collections package. For generic job types, please include [assembly: RegisterGenericJobType(typeof(MyJob<MyJobSpecialization>))] in your source file.

#

holy why is this happening all of a sudden ๐Ÿ˜„ i don't get it

#

ohh, i think the big difference is that i'm now using this in an ISystem instead of SystemBase

#

i've not the biggest experience with ISystem yet but generics were always problematic.

drowsy pagoda
#

The built-in UI isn't yet "built-in" to ECS 1.0.0 yet right?

viral sonnet
#

wdym? UnityUI, UIToolkit?

rotund token
#

why aren't you just using SystemAPI for this anyway?

viral sonnet
#

do you mean me tertle?

rotund token
#

yeah sorry replying to old messages

#

the singleton stuff

viral sonnet
#

i would but it's for a MB

rotund token
#

ooooooooo

#

explains a lot! ok

#

you mentioned you didn't want to create a query right?

#

var singleton = world.EntityManager.GetComponent<T>(world.GetExistingSystem<S>())

#

is slightly annoying that you are loosely coupling on a system though

viral sonnet
#

ah, via SystemHandle? that can also work

#

do you know why ISystem is especially picky with generic jobs?

#

yet it didn't in a SystemBase

#

a bit more direct ```public static TComponent GetSystemSingleton<TSystem, TComponent>(this EntityManager entityManager)
where TComponent : unmanaged, IComponentData
where TSystem : unmanaged, ISystem
{
var systemHandle = entityManager.WorldUnmanaged.GetExistingUnmanagedSystem<TSystem>();
return entityManager.GetComponentData<TComponent>(systemHandle);
}

    public static TComponent GetSystemSingletonManaged<TSystem, TComponent>(this EntityManager entityManager)
        where TComponent : unmanaged, IComponentData
        where TSystem : ComponentSystemBase
    {
        var systemHandle = entityManager.World.GetExistingSystem<TSystem>();
        return entityManager.GetComponentData<TComponent>(systemHandle);
    }```
rotund token
#

does it have issue?

viral sonnet
#

no

rotund token
#

yeah i think it's less the job, more the bursted job scheduler

viral sonnet
#

yeah it crashes there

#

do you think i should make a small repo project for the crash? i mean, there's no error or anything beforehand. it just crashes

rotund token
#

oh didn't realized it just crashes

#

it shouldn't do that

viral sonnet
#

well, i should say it only crashes with safety turned off ๐Ÿ˜„

viral sonnet
#

well, this whole singleton thing to get rid of shared containers and jobHandles worked out pretty great. the downside is that it's harder to schedule tight. i got one job that's just running after a big system where previously it was running in between because i could accurately set with which jobHandle it should run. guess i've to move the job also in the system.

#

still would be cool if the job system would figure it out ๐Ÿ™‚ as far as i understand it now, systems are imaginable as blocks on the timeline. the job scheduler does a good job packing jobs together within a system but for another system that just has a RW dependency in the middle of the previous system, the job just runs after the block

viral sonnet
#

on second thought, it's not even the job system that doesn't figure it out. it pretty much can't because the whole system has the RW dependency on the singleton.

rotund token
#

yes

#

dependencies are per system

#

you'd have to split system in 2 to have another system inject a job between it

viral sonnet
#

would there be a way to release the dependency after a job or something?

#

like, now it's okay to write ^^

rotund token
#

doubtful

viral sonnet
#

splitting sounds more reasonable

gentle gyro
#

If I want to avoid subscenes for now in 1.0 to avoid the IL2CPP crash bug, what should I use to author entities?

brave field
#

๐Ÿฅฒ How to solve this issue at 0.51? Still the same issue at both Unity 2021.3.8 and 2021.3.11. It's really weird that same project at different pc works properly

rotund token
#

why are you creating 1 million client worlds

#

i feel the solution to this is don't create a million client worlds

brave field
#

No. It's bugged. I dun want create so many worlds

rotund token
#

i'm confident this is something you're probably doing

#

is this netcode? have you changed the multiplayer tools settings?

#

i'm pretty sure this is saved in editorprefs so would only affect 1 machine

#

Multiplayer -> Play mode tools

brave field
#

๐Ÿ‘€ you are right. Not sure why client count is 32. lol

#

thanks a lot

dense storm
#
    [UpdateBefore(typeof(CompanionGameObjectUpdateSystem))]
    public class PostMovementGroup : ComponentSystemGroup, ICombatWorldSystem { }
error CS0122: 'CompanionGameObjectUpdateSystem' is inaccessible due to its protection level

I am getting this error after setting up assembly definition.

#

But I need this group to update before CompanionGameObjectUpdateSystem

#

Probably because its internal, but how do I get around this?

rustic rain
#

Use asm ref trick

dense storm
rustic rain
#

Create folder with assembly reference file

#

Create empty cs file here

#

And add to it assembly attribute 'InternalsVisibleTo(yournamespace)'

dense storm
#

Ok let me try that

dense storm
rustic rain
#

Yeah, good stuff

rustic rain
#

ok, I figured why selection doesn't work

#

implementation of graphics is just...

#

absolutely not obvious

#

none of built in methods to get meshes/materials work

#

methods that get array index are also invalid

#

this is just absurd

rotund token
wicked trout
#

Hi! I wanted to know if there is a way to create an Entity without using a Subscene.

rotund token
#

EntityManager.CreateEntity

rotund token
brave field
#

@rotund token Btw have u successfully get a working player runtime build for hello world dots netcode project? At 1.0 release

rotund token
#

haven't tried a netcode build yet

#

haven't even got around to getting my netcode project running yet

#

too busy adding cool stuff to libraries

wicked trout
spice vale
#

I'm trying to understand subscenes a bit better. Noticed that when a subscene is open it actually creates two separate worlds. Anyone know what's going on here?
Open:

#

Closed:

rustic rain
#

isolated in it's own

spice vale
#

Why is it not a world? I mean the baking systems run in a separate world right?

rustic rain
#

I'm not sure tbh how it works rn

#

maybe it is world

spice vale
#

I feel like it should only be one extra world, but then there's this shadow world.

rustic rain
#

you sure it's world?

#

it says archetype

#

๐Ÿ˜…

spice vale
#

The archetypes are inside:

half jay
#

is it possible to not add this components when bake conversion is happening. It should be just entity without any render logic

rustic rain
#

beside

#

SceneSection

#

this one is SubScene component

half jay
#

So I can leave it as it is and not worry?

rustic rain
#

yes

half jay
#

Is there an analogue of CopyTransformToGameObject or how can i solve case when i need control GO from system?

rustic rain
#

why there's white square over entiites?

rustic rain
#

ok I figured it

#

kek

#

forgot to attach with all and with none attributes on job after migrating from foreach

stone osprey
#

As far as i know unitys ecs is kinda "protected" in legal terms right ?

Since i want a similar ecs for my standalone c# console server... i wanted to copy its ecs and create a pure c# version from it.
It would be archetype based and consist of chunks/buckets like unitys ecs does. Is this allowed ? Or does this already violate some legal stuff ?

rustic rain
#

you can copy the way it works

#

ECS is not new

#

and certainly not unique

stone osprey
#

Alright thanks, i thought they protected that "bucket/chunk" mechanic ^^ So i wasnt sure about that

rustic rain
#

Burst certainly is

#

and burst is pretty much the main reason to use Unity ECS

stone osprey
#

Alright, i will totally not copy burst xD

rustic rain
#

tbh

#

what stops you from building your app on Unity?

#

xD

stone osprey
#

The client is unity already, for the server however i went with c# and .net core... latest .net... latest language features, smaller, less memory footprint... those were basically the reasons ^^

#

Even unity in server mode is kinda massive

viral sonnet
#

entities is allowed to only run in unity. no porting. it's all patented

spice vale
#

anyone else getting this error every 5 seconds? Generic message code 233 has not been handled

misty wedge
#

How does the safety system work now exactly? For example, what happens if I have an unsafe collection in a component to modify it, can I then create a safe collection from that unsafe collection and pass it to a job and have safety?

coarse turtle
misty wedge
#

I mean you could write one

coarse turtle
#

you might be able to create an asmref so you can do something like NativeCollections.SetAtomicSafetyHandle<T>(ref T collection, AtomicSafetyHandle)

misty wedge
#

I was more asking if that's ok to do, or is there some other magic going on somewhere to facilitate safety

coarse turtle
#

i typically do it frequently w/ native arrays

misty wedge
#

What do you use it for? Since native arrays don't have an unsafe version

coarse turtle
#

I alias the NativeArray to a pinned blittable C# array

misty wedge
#

Why not just use the pointer to the unmanaged array?

#

Or is this library code

coarse turtle
#

libraryish code

#

i didn't really want my teammates having to write [NativeDisableUnsafePtrRestriction] in jobs

#

everytime they needed a pointer

misty wedge
#

By the way are there any usage differences between safe and unsafe collections? I have some code that works fine with safe collections but somehow breaks (doesn't throw any errors) with an unsafe collection ๐Ÿคท

coarse turtle
#

looks like the primary difference is the ENABLE_UNITY_COLLECTIONS_CHECK on properties between Native & Unsafe versions

half jay
#

im want add some classes from scene to sharedcomponent and im doing it like in screen shot. Is it valid? im afraid that after subscene loaded ill get nulls in fields. Also looks like when im trying build apk im getting an error about nulls, but in play mode this works. May be i should mark somehow to not destroy game object?

misty wedge
misty wedge
#

I really hope safe non-nativearray collections are writeable in components one day, only arrays is pretty limiting

half jay
coarse turtle
#

well if you wrap a NativeList around an UnsafeList - the m_length variable would get updated as long as the m_ListData pointer is valid (and the safety handle is set)

misty wedge
misty wedge
#

I'm guessing if you ever mess up with race conditions outside of the safety system that's hell to debug

coarse turtle
#

yea

stone osprey
#

I mean they cant patent the idea behind it

#

Or can they ?

misty wedge
stone osprey
#

I mean theres c++ entt ecs which is also archetype based and uses chunks... so i guess the can not

coarse turtle
misty wedge
#

Yeah I hope one day we don't ever need to mess with unsafe collections (at least if you aren't doing anything crazy)

misty wedge
misty wedge
coarse turtle
#

yea

misty wedge
#

specifically these lines

m_Safety = CollectionHelper.CreateSafetyHandle(allocator.Handle);
CollectionHelper.InitNativeContainer<T>(m_Safety);
CollectionHelper.SetStaticSafetyId<NativeList<T>>(ref m_Safety, ref s_staticSafetyId.Data);
m_SafetyIndexHint = (allocator.Handle).AddSafetyHandle(m_Safety);
AtomicSafetyHandle.SetBumpSecondaryVersionOnScheduleWrite(m_Safety, true);
coarse turtle
#

let me look into collectionhelper - not too familiar with that static class ๐Ÿค”

misty wedge
#

No idea if that will work ๐Ÿคท

#

Also if I'm storing the UnsafeList normally (instead of as a pointer) in the component, what's the best way to get a pointer to the unmanaged component?

coarse turtle
#

Might have to get the reference to the component from the chunk and then the pointer via UnsafeUtility.AddressOf(ref component.UnsafeListField)

misty wedge
#

I think at that point its easier to just store a pointer in the component ๐Ÿ˜…

coarse turtle
#

yea lol

misty wedge
#

Thought there may be a method similar to get component but returning a pointer ๐Ÿคท

gusty comet
#

How would you configure a subscene to fully convert some gameobjects while making others hybrid?

#

Basically Convert and Destroy vs Convert and Inject but with Subscenes and Baking

whole gyro
#

you can't

spice vale
#

Convert and inject is impossible with subscenes

#

sad truth

whole gyro
#

Subscenes are only for fully baked entities. The one exception is the companion link stuff that still appears to work for things like cameras and lights.

spice vale
#

A workaround is to instantiate your gameobjects from systems during runtime.

#

You can check tertles implementation, he has such a setup

whole gyro
spice vale
viral sonnet
# stone osprey Or can they ?

sure they can. they have a very specific implementation. all covered in the patent. but tbh, if you need any kind of game server. just go with a headless unity build

whole gyro
#

@gusty comet And here is someone sharing a solution for runtime entity creation: https://forum.unity.com/threads/entitiesext-runtime-authoring-for-entities-and-tooling.1346108/
It doesn't use baking, but it lets your monobehaviours reference other things in the scene. Tertle's implementation relies on prefabs which cannot have scene references. So the best option really depends on what you are trying to do.

gusty comet
#

And thanks all of you for the wealth of ideas

whole gyro
#

yeah exactly

rustic rain
#

anyone managed to run profiler?

#

my editor crashes

#

always

misty wedge
rustic rain
#

yeah

misty wedge
#

Works fine for me

#

What unity version are you on?

rustic rain
misty wedge
#

I'm still on b9 so maybe that's the issue?

rustic rain
#

๐Ÿค”

balmy thistle
rustic rain
#

but hold on

#

I'll crash it again

#

๐Ÿ˜…

misty wedge
#

Any idea why I can't use Unity.NetCode.Tests.NetCodeTestWorld? I've referenced Unity.NetCode.TestsUtils but it can't find the symbols...

rustic rain
#

what's the equivalent of batchIndex of IJobEntityBatch in IJobChunk?

hot basin
#

chunk index?

hard gulch
#

hello!, where can i find good ecs content for learning?

rustic rain
#

look it up

#

the best I know

hard gulch
balmy thistle
# rustic rain

Thanks, almost certainly memory corruption. Is this consistent?

rustic rain
#

both standalone and built in

balmy thistle
#

built in?

rustic rain
#

normal one

#

I mean

viral sonnet
#

does this happen in an empty project too?

rustic rain
#

empty is fine

karmic basin
stone osprey
#

Btw how does the ecs know if an entity has a component ?

I meany does every entity has a bitmask of its components ? Or how is it done ? ๐Ÿ˜ฎ

rustic rain
#

archetypes know exactly what components they have

stone osprey
#

Yeah but... how does the entity know if which archetype it is ?
Like the entity itself is only a struct with an index... and version...
The entitymanager somehow knows in which archetype it is... how ? ๐Ÿ˜ฎ Is there a map somewhere "Dictionary<Entity,Archetype>" ? xD

misty wedge
#

If I want to store some data per unmanaged world and then also statically use that data in burst, can I just use a static function that reads a static native collection, or do I need to use shared static?

hot basin
#

what's the best way to update GUI?

rustic rain
#

but if you wonder how EntityManager knows it

#

they just store a huge hashmap

#

for every entity and it's chunk

stone osprey
#

Oh... that simple ? I thought theres more magic going on ๐Ÿ˜„

rustic rain
#

well, maybe there is

#

last time I looked at GetChunk of entity

#

in sources

#

it was literally hashmap xD

hot basin
#

I think I saw explanation somewhere in new tutorials

#

here

stone osprey
#

Some of the smartest people are working on that project and thats their solution... kinda funny, but sometimes the simplest solutions are also the most efficient ones

rustic rain
#
        public Chunk* GetChunk(Entity entity)
        {
            var entityChunk = m_EntityInChunkByEntity[entity.Index].Chunk;

            return entityChunk;
        }
stone osprey
#

Uh interesting... i just see that unities archetypes are actually structs of arrays

#

Yeah literally a map, insane ๐Ÿ˜„

rustic rain
#

ok maybe it's not just map

#

it's a...

#

pointer

#

and entity index is...

#

offset

rotund token
#

No reason to use a map, index increment

rustic rain
#

๐Ÿค”

stone osprey
#

Whats index increment ?

rotund token
#

May as well just use an array

stone osprey
#

Oh i see... probably even more efficient

#

Lets say we create a query and query for entities...
How does this actually behave under the hood ?

My current assumption is that the query actually loops over all archetypes, check if fits the query describtion and than iterates over the chunks and their content. Is this right ?

misty wedge
#

That would be terribly slow

stone osprey
#

Oh there its actually written i see

rotund token
#

Instead of asking why not just look at source! Better to get first hand information than third!

#

It's nicely all available to us

#

(this is only directed if you want very explicit implementation details about what goes on under hood.
Asking questions is fine about how things are done but your going to get a summary that is likely a bit wrong and if you're after explicit details they're better read directly imo)

misty wedge
#

I can't see a reason why it's not usable, it's not even marked internal or anything

rotund token
#

If I recall unity test stuff isn't included by default

misty wedge
#

It's weird because it worked in 0.51, so I guess they changed something

rotund token
#

It's been like 2 years so memory is fuzzy but you need to mark tests from a package as being imported specifically

hot basin
#

what't the best way to update GUI from inside ECS?

rotund token
#

This is because 99% of time you don't want unity tests to appear in your test runner

misty wedge
#

I can't import unity's netcode helper world though for some reason

#

(NetCodeTestWorld)

rotund token
#

Because the assembly is ignored

misty wedge
#

I thought it was only ignored in the test runner

rotund token
#

As far as I'm aware no

#

Test runner shows everything that is loaded

#

I used to run the actual unity tests because they had reflection stuff for your own code

#

Then they started shipping broken tests

#

I believe all test assemblies in package cache are just not loaded by default

misty wedge
#

Is there a way to un-ignore the assembly? Or am I better off just duplicating the class

rotund token
#

(again been 2 years since I've looked at this)

rotund token
#

There's a field in package manifest to include tests

rustic rain
#

hmmm

#

so now

#

for custom ECB systems

#

I need to define singleton

#

tbh, I'd expect Unity to just cache that entity in codegen

misty wedge
rotund token
#

Yes

rustic rain
#

while searching for it through query in OnCreate

rotund token
#

testables

rotund token
#

That you need to setup

#

It needs a unique component defined

rotund token
misty wedge
rotund token
#

Let me know if it works then I can say memory refreshed!

misty wedge
#

and iirc you are right that in 0.51 the netcode tests were showing up in the runner, they're gone now

rotund token
#

Like a local copy

misty wedge
#

Ah, I did. I had a very specific bug that was fixed but not pushed to 0.51 yet. It's fixed now in 1.0.0 and I deleted the package. So that was probably why

rustic rain
#

you can just query for entities

#

and compare type index

#

until you find the one you need

#

cache entity

rotund token
#

you realise the singleton isn't stored on the system entity?

#

And that's not the issue

#

The issue is it still needs a unique component

rustic rain
#

well, it can be stored anywhere

rotund token
#

So that normal people can query by singleton

#

How it was designed

rustic rain
#

but that's not actual must

#

or convenience

#

end goal - get data

rotund token
rustic rain
#

component will have some type index

#

that is unique to Type

#

so it's burst compatible

rotund token
#

What

#

That's what a unique component is

rustic rain
#

no no

rotund token
#

A unique type index

rustic rain
#

I'm not talking to unique component index

#

about*

#

I'm talking about Type - integer of System

#

so all ECB entities belong to same archetype

#

and you just do query over them once

rotund token
#

For the record you can't even query it in oncreate

rustic rain
#

comparing index of system you want

rotund token
#

Because the ecbs might not be setup

rustic rain
#

well, that's not really a problem

#

because if none found

#

can be created on demand

#

which then ECB will figure

#

goal - cache entity in OnCreate

rotund token
#

This just sounds worse

#

Than current setup

rustic rain
#

but it's way easier to setup custom ECBs that way

#

also it's probably better

misty wedge
#

It's like 2 6 lines of code

rustic rain
#

because less achetypes

misty wedge
#

to create the singleton and call the init function

rustic rain
#

in a World

rotund token
rustic rain
#

I know

rotund token
#

and it's not something you should really do much anyway

rustic rain
#

that's not the problem though

rotund token
#

and if they fix the bug with SystemAPI

#

then creating a new ECBS

#

will be 1 line of code

#

in future

#

by just using generics

rustic rain
#

it's just I find it absurd you have to setup whole chunk just to query over it easier

rotund token
#

public class myecbs : EntityCommandBufferSystem<myecbs>

#

because this is totally possible

#

the reason it doesn't work atm is that
SystemAPI.GetSingleton<myecbs.singleton> fails on generics

#

even though it's explicit

rustic rain
#

I don't get though, why you think that my solution is bad

#

what makes it bad

misty wedge
#

It's a ton more boilerplate

rustic rain
#

if no codegen

#

it's just 1 method

#

World.GetECBEntity<T>();

#

or EntityManager

#

for Burst

rotund token
#

can be created on demand

rustic rain
#

and then EM.GetECB(entity)

rotund token
#

cant be created on demand

#

it's a manged system

rustic rain
#

not managed system

#

entity

rotund token
#

ok

rustic rain
#

with component that says index of that System

rotund token
#

why don't you implement this then

#

it's extendable

#

you could probably do it without any changing source

#

and then you can share it with us and we can benefit

rustic rain
#

Don't think so, it needs to run in OnCreate of ECB

#

so I can extend my types

#

but not built in

rotund token
#

yeah but you dont need to change builtin

#

they are already setup to work nicely

rustic rain
#

besides

#

I can't affect codegen

rotund token
#

a) you can
b) i dont actually see why what you're suggesting needs code gen

rustic rain
#

Because codegen makes it so much better

#

literally just 1 method

#

without any boilerplate

rotund token
#

yeah

#

you don't need codegen to write an extension method

rustic rain
#

but I need codegen to get rid of boilerplate

rotund token
#

what boilerplate

#

for ecbs?

rustic rain
#

field, caching oncreate, getting data in OnUpdate

rotund token
#

but that's just 1 line

#

without codegen

#

World.GetECBEntity<T>();

rustic rain
#

but that needs to be done in onCreate

#

which if I don't have overriden

#

already makes code way bigger that it should

#

then I have to store it in a field

#

so OnUpdate is fast

rotund token
#

(could have written every ecbs system you'd ever need in this duration oft he conversion =D)

misty wedge
#

I feel like this is a lot of work for effectively saving like 1 archetype chunk per additional ECB, how many are you making?

rustic rain
#

but I want to share my idea, because I find it absurd you store unique chunk for every ECB

rotund token
#

๐Ÿคทโ€โ™‚๏ธ

#

does it really matter

#

how many ecbs are you going to have

#

beyond micro optimizations

rustic rain
#

just built in contains 6
I implement 3 (for now)

misty wedge
#

the devs don't seem to be massively concerned with creating additional archetypes. The whole system entity thing we have now also creates a new archetype per component you slap on instead of storing state in the system directly which skips the archetype

rotund token
#

so 100kb

rustic rain
#

9 archetypes instead of 1

rotund token
#

btw issue, in your custom ecbs you could just make them all use the same entity

#

so it's same archetype

#

if this was a real concern to you

rustic rain
#

bruh, stop bullying

rotund token
#

(i should say, i do wish there was like custom chunk options to merge unique entities for settings etc which this would fall under)

rustic rain
#

So I guess that's the code I need to add to my ECB?

        public unsafe struct Singleton : IComponentData, IECBSingleton
        {
            internal UnsafeList<EntityCommandBuffer>* pendingBuffers;
            internal Allocator allocator;

            public EntityCommandBuffer CreateCommandBuffer(WorldUnmanaged world)
            {
                return EntityCommandBufferSystem.CreateCommandBuffer(ref *pendingBuffers, allocator, world);
            }

            public void SetPendingBufferList(ref UnsafeList<EntityCommandBuffer> buffers)
            {
                pendingBuffers = (UnsafeList<EntityCommandBuffer>*)UnsafeUtility.AddressOf(ref buffers);
            }

            public void SetAllocator(Allocator allocatorIn) { allocator = allocatorIn; }
        }

        protected override void OnCreate()
        {
            base.OnCreate();

            this.RegisterSingleton<Singleton>(ref PendingBuffers,
                World.Unmanaged,
                $"{nameof(EndSimulationEntityCommandBufferSystem)} {nameof(Singleton)}");
        }
rotund token
#

yep

#

nameof(EndSimulationEntityCommandBufferSystem)
probably want to tweak that to be your own system

#

though i think it's only used for EntityName

rustic rain
#

ugh

#

can't believe you're defending this solution

rotund token
#

i find that interesting since i've never disliked boilerplate

#

i only care about dev time and this takes 2 seconds to setup

misty wedge
#

I feel like if anything you'd rework the way singletons interact with chunks instead, and then use that for all singletons

rotund token
#

that said, as i mentioned above this shoudl be as easy as implementing a new system via a generic

rustic rain
#

think about future devs, that will spend 0 seconds to set it up

rotund token
#

and all this singleton stuff should be setup for you automatically

#

this is what i mean

#

i don't see any reason why this can't be setup via generics in future

rustic rain
#

_bufferSystem.AddJobHandleForProducer(Dependency);
So with SystemAPI no need to call that anymore?

misty wedge
#

No, you don't

rotund token
#

for the record, SystemAPI isn't adding this call it's just ECBS is using the dependency on the singleton instead

misty wedge
#

Yeah I was really confused until I saw the RW handle on the singleton

misty wedge