#archived-dots
1 messages ยท Page 32 of 1
that you can attach to a system group
just like how FixedStepSimulationSystemGroup works
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?
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)
I don't mean the Disabled component. I mean an IEnableableComponent that is has been disabled with SetComponentEnabled(entity, false)
oh
well exactly what i said
except IgnoreComponentEnabledState
๐
well hmm
it will be boht disabled/enabled
do you just want disabled ones?
yeah exactly
just the disabled set. I know its a weird thing to ask, but wondering if it is possible
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
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;
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.
what about it?
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)
do you know how netcode handles tick? is it in a singleton?
that was my question ^^
interesting that they use a singleton. that's really the new thing now. previously it was just a field in a ClientSimulationSystemGroup/SimulationSystemGroup
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
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
well the archetype version is going to be better
if you cache the archetype in oncreate / outside burst
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?
typeof returns Type
Type is always managed
public abstract class Type : MemberInfo, _Type, IReflect
oh never realized
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.
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
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?
close your subscene is really only solution as far as i'm aware
which isn't really a solution
yeah...
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
lol
can you send me the link for the forum where this is mentioned? I'd like to jump on that train ๐
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
thx
@proud jackal How to extend idomatic foreach parameters limit without using aspect?
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
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?
PhysicsWorldSingleton just has a reference to PhysicsWorld and CollisionWorld
Please excuse the flurry of questions, but also is neglecting to set GroupIndex an issue?
it should be 0 unless you want to do special things
Thank you. I'll keep looking for clues
sorry i got distracted by work i had some stuff to follow up on this
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
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
with open subscenes?
Yes
probably same issue as things falling through ground
Ah. So I just close the Subscene/stop editing them before playing?
yes
shouldn't be an issue with closed subscene
you can still click them it'll just be entity representation instead
Thanks, I'll give it a shot
we were just discussing this above ^
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
oh yeah
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
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
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.
but i cant' see one
var buffer = EntityManager.AddBuffer<EnemyPathElement>(newEnemyEntity);
invalidates
in DynamicBuffer<EnemyPathElement> enemyPathTags
why would it?
because it's a structural change
any structural change
will invalidate all existing buffers
not just that buffer
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.
Entities.ForEach((Entity entity, in EnemySpawnTag enemySpawnTag, in EnemySpawnComponent enemySpawnComponent) =>
{
var enemyPathElements = EntityManager.GetBuffer<EnemyPathElement>(entity);
so this should technically solve it?
no
it will still be invalidated
you would have to make a copy in a native array
ToNativeArray()
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
and get buffer doesn't point to the new location when its called?
to stop blowing yourself up, unity forcefully invalidates them all
i see...
so getbuffer is a cache of pointers
for like that frame or something
or job?
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
i'm trying to find out how often get buffer is "refreshed" with new pointer
or, copy your buffer to a nativearray
hmm k
i'll look into command buffers afterwards i guess
for now i'll just use native arrays and manually dispose of them
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
i see, whats the draw back?
How to extend idomatic foreach 8 parameters limit?
nothing really, you could even turn burst back on your job
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
.WithStructuralChanges() - you shouldn't need this
var newEnemyEntity = EntityManager.Instantiate(enemyPrefabs[0]);
you're still breaking it here
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
for now
you can?
seems silly to write new code you're doing to have to rewrite anyway
i think you misread my comment lol
you can just do the same thing in IJE
who knows when they support TileMaps in 2022.2
it took forever in the past to port stuff
with 2d physics
I don't think 2d is high on any priority
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?
disable burst and see the normal exception
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);
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.
or also because manual per entity iteration requires to save each entity
and some meta data for ECB
this makes sense
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
For example adding a tag to a query will simply mark the chunks that they have the tag
alright now to figure out how to sync entity component data to UI display
guessing this is gonna be weird
Grab the entity manager from world in MonoBehaviour update and you can do what you need
i hate that this is the answer
Yeah unfortunately that's the case, but if you do all calculations in dots it's kinda a miniscule overhead
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
You could also just expose an array in a system and grab data from that
O.o?
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
Use a SystemBase instead of ISystem
No, a system just needs a reference to whatever element it owns
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
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
You can touch anything in update
You just can't touch it inside a job off main thread
(At least not without considerable effort)
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
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
Learning experience! You probably learned something new while doing it!
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
is there something i can read about getting references of stuff like this?
or is this specifically whatever UI toolkit is
aka it can draw UI's via code
Ui toolkit is unitys new ui (probably) replacing ugui
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
i basically hate frontend
so i'll probably stick with the old UI system cause i know abit about it
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 ๐
Our studio historically has not been big enough to have such fixed roles
ahh i sold my soul to normal business coding couldn't stomach working for a game studio
cause of pay unfortunately
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 ๐
(I actually don't care that much for making games, I just enjoy game architecture)
well anyway back to the actual question, how does a system have a reference to the TMP_Text component to update?
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
that still begs the question how does the system have a reference to the monobehaviour
However you want
Bind it to a component during baking
Make it a singleton you read at runtime
Search for it in a scene
i see
Load it from addressable from your system
Really depends how extensive you want this to be
And how much effort you want to put into it
i more trying to understand ECS
so making a super extensible frontend doesn't really matter to me right now
Debug to console them ๐
what do you mean
Entities for each can use managed locals if you run it
without burst
I wonder if I can do the same with IJobEntity
Managed fields in IJobEntity are not allowed, but Managed Components are as long as you call .Run :3
๐ค
@rotund token did you manage to make your UI systems, ISystem and burst compiled too? (for the most part)
๐ค
why Material int is 6
and Mesh is 3
while arrays are both [3] size
and it always returns null
bruh
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 ?
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
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 ?"
one way I see it: make a pipeline of damaging
so every you change health
you also check for dead state
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
well, allthough it helps avoid structural changes
tbh I'm not sure this is the best way
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 ^^
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 ๐
Damn... i see :/
But this looks like a typical case of : "Just do what you like more" ^^
But can't that be solved with aspects?
I think so
I haven't looked so much into them, but It feels like it should be possible.
I'd guess, if entities meant to die a lot - bit
if they are not meant to die a lot - comp
Guess that makes the most sense... with bit you mean tag cmp right ?
wdym with ECB on every damge system? you can change the enabled flag without ECB too.
I was talking about simple tag option
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
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.
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
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 ๐ค
Just don't use IJobChunk ๐
<record scratch> hold up
haha i have 95% IJobChunk
Same comps can't overlap in a job. I don't remember if this only counts for Write comps or in general. Anyway, put a [NativeDisableContainerSafetyRestriction] on the lookup.
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)
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.
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?
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?
variable? it's to get the variable by reference and not by value
yes but i cant seem to figure how to do that
if it's just an int, the int will stay local to the thread
im not exactly going to make a nativearray of 1 item
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?
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
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
are you in a asmdef?
nope
i was thinking why isnt there just a simple Native Reference
it does exist, yet it doesnt
hm, i'm stumped too. NativeReference was around long before collection went 1.0
NativeReference?
i have .net Standard 2.1 api level
Is that a way to have ref to field?
basically, yeah as it's using a pointer
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?
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
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)
the implementation just has a void* and allocates sizeof(T)
I'd guess so
initially I thought it was actually just a pointer to existing memory
which you accessed through ref
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
it's just running main thread so no scheduling involved
that was my task though
you just want a convenient way to query data i take it?
yeah
did you get your selection working again?
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
๐
that could be a bit slow at scale
but i guess it depends on your game
yeah it probably is
but for now
I just want working solution
until I get my project working back at at least 90%
that's fair enough
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
๐ฅ
even BIGGER
๐
whelp, there's no nuke
but let's see how cool singletons and dependencies are
Is there no way to do unsafe cast?
Ah, missed that
Do you mean yours or unitys?
my selection tool, yes
(also what is camera b)
camera A is topdown view
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
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
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?
guy above you literally sent ready solution xD
huh? i only have EntityManager. rest are ISystems, no direct references
EM contains reference to World
does EntityManager.UniversalQuery.GetSingleton() work maybe? not sure...
yeah, i think that does the trick.
Doh, I should try that first. Thanks!
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]
Have you confirmed this works? EntityManager.UniversalQuery.GetSingleton()
otherwise it might be that it needs a specific query
big rewrite. i'll get to it ๐
It's claiming that there are 34 entities with the singleton component when there should only be 1
I see, so does not work
setting [CreateBefore] helps indeed.
I guess for GetSingleton to work the query has to match only one entity.
well, if there's really just 1 entity it'll work
But universal query is all entities
yeah, that's always the case for singleton entities
There's only 1 Entity as verified by the debugger, but the universal query is throwing an exception saying there are 34
universal counts all entities in a World
I see. I'll try this instead: Avatar = EntityManager.CreateEntityQuery(typeof(AvatarCommandComponent)).GetSingleton<AvatarCommandComponent>();
don't forget to dispose query
they are disposable
no?
Thank you, it worked like a charm
only when using EntityQueryBuilder
hmm, I'm doing this from a Monobehavior
pretty much always
It worked, but I might be misusing that method
unless you use it in system
huh, did not know.
But is it not cached in the world for the next time I would access that query if I don't dispose it?
idk
the only thing to remember
there are limited slots for entity queries in world
So simply getting a singleton from world is way too complicated atm I feel.
Get EM, create query, get singleton from query, dispose query
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
but you don't dispose query ๐
using
yeah, pretty convenient
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
y'all been able to connect the rider debugger to Unity in 1.0?
probably completely unrelated issue to DOTS
yeah
constantly errors though in specific scenarios
have to restart unity frequently
ok, i really have not added the job to state.Dependency. it's working now ๐
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 ^^
Well, if your game has only one entity, it is perfect. I don't see what you mean ๐
haha ๐ yeah ...
what is even going on here
why?
haha ๐
Universal Query is just a normal EntityQuery which has a GetSingleton method
it'd be weird if it didn't have one
we have realized ๐
wanted to use a method to get a singleton without creating a query
hey wondering quickly, which specific package is needed for NativeList?
collections
ah thanks!
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;
}```
are the others system entities?
I dont really get why they are excluded by default
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
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.
The built-in UI isn't yet "built-in" to ECS 1.0.0 yet right?
wdym? UnityUI, UIToolkit?
why aren't you just using SystemAPI for this anyway?
do you mean me tertle?
i would but it's for a MB
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
ah, via SystemHandle? that can also work
do you know why ISystem is especially picky with generic jobs?
it needs a RegisterGenericJobType for this job https://github.com/enzi/Entities.Exposed/blob/main/Collections/ParallelList/ParallelList.cs line 257
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);
}```
if you turn off burst in your ISystem
does it have issue?
no
yeah i think it's less the job, more the bursted job scheduler
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
well, i should say it only crashes with safety turned off ๐
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
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.
yes
dependencies are per system
you'd have to split system in 2 to have another system inject a job between it
would there be a way to release the dependency after a job or something?
like, now it's okay to write ^^
doubtful
splitting sounds more reasonable
If I want to avoid subscenes for now in 1.0 to avoid the IL2CPP crash bug, what should I use to author entities?
๐ฅฒ 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
why are you creating 1 million client worlds
i feel the solution to this is don't create a million client worlds
No. It's bugged. I dun want create so many worlds
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
[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?
Use asm ref trick
Teach me master
Create folder with assembly reference file
Create empty cs file here
And add to it assembly attribute 'InternalsVisibleTo(yournamespace)'
Ok let me try that
Wow this works, thanks!
Yeah, good stuff
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
ran into this same error, a bit annoying!
Hi! I wanted to know if there is a way to create an Entity without using a Subscene.
EntityManager.CreateEntity
oh boy do i have a gross workaround for this
public JobHandle Build(NativeArray<T> positions, JobHandle dependency, QuantizeJob _ = default)
@rotund token Btw have u successfully get a working player runtime build for hello world dots netcode project? At 1.0 release
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
Thanks!!
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:
it's not separate world, it's just subscene
isolated in it's own
Why is it not a world? I mean the baking systems run in a separate world right?
I feel like it should only be one extra world, but then there's this shadow world.
The archetypes are inside:
is it possible to not add this components when bake conversion is happening. It should be just entity without any render logic
these are only editor components
beside
SceneSection
this one is SubScene component
So I can leave it as it is and not worry?
yes
Is there an analogue of CopyTransformToGameObject or how can i solve case when i need control GO from system?
can try using companion links for hybrid
wtf
why there's white square over entiites?
ok I figured it
kek
forgot to attach with all and with none attributes on job after migrating from foreach
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 ?
Alright thanks, i thought they protected that "bucket/chunk" mechanic ^^ So i wasnt sure about that
Alright, i will totally not copy burst xD
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
entities is allowed to only run in unity. no porting. it's all patented
anyone else getting this error every 5 seconds? Generic message code 233 has not been handled
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?
I don't know of any utility method that can set the AtomicSafetyHandle outside of NativeArray
I mean you could write one
you might be able to create an asmref so you can do something like NativeCollections.SetAtomicSafetyHandle<T>(ref T collection, AtomicSafetyHandle)
I was more asking if that's ok to do, or is there some other magic going on somewhere to facilitate safety
i typically do it frequently w/ native arrays
What do you use it for? Since native arrays don't have an unsafe version
I alias the NativeArray to a pinned blittable C# array
libraryish code
i didn't really want my teammates having to write [NativeDisableUnsafePtrRestriction] in jobs
everytime they needed a pointer
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 ๐คท
looks like the primary difference is the ENABLE_UNITY_COLLECTIONS_CHECK on properties between Native & Unsafe versions
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?
I just remembered, I'm assuming the issue is I copy the collection somewhere which doesn't write back the length value
Why not just check the converted subscene
I really hope safe non-nativearray collections are writeable in components one day, only arrays is pretty limiting
sry can you clarified what should i do? as i understand i checked it and its works in editor
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)
If you click load on the sub scene in the entities hierarchy, you can see what everything was converted to
I know but I'd rather just pass a pointer to make it obvious that it isn't using the safety system
I'm guessing if you ever mess up with race conditions outside of the safety system that's hell to debug
yea
which is why I want this
And what if i just write a ecs which just makes use of archetypes and chunks ?
I mean they cant patent the idea behind it
Or can they ?
I suggest you just check the patent
I mean theres c++ entt ecs which is also archetype based and uses chunks... so i guess the can not
yea that's a fair point honestly - I probably have some library code doing some questionable things that i need to recheck with UnsafeLists ๐
Yeah I hope one day we don't ever need to mess with unsafe collections (at least if you aren't doing anything crazy)
The patent doesn't only say "patented ecs and chunks". It specifies what parts of the design / engineering / implementation are under patent
Since the disposal safety is now handled by the allocator, would I need to set the allocator type to None to signal that the NativeList doesn't own the backing UnsafeList? Since it seems the scheduling safety system also requires the allocator handle
yea
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);
let me look into collectionhelper - not too familiar with that static class ๐ค
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?
Might have to get the reference to the component from the chunk and then the pointer via UnsafeUtility.AddressOf(ref component.UnsafeListField)
I think at that point its easier to just store a pointer in the component ๐
yea lol
Thought there may be a method similar to get component but returning a pointer ๐คท
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
you can't
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.
A workaround is to instantiate your gameobjects from systems during runtime.
You can check tertles implementation, he has such a setup
Yeah, or instantiate your entities from monobehaviours in the normal scene at runtime.
Check this thread to see tertles implementation https://discord.com/channels/489222168727519232/1027355900496851027
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
@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.
I see, so you store the gameobject prefab in a class component data, and once the entity is baked and the subscene is loaded, a system will instantiate the gameobject prefab and perform some wiring logic?
And thanks all of you for the wealth of ideas
yeah exactly
The normal unity profiler?
yeah
I'm still on b9 so maybe that's the issue?
๐ค
Have a callstack?
I actually already sent a bug report, heh
but hold on
I'll crash it again
๐
Any idea why I can't use Unity.NetCode.Tests.NetCodeTestWorld? I've referenced Unity.NetCode.TestsUtils but it can't find the symbols...
what's the equivalent of batchIndex of IJobEntityBatch in IJobChunk?
chunk index?
hello!, where can i find good ecs content for learning?
moetsi ECS tutorial
look it up
the best I know
ty
Thanks, almost certainly memory corruption. Is this consistent?
always
both standalone and built in
built in?
does this happen in an empty project too?
moetsi guide is indeed awesome, though not up-to-date (still at 0.50)
You can also find the new official guide for latest version (1.0) here https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/DOTS_Guide/README.md
(check pinned messages in this channel for resources)
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 ? ๐ฎ
they belong to archetype
archetypes know exactly what components they have
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
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?
what's the best way to update GUI?
somethig like that
they exist in chunks, heh
but if you wonder how EntityManager knows it
they just store a huge hashmap
for every entity and it's chunk
Oh... that simple ? I thought theres more magic going on ๐
well, maybe there is
last time I looked at GetChunk of entity
in sources
it was literally hashmap xD
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
public Chunk* GetChunk(Entity entity)
{
var entityChunk = m_EntityInChunkByEntity[entity.Index].Chunk;
return entityChunk;
}
Uh interesting... i just see that unities archetypes are actually structs of arrays
Yeah literally a map, insane ๐
No reason to use a map, index increment
๐ค
Whats index increment ?
May as well just use an array
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 ?
That would be terribly slow
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)
Anyone have an idea? I've never had this issue before
I can't see a reason why it's not usable, it's not even marked internal or anything
If I recall unity test stuff isn't included by default
It's weird because it worked in 0.51, so I guess they changed something
It's been like 2 years so memory is fuzzy but you need to mark tests from a package as being imported specifically
what't the best way to update GUI from inside ECS?
This is because 99% of time you don't want unity tests to appear in your test runner
What do you mean? I'm not trying to run anything in the test runner, I just want to write helper functions to make writing future tests easier
I can't import unity's netcode helper world though for some reason
(NetCodeTestWorld)
Because the assembly is ignored
I thought it was only ignored in the test runner
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
Is there a way to un-ignore the assembly? Or am I better off just duplicating the class
(again been 2 years since I've looked at this)
Yes
There's a field in package manifest to include tests
hmmm
so now
for custom ECB systems
I need to define singleton
tbh, I'd expect Unity to just cache that entity in codegen
In the Packages/manifest.json?
Yes
while searching for it through query in OnCreate
testables
Ah the singleton holds data
That you need to setup
It needs a unique component defined
"testables": [ "com.unity.package-1", "com.unity.package-2" ]
Yeah I just found the docs for it. Never used this before, thanks
Let me know if it works then I can say memory refreshed!
and iirc you are right that in 0.51 the netcode tests were showing up in the runner, they're gone now
Did you have the package manually imported
Like a local copy
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
thing is, there is no need to GetSingleton
you can just query for entities
and compare type index
until you find the one you need
cache entity
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
well, it can be stored anywhere
why?
But how do you know this data belongs to the specific system
you query for it once in OnCreate
component will have some type index
that is unique to Type
so it's burst compatible
no no
A unique type index
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
For the record you can't even query it in oncreate
comparing index of system you want
Because the ecbs might not be setup
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
It's like 2 6 lines of code
because less achetypes
to create the singleton and call the init function
in a World
it's like 6 lines of code to setup a custom ECBS
I know
and it's not something you should really do much anyway
that's not the problem though
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
it's just I find it absurd you have to setup whole chunk just to query over it easier
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
It's a ton more boilerplate
if no codegen
it's just 1 method
World.GetECBEntity<T>();
or EntityManager
for Burst
can be created on demand
and then EM.GetECB(entity)
ok
with component that says index of that System
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
Don't think so, it needs to run in OnCreate of ECB
so I can extend my types
but not built in
a) you can
b) i dont actually see why what you're suggesting needs code gen
Because codegen makes it so much better
literally just 1 method
without any boilerplate
but I need codegen to get rid of boilerplate
field, caching oncreate, getting data in OnUpdate
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
(could have written every ecbs system you'd ever need in this duration oft he conversion =D)
I feel like this is a lot of work for effectively saving like 1 archetype chunk per additional ECB, how many are you making?
but I want to share my idea, because I find it absurd you store unique chunk for every ECB
๐คทโโ๏ธ
does it really matter
how many ecbs are you going to have
beyond micro optimizations
just built in contains 6
I implement 3 (for now)
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
so 100kb
9 archetypes instead of 1
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
bruh, stop bullying
(i should say, i do wish there was like custom chunk options to merge unique entities for settings etc which this would fall under)
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)}");
}
yep
nameof(EndSimulationEntityCommandBufferSystem)
probably want to tweak that to be your own system
though i think it's only used for EntityName
i find that interesting since i've never disliked boilerplate
i only care about dev time and this takes 2 seconds to setup
I feel like if anything you'd rework the way singletons interact with chunks instead, and then use that for all singletons
that said, as i mentioned above this shoudl be as easy as implementing a new system via a generic
think about future devs, that will spend 0 seconds to set it up
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
_bufferSystem.AddJobHandleForProducer(Dependency);
So with SystemAPI no need to call that anymore?
No, you don't
for the record, SystemAPI isn't adding this call it's just ECBS is using the dependency on the singleton instead
Yeah I was really confused until I saw the RW handle on the singleton
That'd also be weird if it was codegen since then it would break if you just used the "normal" GetSingleton call