#archived-dots
1 messages · Page 133 of 1
i don't know what you mean
if anyone finds themselves needing SIMD Aabb's: here you go https://gist.github.com/jeffvella/6926229d1466d905e6bb50bd2f7e1ce4
https://github.com/jeffvella/NativeOctree. GitHub Gist: instantly share code, notes, and snippets.
Hola. Anyone here experienced that a subscene simply doesn't show up in an iOS build?
I have an extremely simple test scene with a bouncing sphere and a cube, which worked fine on iOS with dots physics when I just used convertToEntity, but when I converted to subscene and removed the convert stuff, it works in the editor but they don't show up in the iOS build anymore
There's a console error in XCode which indicates that it's a serialisation issue
Coming from Unity.Entities.Serialization.StreamBinaryReader.ReadBytes
are you building with new build tools?🤔
hmm no, although I'm not quite sure what you mean
I'm using 2019.3.7f1, and all the packages are up to date
I'm using Xcode 11.3 beta, I don't know if that could be a problem?
I recall having this same problem a while back when I did another quick dots test for ios
where anything that was converted to a subscene would not show up in the build
Yeah, looking more at the xcode logs, it can't load the files
"Can't open file" for the subscene
How can I debug this issue where 2 iterations of the job take a lot longer than the other iterations?
The others take ~0.5ms, and the worst takes 20ms
@cosmic sentinel it might be waiting for some other job to finish perhaps ?
@gusty comet subscenes are broken in builds, they are bugged
isn't that the old new build tools
new new build tools are code only?🤔
i think so yea
## Deprecated
- Class `BuildPipeline` is now obsolete. It has been replaced by `BuildPipelineBase` which is no longer asset based. All build pipeline assets must be converted into a corresponding build pipeline class that derives from `BuildPipelineBase`.
Oh huh
@wide fiber ok, thanks!
@warped trail wow, I honestly didn't even know about this. Where can I get it? Is it a package?
i just copied mine from ecs samples😅
Ah, I see. You just downloaded the build configuration files from the ecs samples?
or do you mean this "SubsceneWithBUildConfigurations" stuff?
Wow, changing to a custom build configuration with the OSX hybrid pipeline did the trick!
is anyone using the 2d entities package? I wanted to use it for ludum dare but now I saw it depends only on entities 0.5.1 which is pretty outdated?
so do I understand it right that 2d entities gives me 2d-dots rendering + 2d dots physics but outdated entities package?
I currently have a bunch of persistent NativeArrays and other collections which are used by various systems throughout my game. They are generated in a System and made publicly accessible from there, which feels icky.
What would be a more suitable data container for a bunch of Persistent NativeCollections (which need to be recalculated every cycle of game-end-load)?
you could go for Shared Statics, they are basically 'Global' fields that can be accessed from both ECS and MB
but its important that you initialize those fields before accessing them for obvious reasons
also it only works for struct types, so no managed stuff
you can put your native collections in there
Not heard of shared statics, are they relatively new in ECS? I do try to avoid static in general, but would be good to read up more on this
static is just name, you can manipulate it during runtime
and no, it was around for a while
it might be confusing at first but its easy, its just copy paste xD
you are basically doing what physics doing😅
Are there any other ways that people are making this sort of data available within their project?
I'm not sure I understand what difference it would make eg storing the data on a system vs a sharedstatic from an organisational perspective
Let me rephrase, I definitely don't understand the differences between storing the reference to a NativeCollection within a system versus a SharedStatic (which is after all listed in the Advanced Usages - this can't be how Unity envisages this type of data being accessed surely?
i mean.. if your data 'naturally' belongs to a system then go for your way, but if its global i rather use Shared Static
you said it feels icky so i simply suggested there is an another way of doing, your call if you want to do it or not
@wary anchor follow examples of smart guys😅
wrap your native arrays in some struct and expose some job handles
like Unity physics
I appreciate the advice, sorry I didn't type my intentions clearly - I'm trying to learn not dig my heels in! :)
and the class that it's stored in, they have an abstract basic class in that example that kinda creates itself? I don't understand what it's doing
well, i myself am not smart enough to know how things shared static works, i only know it works which is all i need 😄
This article is for explanition of shared statics, if you are interested
thanks again, you're right it does make sense to have those data off the system. I'll copy/paste and play a bit to try to wrap my head around it 😄
definitely interested, thank you, yes JDs articles are awesome, not seen this one yet
@wary anchor the sharedstatic stuff works by hashing the abstract class and the member field you pass. With that hash it requests some memory. Therefore you have the GetAndCreate method (you can get the same memory location again at a later point in case you don't store it)
I don't really understand the logic behind being able to have this Get method and get the same memory location again, since after you got it, you can just store it somewhere. But maybe it has something to do with unity having to be able to access this from managed and unmanaged (so they can get the same memory location twice)
Can some things force a ScheduleParallel to be processed as a single job?
have a job that takes the same amount of time for 10 entities in parallel as it takes to run them all in a single job (~180ms). when I do ScheduleParallel it starts the 10 jobs but all but one complete in 0.5ms but one takes 180ms (same as single)
Schedule()
what this special job is doing? 😅
a fair bit
oh, i misunderstood your question 😅
sorry, probably didn't explain it very well
but I'm pretty sure something is causing the jobs to be stalled by one job (or all jobs to be processed as one after some point)
Maybe you have some weird logic with your jobs all writing to the same nativearray, but they somehow depend on each other? 🤔
yeah, used to work ok. I'll just have to start going back in history to track down what it is
git bisect time
alright. that's very confusing. turns out it's an EntityQuery in a different system that is causing it to stall
{
All = new ComponentType[] { ComponentType.ReadOnly<Tags.Building>(), ComponentType.ReadOnly<GridPosition>() },
Any = new ComponentType[] { ComponentType.ReadOnly<Tags.Dead>(), ComponentType.ReadOnly<Tags.Created>() }
});
RequireForUpdate(buildingQuery);```
which is created in OnCreate in a different system
and they don't really have anything to do with each other
oh. I think it might be the JIT burst compiler that is confusing me
yeah, if I set it to synchronous it spends most of that time compiling
Seriously sounds like a bug 🤔
Hi there.
I was wondering if anyone here could offer me some help.
I'm trying to create an inventory system using Entities and the Job system. The entity and job systems are quite new to me, but I understand the basics. It's just a bit difficult for me to understand how to properly handle making this all use the ECS, since I have to use blittable types everywhere and some things I need (such as Texture2D for inventory image, and a List to store the inventory slots) are unavailable.
I hope this is the right place to ask this by the way. If it isn't, feel free to point me elsewhere 🙂
You can use Dynamic Buffer as your inventory slots, as for item images you can always make class IComponent data and put your Texture2D there, only thing you have to be aware of you simply need to run the system on main thread if you are dealing with class components.
I'll have a look at Dynamic Buffers. Thanks! For the other thing, the issue is that as soon as I added Texture2D to a class as variable, it told me I can't use the class, because it's not blittable anymore.
use class IComponentData instead of struct 😅
instead of "struct ComponentA : IComponentData" you do "class ComponentA : IComponentData"
Ah I see
I was using ScriptableObjects for the item types, but I imagine I can't use those anymore then
Using both ScriptableObject and IComponentData as parent classes didn't work
Is there a way to include burst compiled code with an assembly that is loaded at runtime?
Is a bufferelementdata allowed to store unity references like gameobjects ?
Damn... so theres no mix between sharedelement & bufferelement ?
you can inspect the code burst generates
i mean if you make it class then you can store references 😄
but otherwise no
My understanding is that all burstcompiled code is stored in another assembly at build time.
i never did anything with shared components so i cannot say
oh i dont know about that Rein, sorry, maybe someone with more experience can help
So say I had another assembly that I was loading as a dependency at runtime, could that assembly provide burst compiled code to use.
I'm gettingInvalidOperationException: InventoryData used in NativeArray<InventoryData> must be unmanaged (contain no managed types) and cannot itself be a native container type. Unity.Collections.NativeArray`1[T].IsUnmanagedAndThrow () (at <05f2ac9c8847426992765a22ef6d94ca>:0)when trying to use DynamicBuffer instead of a List for the inventory slots
NativeArray and DynamicBuffer have a struct constraint
What constraint do you mean?
on T
InventoryData is a struct ?
InventoryData is the object with the DynamicBuffer
The buffer is of type ItemObject (a struct with 2 int variables)
can you post some code, something doesn't add up because its trying to put an object in a NativeArray which isnt going to work.
public struct InventoryData : IComponentData
{
public DynamicBuffer<ItemObject> m_InventorySlots;
}```
This is the InventoryData struct
you can't do this😅
i guess you have to read docs first 😅
hes saying you cant put a DynamicBuffer in a component like that
I'm trying to figure it out, but even with the docs I'm having difficulty wrapping my head around it. I'm completely new to DOTS and I have an assigment I have to finish in way too little time. Would be easy getting this to work without DOTS but alas that's not what I have to do
a DynamicBuffer is an alternative to a component, so you use EntityManager.AddBuffer() instead of EntityManager.AddComponent()
in general, you can't put a list of things inside a component.
Ehhh. I'm not even using AddComponent right now. I've just attached the InventoryDataAuthoring script to the object that needs the inventory and tried to get some basic code running using the job system
What would you suggest me to do for this? I need to somehow store a list/array of those the inventory slots.
Then all I'd need to do is read the items in that list/array and alter their values to change the proper items. It's just that I'm getting stuck at getting any kind of list in the ECS
ItemObject is an inventory slot ?
Yeah
It's basically <amount> of <type> item
At first I used GeneratedObjects for the type, but that wasn't supported for this either so I decided to just copy the values in there and transfer them over manually each time the item type changes.
you could create a system that makes an entity, and add to the entity a DynamicBuffer of Inventory slots
@dark mauve Probably the "Prototype"-Pattern could help you out... everytime you "clone" a item, you customize that item after on with the certain unity data and store the references in a sharedComponentData
Any idea what this message here means ? https://prnt.sc/s1t7qz
This is my system
another option is to have a seperate entity+component for each inventory slot
Yeah that's what I was kinda worried about at first, but then again I only need the player to start with an empty inventory and then I need to be able to add and remove items to this inventory.
That's also a good idea
I'm just not sure where to begin with this all. It's really overwhelming me and the tutorials I find are usually making me more confused than I already was. Also a lot of them are a bit old and so much has changed to Entities since then.
I'm not sure what that is genar. I'll have a look. Basically the only limitation I got was that I have to avoid MonoBehaviors wherever possible
Thank you both a lot for your help btw
@dark mauve Using this for my little mmorpg... its quite usefull 🙂
Otherwhise
what does this mean "InvalidProgramException: Invalid IL code in Script.Client.Environment.Entitys.Systems.AnimationSystem/Script.Client.Environment.Entitys.Systems.<>c__DisplayClass_OnUpdate_LambdaJob0:OriginalLambdaBody (Script.Client.Environment.Entitys.Components.AnimatorComponent&): IL_00ae: endfinally
"
?
id suggest, just to see something working,
- Create a SubScene and put a few GameObjects in it, each represents a different ItemObject
- Create an authoring component to hold the max and count fields, add it to each GO.
- Press play and view the entities in EntityDebugger.
there's activity on this branch now: https://github.com/Unity-Technologies/DOTS-StreamingSamples/commits/dungeon-hybridv2
Thanks @mint iron , I think you've just given me an idea 🙂
"Update to latest dots multiple-subscene-instances branch "
@dull copper yeah, we will get some new subscene tools in next release😅
I guess that's some internal dots dev thing
is it confirmed?
I mean they are cooking something obviously
* We are adding the ability to load & offset entity scenes (By letting users modify the loading staging world, before it is moved to the simulation world)
* We are adding the ability to load the same entity scene multiple times (Each one offset differently)
* We are adding the ability to generate meta data from the scene that can be used during placement
I expect those will land in a release in a couple of weeks in dots.```
from Joachim_Ante
interesting, what would the usecase be for loading the same subscene multiple times?
@mint iron I could see that useful for populating procedural worlds
could reuse some subscenes here and there
Dang I'm working on my dumb minecraft clone right now, this sounds like it would be pretty useful
Having to manually set up generated chunks is really awkward and annoying
I mean the subscene doen't have to be big even
I'm happy they are improving this but it'll not benefit me at all atm 😄
my two main annoyances on dots are a) tooling / conversion setup b) subscenes breaking everything for me
oh wait, that dungeon example does that specifically
I just now read the thread
We are working on a sample where we do procedural dungeon generation.
Our approach is:
* A dungeon tile is an entity scene
* A procedural generator high level streaming rig (User code) has a list of SceneAsset references that define the possible tiles stored in a scriptable object.
At load time the scriptable objects defines all possible scenes, we load the meta data of each scene. (Eg. what connectivity of tiles do we have) Based on that it determines the placement of every possible tile in the world. Each represented by an entity representing the scene.
Then it uses normal streaming functionality to load the data. Eg. some scene sections are always loaded, other scene sections are loaded on demand based on distance.```
good that i know something about scene sections from Unite Japan 😅
SceneAsset references that define the possible tiles stored in a scriptable object. thats interesting, so they'll leverage SOs for the scene configuration (and so it can be edited/loaded with normal Asset management/importing systems). Presumably they also need to seperately make sure the referenced SceneAssets are loaded.
the rest sounds like standard dungeon tile gen, in Diablo3 all the scene tiles have exit/connector count meta and can have holes in them, that can then be filled with sub-tiles, so you get the double dynamicness of different outer environments, with switchable features inside them. its pretty cool.
thats pretty interesting
the procedural dungeon sample? or entity scenes in general?
Topher is our god basically
cool, looks very interesting
what about documentation? 😅
who needs documentation when we've got sample projects?
I am a little disappointed to see samples still using JobComponentSystem.
if you refer to https://github.com/Unity-Technologies/EntityComponentSystemSamples then that's not been updated for 2 months now (for ECSSamples)
feels like the sample repo prio has dropped dramatically now
in past there was update always after new entities package or physics package
I'm guessing the samples are getting redone again in the future(?)
oh, so it's just not pushed to us? :/
Can you pester whoever is in charge of the animation samples repo too?
I have no idea how it works internally 😀
Making some progress. My next challenge is something I can't find anywhere online about.
I need to have a reference to a GameObject in an entity, so the entity can say "gameobject->dothis". The reason I need this in a gameobject is that it's for UI and UI entities aren't really a thing.
I know how to reference to an entity from a gameobject, but I need it the other way around. Any tips?
@dark mauve look up class IComponentData
those are a lot slower and more limited than normal components, but they are "normal" C# classes, and as such, can call normal C# stuff
@vagrant surge I was using them, but they can't have a GameObject reference, because that's not blittable. Or am I doing something else wrong?
have we today a way to have presets of IComponentData with values?
something like scriptableObject but in dots world
@dark mauve normal icomponent data (struct) are the blittable ones
class icomponent data re normal C# classes
or a way to get all types from entity
Using the class gives me Entities.ForEach uses managed IComponentData ItemObject&. This is only supported when using .WithoutBurst() and .Run()
About this line
use .WithoutBurst() and .Run()😅
That's what I tried, but it doesn't recognise Run() at all
and just WithoutBurst doesn't fix it
You should use SystemBase instead of JobComponentBase
Hi. Is it somehow possible to reference a (fixed size) list/array of Entity inside a IComponentData struct?
@bright sentinel where? I'm not using JobComponentBase anywhere
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
float deltaTime = Time.DeltaTime;
JobHandle jobHandle = Entities.ForEach((ref ItemObject item) =>
{}).Schedule(inputDeps);
return jobHandle;
}
}```
This is the full class
@bold pebble Yes, you can use a FixedList<T> or FixedArray<T>
@dark mauve Sorry, I meant JobComponentSystem
It was introduced in 0.8 I believe, and replaces ComponentSystem and JobComponentSystem
Will it still use the job system if I change that though? Part of the assignment is that it must use the job component system
something like this i guess```cs
public class ItemSystem : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = Time.DeltaTime;
Entities
.WithoutBurst()
.ForEach((ref ItemObject item) =>
{}).Run();
}
}```
Well, it's pretty much the same functionality, just combines ComponentSystem and JobComponentSystem
@bright sentinel What package/version do I find those types in?
Will def use the job system
and i think without ref when working with classes🤔
@bold pebble It's either in Collections or Entities, not sure which version though
Shouldn't be too new
Thanks a lot then 🙂
Somewhat related to sjoerdtim's question. What's the "replacement" in SystemBase for "returning" the job dependencies?
var buffer = mCommandBufferSystem.CreateCommandBuffer().ToConcurrent();
var randomizer = mRandomizer;
Entities
.WithNone<THidden>()
.WithAll<SMeshID>()
.ForEach((Entity e, int entityInQueryIndex) =>
{
if (randomizer.NextInt(0, 2) < 1)
buffer.AddComponent(entityInQueryIndex, e, new THidden { });
})
.WithName("HideObjects")
.ScheduleParallel();
var buffer2 = mCommandBufferSystem.CreateCommandBuffer().ToConcurrent();
Entities
.WithAll<THidden>()
.ForEach((Entity e, int entityInQueryIndex) =>
{
if (randomizer.NextInt(0, 2) < 1)
buffer2.RemoveComponent<THidden>(entityInQueryIndex, e);
})
.WithName("ShowObjects")
.ScheduleParallel();
That blows up in my face with: The previously scheduled job RandomHideAndShowSystem:<>c__DisplayClass_HideObjects writes to the UNKNOWN_OBJECT_TYPE <>c__DisplayClass_HideObjects.JobData.buffer. You must call JobHandle.Complete() on the job RandomHideAndShowSystem:<>c__DisplayClass_HideObjects, before you can write to the UNKNOWN_OBJECT_TYPE safely.
With JobComponentSystem I would have returned inputDeps combined with the jobhandle for the two for each'es.
Dependency property
Make sure you call AddJobHandleForProducer from the barrier system you produce your command buffer from. I think that's what that error is from @gentle osprey
ScheduleParallel or Schedule basically is this: Dependency = foreach.Schedule(Dependency)
pinging doesnt work if you add it when you are editing your post Sark 😄
That might be it @zenith wyvern cause i've messed that up before.
at least not when i did it last time
From the code you showed you shouldn't need to write back to the Dependency jobhandle
It does it automatically
But should it hten just be mCommandBufferSystem.AddJobHandleForProducer(Dependency);?
@bright sentinel Got it. Thanks. Is it somehow possible to assign entities to a FixedList32<Entity> via the authoring component?
But should it hten just be
mCommandBufferSystem.AddJobHandleForProducer(Dependency);?
@gentle osprey
Yup
Now it works wonders. Thanks :)
is interface blittable 🤔
@bold pebble Probably, you'd have to do that during the conversion. I haven't done something similar, so I can't tell you a solution for it though.
If you're storing an interface as a variable it's a reference type. But in Burst you can still use an interface type as a generic type constraint to get some interface-like behaviour @opaque ledge
@zenith wyvern Can you give an example 👀 like, instead of a component type we do interface in foreach query ?
@bold pebble i tried and it didn't work😅
@opaque ledge I haven't tried it but I think I read on the forums that generics aren't supported in Unity's ForEach code gen right now, and I don't know if they ever will be. But outside the ForEach you can do:
public void SomeFunctionCalledInBurst<T>(T aStructImplementingMyInterface) where T : IMyInterfaceType
{
aStructImplementingMyInterface.someFunc();
}
👍
Can we use "Adressables" inside of unity job systems ?
Once i try to load a adressable inside a foreach query i get weird errors
Entities.ForEach(); / Adressables.LoadAssetAsync<>() | invalid il error
You can't use it inside jobs. You need to retrieve whatever you're retrieving on the main thread then pass it in.
@zenith wyvern So i also cant use it in a Entities.ForEach() lambda ?
Even when "WithoutBurst().Run()" selected ?
You can't use it in a job or with Burst. So yes you can use it if you run on the main thread and disable burst.
@zenith wyvern Hmm... Are you familiar with Adressables at all ? I did exactly what you meant, regarding the main thread... but i get a "IL Invalid Program Execution" every freaking time this system tries to run on the main thread
@opaque ledge an example https://hatebin.com/qvwqphcskm
InvalidProgramException: Invalid IL code
I'm not that familiar with addressables, I'm guessing Unity would qualify that as a bug though since that error message is entirely unhelpful. Maybe the code gen doesn't like trying to spawn threads inside a ForEach or something. Can you force the loading to happen on the main thread instead of trying to run it async inside the ForEach? @stone osprey
@stone osprey Does it not even compile, or does the error happen at runtime?
@zenith wyvern I had that "Adressables.LoadAssetAsync" in the main thread before... that worked... but due to the data oriented part i wanted to put it into a system... im gonna try if it works outside the ForEach loop in the OnUpdate method of the system 🙂 The error happens at runtime, i cant even debug that code... but without the Adressables.LoadAssetAsync it works fine
Another question from me 😅 is there a way to make sure some objects don’t get converted to entities? Once I run the game the camera, map, and UI become entities and are no longer to be seen anywhere.
@stone osprey is more support for animation out or did you write your own? Are you following a tutorial? Sorry if I can't help you but in about 2-3 Weeks I want to start working on animations aswell.
Also, can an entity have multiple buffers?
I also thought that when you close a subscene you’d still be able to see the objects, but they go completely invisible for me
I would suggest you make a bug report or post the problem on the forums @stone osprey. I'm not familiar enough with addressables to know how it might interact with the code gen. You could also check the Burst inspector to see if the generated code gives you any hints:
@dark mauve you have to do convert and inject for those since they have no representation of those in ECS
that or dont convert them at all and do interaction from MB
What if I don’t want some objects to convert?
Like the UI
I want them to stay as gameobjects
then dont convert 😄
Don't make the UI in a subscene
remove the convert script
Don’t have a convert script for them, but the subscene is probs the issue then
oooh, you are using subscene ? yeah you have to get them out of there
Subscenes are dangerous places 👀
They're the future 😄
Wasn't there a way to see the regular C# code from the generated ForEach?
So subscene objects are always entities?
Instead of just assembly
Yes
And outside of subscene they only become entities when I use the convert script?
Yep
yep basically, they are 'scenes' for pure ECS stuff
Ah great, thanks a lot
I really hope you guys don’t mind me asking so many questions btw
I feel a bit uncomfortable about it as I don’t want to waste people’s time
That's what the channel is here for
Don't worry 🙂
If we were annoyed, we could just get out of here
👍🏼🙂 thanks
oh dw, i did lots of asking back in few months 😄
@zenith wyvern Thanks im gonna do that !
Yep, when I started work I had 3 messages each day in our 'getting-started' slack channel, 3 of them would usually be consecutive messages in that channel
Oh... how do you use EntityQueries in Systems ? Its telling me that my entity query has already been disposed... I dispose it on the end of the OnUpdate method
You shouldn't dispose it 🤔
Just create it in OnCreate
Unless you dispose of the whole system, then it might be good practice to dispose everything in the system as well
If you want the system to only run when that query is met, you can also use RequireForUpdate(EntityQuery) in the OnCreate function
Hm so how do I handle this with a camera on a player? Obviously I want the player to be an entity, but the camera as an entity doesn’t seem to work
ConvertAndInject the camera as far as I know
does anyone happen to know if the presence of hybrid components on your entities impacts the performance when using just the other (blittable) components?
@bright sentinel Thanks ! So i created in OnCreate a query and for looping over it i convert it to a array... but once i run that system it tells me "A Native Collection has not been disposed"... any idea why ?
why are you iterating manually? 🤔
tbh it shouldnt, since referenced objects doesnt live on chunks
@warped trail How else should i iterate over a entity query ? I cant use Entities.ForEach for my current test... because Adressables causes crash... so i need another way to loop over a set of components
oh😅
Tells me that it "should" get disposed on line one inside the pic
So the query should get disposed... but that does not make sense
A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
he is not doing any multithreaded thing here 😅
right 😄
The System derives from Systembase... but ^ are right, im not doing anything multithread related with that query
Damn that fucks me up... no one ever used such a query inside a system ? I cant be the only one with that dispose exception, right ? :/
you are disposing of entitys, what Native stuff do you have there other than entitys? 🤔
@warped trail What exactly do you mean ? ^^ Thats the only native array in this system...
So tried out the job handle... nope, same exception
Still tells me that the "var entities = ...ToEntityArray" should get disposed
A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
Unity.Entities.ChunkIterationUtility:CreateEntityArray(UnsafeMatchingArchetypePtrList, Allocator, ArchetypeChunkEntityType, EntityQuery, EntityQueryFilter&, JobHandle&, JobHandle) (at Packages\com.unity.entities@0.8.0-preview.8\Unity.Entities\Iterators\ChunkIterationUtility.cs:152)
Unity.Entities.EntityQuery:ToEntityArrayAsync(Allocator, JobHandle&) (at Packages\com.unity.entities@0.8.0-preview.8\Unity.Entities\Iterators\EntityQuery.cs:623)
Script.Client.Environment.Entitys.Systems.AnimationSystem:OnUpdate() (at Assets\Script\Client\Environment\Entitys\Systems\AnimationSystem.cs:31)
i've had that exception before, but i cant remember how i fixed it 😛 /helpful
maybe use Dependency as your jobhandle because that jobhandle doesnt refer to anything(if this is systembase)?
How can I add something to a FixedList32<Entity> which is part of an IComponentData from inside a (bursted) job?
@mint iron Please try to remember 😉 Where did you created that query ? Where did you converted it to an array ? xD
@bold pebble use .Add() or the array indexer ref access (arr[i].prop = whatever)
wait a minute, what about those returns? 😅
if you return form Update you are not disposing of array
@mint iron: I am trying to do that but somehow the list stays empty.
@warped trail Wait... you are probably a genius
i guess you have to use continue there😅
break
you got the idea 😋
haha, yes, that jogs my memory
well probably still continue, but the current logic is equivalent to break
@bold pebble the collection source looks fine, are you trying to add it to a copy of the struct rather than using the ref'd one directly
@warped trail You are the best, thanks ! That solved my issue ! I converted that from Entities.ForEach where i used the return because we cannot use continue or break in there... totally forget that 😄
we should put a document together 'if the exception says this, this is probably what you're doing wrong'
Ok that works fine... so if someone should ever use "Adressables"... dont do that in Entities.ForEach loops... its not gonna work rn
@mint iron I suspect it has to do something with ref/copy (or readonly). My code: https://pastebin.com/LTBjGYgm
(I added line 16 for testing but that didn't help)
wait a minute, ship is just a copy😅
Ah I see. Beacause it's readOnly?
you have to do something like thiscs shipGetter[registerAtParent.Target] = ship
you get a copy of component with thiscs var ship = shipGetter[registerAtParent.Target];
if you want to change it, you have to assign it back😅
Ah I see. But now I run into the readOnly problem
you have command buffer there😅
Thats also interessting... i just replaced my entityquery with a "entityManager.GetAllSharedUnqiqueComponents" and its 10 times faster...
@warped trail So you mean I can somehow use the command buffer to update the ship component?
something like thiscs commandBuffer.SetComponent(registerAtParent.Target, ship)
but this change won't be immediate
or if you know for sure that you safe, you can disable restrictions and set it through cdfe🤔
and btw you can use GetComponent<T>(entity) inside foreach😅
less code
So I just tried that via the command buffer. This will however overwrite the component with each command and the list will then only contain the last component
Hm, but GetComponent is not available on JobComponentSystem
oh, you are using outdated stuff 😏
Hm, that seems to be a recurring theme for me with DOTS ^^
so you have a lot of entities, which writes to same place?
I have a Ship with 8 Thrusters which should register at the Ship (FixedList32) at startup.
Alternatively the Thrusters could also be assigned via the Authoring component but that would prevent addition/removal of Thrusters at runtime
Btw. JobComponentSystem is outdated? what should I use instead?
SystemBase
Thanks. I will try to migrate everything then.
just run this loop on a single thread, then you could just assign everything via cdfe😅
my naïve advice 😉
or use dynamic buffer🤔
I had a dynamic buffer before but tried to migrate to a fixed list
@warped trail I now run the thing single threaded and migrated to SystemBase. Is there still some unneeded/legacy stuff left now? 😄 https://pastebin.com/XEuxFjmJ
I see. thanks. Btw. what is the difference between Schedule and Run then? I See there is also ScheduleParallel
run mainthread, Schedule singlethread on worker thread, ScheduleParallel() as parallel as it can get 😅
Got it. thanks
The whole World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>(); then var commandBuffer = _entityCommandBufferSystem.CreateCommandBuffer(); and commandBuffer.RemoveComponent<RegisterAt>(entity); still feels a little bit verbose. Is there some shortcut like "PostUpdateCommands.RemoveComponent" or so?
no
I see. It just felt like there should be a shorter way of telling ECS to globally remove all components of a certain type
and how it should decide at what point in frame it should do it? 😅
It would be after the last system ran which depends on this Component (which would be only 1 in my case). Or even at the end of the update.
I also wouldn't mind calling a method at the end of my OnUpdate
Maybe it would also be possible to have "RunOnce" component which is removed by a dedicated system at the end of the frame
you can do this yourself😄
Yes, but I'm still pondering on how to handle multiple types of "RunOnce" components.
I stayed up all night trying to figure this out. Sebastian on the forums says we should get our entities from the V2 conversion off prefab, and I've tried. But this thing just flat doesn't render. All the necessary components are there on the resulting entity, but... nothing.
Position and rotation are correct too. I checked it against the manually constructed entity I can already get to render, and my positioning system put it in the right place.
Actually... FrameDebugger is showing 1 vertex on the draw call. Yet the mesh is generated exactly as it is if I manually build the entity.
I swear, no step of anything is easy in Unity.
That's a weird way to convert a prefab. What does your entity debugger say? Does it show an entity with all the right components?
Sorry I saw you said that, what I mean is have you verified it in the entity debugger instead of just assuming?
I just figured it out. Up all night, and wouldn't you know, as soon as I verbalize the problem to someone else, BAM! I got it.
This is wrong:
quadMesh.triangles = new int[6];
This is right:
int[] tris = new int[6];
// do stuff to tris
quadMesh.triangles = tris;
Coming from a C++ background, I don't see the difference.
Also, it's weird because it's purely procedural 😄
Oh right, the getters for mesh properties return copies instead of returning the actual underlying arrays
I'm not sure your original code would have even compiled if they returned the underlying arrays
I guess it would have. But yeah that's more a quirk of how Unity chose to design their mesh properties. For whatever reason they chose to make them return copies.
How does assigning tris to the copy end up putting it in the underlying array though?
I'd expect it to get assigned to the copy, and happily continue on out of local scope, blinking the tris out of existence.
The getter returns a copy, the setter assigns to the actual underlying array
(facepalm) I keep forgetting about C# getters and setters.
Like I said I have no idea why they chose to make it return a copy. I'm sure they have some good reason
Probably for some kind of memory safety reason.
Yeah properties are a constant source of annoyance when you're getting used to C#
Lots of hidden rules
Worth it though. Having stuff like Linq and managed memory without having to take it down to C is awesome.
Definitely. In this case having the same property return a copy and assign to the underlying array is not great design, but maybe it's a typical thing in C#
awesome until you want performance 😋
Better to have two separate functions with clear naming
First test up, I'm seeing worse stability having V2 build the entity off a prefab. I can get to 38k entities, 2000 instantiations at a time, and then get a swapchain crash. Building entities manually, I can go 2000 at a time until 788k, and still don't get a crash. My processor just gets too bogged down.
Going to try taking it down to smaller batches. Maybe all those extra HDRP components are leading to more data sent to GPU.
500 at a time, it crashes sooner (17k instances)
5k at a time, 65k entities. So, we should instantiate as many as possible in one pass doing it this way. Exactly the opposite of building entities manually.
i just instantiated 250k at once, no problem 😅
and default culling system is pretty good, if not borderline awesome🤔
Are you instantiating entities directly in a buffer, or instantiating prefabs?
You could probably get it even faster using a NativeArray. But presumably you have some setup to do for each entity
Okay, I'm messing up by doing it in a ECB then.
Naively, I'd think skipping the converter step would be more performant and stable (asking for less work to be done)
you are not paying for conversion🤔
Conversion should happen in the editor or once when you hit play
with subscene at least
The only cost should be Instantiate
Which should be very fast since the conversion should be done already
Hmm I'll show my spawner. 1 sec. I'm not keeping a game object around, so that might be my mistake.
Not using subscenes either, since it's all procedural.
For now I think the best way is to set up your entity prefab as a gameobject prefab and use conversion system to create your canonical "Prefab Entity"
It sucks but that seems to be the way they want us to do it
That has a test set up for 500k entities at 7k a pass (crash at 98k on my system)
I can't imagine why, except to keep us chained to the editor. Which kinda sucks if you want to make something like a ECS UI where the developer to use it should only see the result of editor field entries.
Conversion workflow is here to stay. If you avoid it you're going to be fighting their intended way to do things the whole way
Roger that. So, I better get used to it. This has been a learning experience though, so I wouldn't call it a waste.
I don't see anything unusual about your instantiation, it looks like you're not doing anything fancy
So not sure why there would be performance issues
But I'm instantiating entities directly. So, this isn't the wrong way?
If you need to make unique changes to each entity you are instantiating then what you're doing is the right way as far as i know
From what i can see you might be able to get away with a batch operation though
In my use case, I will need an arbitrary number of UI forms at runtime. Ideally in the end, they'll be on world canvases. So, yeah, they'll need further changes after instantiation. For now, I'm just trying to achieve what I've seen others can do, because I know I'm doing it right then.
There's a version of EntityManager.Instantiate that takes a NativeArray. You give it a prefab and a NativeArray<Entity> set to whatever size you want and it will fill it VERY quickly with copies of your prefab
When you say "prefab" in this case, this needs to be a GameObject native array?
No, entity prefab
Okay, I'll give that a shot. Time for coffee first though.
just some entity, which you wish to copy😅
According to the API there is an overload that takes a GameObject prefab as well
Feels like I've been grinding at this milestone forever. By now, I thought I'd have moved a camera to ECS to sync camera with quad movement (weird jitters if you don't), and replicated rect-based UI stuff.
People who can estimate development time are wizards. Or prophets.
Heretics
😄
can you still add entities to locked chunks?
Nope. No structural changes as far as I know. You can only change component data
mmm, i see, they remove it from chunk->Archetype->EmptySlotTrackingRemoveChunk(chunk); on lock so it wont be picked up as a candidate with empty slots when adding entities.
for some reason i thought adding entities would be fine since its just adding more data and the archetype of the chunk doesn't change.
If it's locked they promise the order of entities won't change either
Hi. I have a subscene with "auto load scene" checked in my scene. When I play in the editor it loads fine, but when I build the sub scene is not loaded. Do I need to manually load subscenes in a build regardless of the auto load flag, or is there something else I am missing here?
how you build your game? 😅
just playing around to understand how to work with subscenes right now. I just have one scene that I build which has this subscene in it
i mean which tools are you using to build🤔
with subscene you have to use new build tools
ah, then that is probably what I am missing 😬 where do I find the new build tools? I am new to dots and struggling a bit with navigating the documentation
i just copying files from here😅 https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/BuildConfigurations
ah, okay😅 thanks!!
I can't find this anywhere but it feels like it must exist and I've seen mention of people asking how it works with no replies before.
Can EntityArchetype extend or parent off other archetypes?
What do you mean? Like have a base archetype with "sub-archetypes" that have all of the base archetype components plus extra ones?
Yup, space game so everything requires physics, translations, rotations, rendering local to world etc, would be much cleaner to setup a couple parents and inherit from those with what's needed
I don't know if there's anything built in, but I know you can do EntityArchetype.GetComponentTypes() to get the an array of types in an archetype.
Then you could add new types to the array and create a new archetype from that.
EntityArchetype is a struct, so you cant inherit from it.
Yeah I was considering setting up a method for handling it manually, just wanted to make sure there wasn't a built in way. Wanting to do things right, but also because I'm a bit of a C# noob and array management is still so counter to every other language I use.
I currently have a static class for storing all the archetypes so not difficult to add to it.
You could probably write an extension method where you pass in new types to automatically create an archetype with the archetype's base types + new types
I just managed to crash Unity so I must be on the right track!
I switched to instantiating with EntityManager, into a NativeArray, and I still get a swapchain crash.
In fact, it's considerably slower and crashes more easily than instantiating in a command buffer.
It's getting hard to believe these people who claim to render hundreds of thousands of entities, instantiated all at once.
It's starting to become more believable that they're using compute shaders instead of batch processing.
Huh, I thought using EntityManager with NativeArray was supposed to be substantially faster, I guess not
probably because they just made ECB playback bursted.
or maybe counting the speed in the system rather than the CommandBufferSystem being used for playback 😄
Note, I can instantiate any number of entities if I add the DisableRendering tag component first.
@gusty comet You may want to take a look at https://docs.unity3d.com/Packages/com.unity.entities@0.9/manual/exclusive_entity_transaction.html?q=ExclusiveEntity
But there are people claiming to render in the 100s of thousands
I've never used it before but it sounds like it's made exactly for your scenario
It does, but I got the impression from posts on the forum that world creation isn't supported yet. Still, haven't tried it, so it's worth a shot.
I just checked my stress test, I can render 250k static cubes with plenty fps to spare
In the editor no less
Using URP 9 with Hybrid v2
Maybe it's having them marked static that is making the difference?
They're not marked as static, I just mean I'm not moving them
Saves the work from the transform system and having to recalculate renderbounds
If I move them all it performs substantially worse
That may be it then. I'm rotating them behind the camera.
It's my way of getting around the problem of adding and removing tag components leading to lots of rebuilding chunks, since one-sided quads rotated behind the camera should be hidden from view in two ways.
Actually, I was wrong. I already stopped rotating them.
Well my profiling seems to show that the transform system and recalculating renderbounds is a massive performance hit for large amounts of objects. What does the timeline on your profiler show?
Gfx.WaitForPresentFromGraphicsThread
Waiting for a signal from the GPU. That's half a second for instantiation of 2000 quads, whether rotated or not.
Which is weird for two reasons. Without the rotation, computation should be cheaper (CPU side), but with the rotation, they should be culled (GPU side).
With 25k quad entities instantiated, the SRP Batcher has enough verts and indices for 29 quads. So, there's a limit to batch rendering from the same quad.
I'd suspect my hardware, but it runs Beat Saber at 4k resolution and 90fps just fine.
Hello, I have a native job dependancy question. I have a large number of jobs (work jobs) each writing data to a different temporary NativeContainer, and I want to coalesce the previous results into a single final NativeContainer (merge jobs).
I can create a sync point between the work jobs and then schedule the merge jobs sequentially but that's not optimal.
Is there a way to run the merge job as soon as the corresponding work job is complete, while maintining sync? (In a producer/consummer kind of way?)
180k quads, constant up/down and constantly facing camera, cpu 95%, gpu 60%, URP😅
I don't know what I'm doing wrong.
Pretty consistent with mine. I have a pretty beefy PC so my limits higher but yeah
Are you sure you have burst enabled?
Yep.
just copy SpawnFromEntity codefrom ecs samples for test🤔
Looks like I'm already doing something pretty close to that. So, shouldn't take long to convert. I could have sworn I read through that last night.
Oh this is maddening, If I try and use PhysicsVelocity in a pure ECS component it just decides to up and NaN all position, rotation and local to world variables. Can find a couple posts about it with 0 solutions and nothing else. But if I convert to entity physics works fine.
Yeah, as I'm discovering, they want a very specific workflow.
@spice venture you can just schedule all your jobs and scheduler will run your jobs in right order🤔
like your last job won't run, until previous jobs which writes to native containers finished
Is there automativ dependency management from NativeArray usage? I expect safety errors If I try to write to the same NativeArray from parralel jobs.
if they are in same dependency chain
like JobB depends on JobA
you can combine dependency
like if JobB writes to nativeA and JobA writes to nativeA, JobB won't run until JobA finished
Without having to use any JobHandle chaining when scheduling jobs? That's neat.
you have to use JobHandle chaining😅
I'll try to reframe my problem:
I have jobs A1, A2, A3 ... that can run in parallel
For each of this jobs, I have merge jobs M1, M2, M3, ... that write to the a common array. So M1 depends on A1, and so on.
The problem is that I don't know if which order the A jobs will finish, so scheduling M1, M2, ... in order isn't optimal.
(Unless I wait for all the A jobs to finish, but that's wasted time to)
schedule A1, A2, A3, combine depenencies and schedule M1, M2, M3🤔
Well that's a sync point, and that's I'm trying to avoid.
There could be one lone worker thread finishing its A job, while other threads are idle
But I think I have a (negative) answer there: https://docs.unity3d.com/Packages/com.unity.jobs@0.1/manual/scheduling_a_job_from_a_job.html
combining dependencies doesn't not mean you are waiting for A1, A2, A3 to complete🤔
Well it does if M1, M2... depends on the combined handles of A1, A2, ...
Unless I didn't understand you?
Sorry if i'm not clear enough 😄
it will look something like thiscs var jhA1 = JobA1.Schedule(); var jhA2 = JobA2.Schedule(); var jhA3 = JobA3.Schedule(); var jobHandleA = JobHandle.CombineDependencies(jhA1 ,jhA2 ,jhA1); var jhM1 = JobM1.Schedule(jobHandleA); var jhM2 = JobM2.Schedule(jobHandleA); var jhM3 = JobM3.Schedule(jobHandleA);
Doesn't that mean M1, M2, M3 will be waiting on ALL of A1, A2, A3 ?
if nativeContainer is not blocked by any job it will run
I need to read up on jobhandles
does anyone have a more in depth explanation on how ComponentDataFromEntity works? Why do I need do use GetComponentDataFromEntity from a job to make one? Is it because of thread safety?
There is a video https://www.youtube.com/watch?v=KuGRkC6wzMY
Interaction is fundamental in games, both in how players interact with a game and receive responses, and in how parts of the game interact with one another. Unity’s Entities package provides a variety of options for writing systems where entities communicate information to one...
although it is not really that in depth
I was just kinda curious what's going on under the hood. What's the reason to not just make a whole bunch of ComponentDataFromEntity from the beginning instead of in each job?
ty, tho, I havent seen this video yet
https://youtu.be/KuGRkC6wzMY?t=1037 is the specific time where they start taking nabout them
Interaction is fundamental in games, both in how players interact with a game and receive responses, and in how parts of the game interact with one another. Unity’s Entities package provides a variety of options for writing systems where entities communicate information to one...
"What's the reason to not just make a whole bunch " I think it makes job scheduling more xomplex, if each job has access to 20 different types of components, it makes it harder to know when its safe to let something read or write
thanks, that's kind what I was suspecting
Okay, so in V2, SpawnFromEntity is broken. The converter never picks up registered prefabs, and it's impossible to get it assigned properly before the spawner job tries to run.
But at any rate, I really don't see how this is any different from spawning from an entity obtained through the ForEach query.
This is my spawning system for my test scene https://hatebin.com/aqnqlgrwup
The prefab authoring script: https://hatebin.com/qwwgogyzhm
That's it. I put my authoring script on a unity cube and add a ConvertToEntity. From those two scripts I get 250k cubes rendering.
@gusty comet
This is with URP 9, Unity 2020.1b3.
Okay, so my real problem is the workflow. They're forcing us to spam the editor to the point that it'll end up useless.
I don't know what you mean by "spam the editor"
I'll need a primitive built-in prefab dragged into the scene hierarchy, which is going to mean every kind of quad and every unique piece of geometry will need one too.
No, you just need a renderable gameobject. Convert it then set the mesh at runtime
All your renderable entities can come from one single prefab, and you can just give it the appropriate mesh when you instantiate it
Same problem following your example. Convert() is never called.
You need to have a ConvertToEntity script or have your gameobject in a subscene for it to be converteed
That's it! Haven't even tried it yet, but I bet
You should really have a better grasp on the basics of using ECS before you try to do something so advanced. This is covered in the second example https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/HelloCube/2. IJobChunk
I was trying not to use gameobjects at all. That's why I scanned over the gameobject based examples.
They aren't really gameobject based, everything at runtime is always an entity, in every example. Gameobjects are only used for authoring. As has been said, it's annoying but it's the way they want us to do it
Well, I can testify. I've been trying to get around that for more than a week, every day. It's technically possible, but at extreme performance and stability cost.
From what I can tell it seems like you'll save yourself a lot of time and headache if you just take a step back and go through the examples in detail. Take your time, learn how to do it right. It'll save you time in the long run
I'll start reading over them tonight. Meantime, that one script was the issue with getting the game object converted.
Is there some kind of "manifest extension" that can sit in the Assets folder that just lets you add on github references?
I know I can use the Package Manager client to programatically add packages
but that makes me have to deal with editor callbacks and feels clunky
453320 quad limit, in any combination, and then the hybrid renderer fails a bool assert. That's a success though. Thank you, @zenith wyvern and @warped trail . Now to stop and read
Just to be safe, is it smart to use functions like this with the JobSystem? https://pastebin.com/3SS8pSXf
Or would you guys suggest me putting the code directly in the lambda's?
Part of the reason I do this is that I plan to have quite a bit of code with different functions here
Another question: How do I find a different component system and call a function there.
For example, in my pickup system I want to do itemsystem->additem. How do I get the itemsystem from the pickupsystem?
{
base.OnStartRunning();
ItemSystem itemSys = ???????????????????;
Entities.WithoutBurst().ForEach((Pickup pickup) =>
{
itemSys.AddItem(pickup.m_ItemType, pickup.m_Amount);
})
.Run();
}```
World.GetExistingSystem<T>()🤔
Thanks 🙂
I'm not so sure about the functions though. I don't really know how they even work with Burst, but it kind of seems like you may just want to schedule more jobs? 🤔
I'm also not sure about the performance on calling functions
I know there are some function pointer stuff, but that may be unrelated
This is what I have right now
ItemSystem: https://pastebin.com/w8TcKzWB
PickupSystem: https://pastebin.com/kpfnWSYf
I'm not sure if there is any better way to do this
My assignment says I have to avoid MonoBehaviors wherever possible and use the ECS and Job systems
but with this approach it will be hard to use jobs🤔
Am I not using jobs already here?
I have no idea what other approach I could take with this
hello 👋
is there any way to set instanced material properties through the hybrid renderer using RenderMesh? the documentation is a little sparse... https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.4/api/Unity.Rendering.RenderMesh.html
I found this, but no idea what it does: https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.4/api/Unity.Rendering.RenderMeshSystemV2.html
you can, but with hybrid renderer V2 🤔
I am using hybrid renderer v2
using 2019.3 and BRP 
then you are not using hybrid renderer V2😅
yes, i expect you're right 😄 V2 was set in the scripting defines but from reading this page again it's clear V2 isn't supported in 2019.3
trying to upgrade now
upgraded
unsure as to whether this is a typo

still trying to figure out a better way to get values from a NativeMultiHashMap. because a Enumerator is a bit slow. (around 100 ms more than without)
do you want all the values or a specific value
it shouldn't be that slow, are you using burst?
is your equality implementation slow maybe
What do you mean by that?
i mean they test each key by calling the equals method (IEquatable<T>), so if you're using your own structs for keys, and your equals method does a lot of work, that would slow it down.
if thats still too slow, you could use a normal hashmap that returns an index+count for your own array of values.
it could be the cause, since its ran about 40,000 times
so to solve this I just need a unique identifier on each? like a index
for the key or value?
well the key is the struct
dependa on what you're doing with the values too, for example, the key will be accelerated by hashing, but once you get the values back, if you have 40,000 values and only need a specific one, then you're wasting a lot of time iterating values.
well its not 40,000 values, I'm saying that the Enumerator loop is done 40,000 times
and each key has 64 values
are you iterating every key or using TryGetFirstValue ?
maybe posting some code would help me understand.
this is what I do
public NativeArray<Color32> GetSprite(TerrainSprite data) {
NativeArray<Color32> colors = new NativeArray<Color32>(terrainSpriteSize * terrainSpriteSize, Allocator.Temp);
var valueEnumarator = colorTerrainTypes.GetValuesForKey(data);
int i = colors.Length - 1;
while(valueEnumarator.MoveNext()) {
colors[i] = valueEnumarator.Current;
i--;
}
return colors;
}
one big 1d array😋
you are taking all values? there should a be a block copy method to get them all somewhere.
Yeah I'm getting all values for a key
which is the slow part
or well specifically the loop
yeah :(
i wouldnt use it then in your case, i'd put the data elsewhere, use hashmap to lookup the key, and get something back that can let you quickly find the right block of values.
Yeah I know one alternative is using a 1D array but it wont really work because I have that struct with 3 indexes
other than that, I'm unsure
can you explain that for me a bit more, i dont see the problem.
well I guess its just mainly me, I dont know how to get the correct values if its a 1D array
sine again, I have those 3 indexes
no, the indexes in the struct, "public int terrainID, variantID, bitMaskID;"
thats in TerrainSprite?
yeah, thats all the TerrainSprite does
it would be good if I could have the color array in there intead
and your equals presumably checks each one
yes
public bool Equals(TerrainSprite other) {
if (other.terrainID == terrainID && other.variantID == variantID && other.bitMaskID == bitMaskID) return true;
return false;
}
yeah, thats fine, you can just have that in a hashcode.
may sound dumb but whats a hashcode
umm... basically everything in c# has a GetHashCode() method, and it returns an id.
right yes, I just return 0 in there lol
some of the default containers use it for stuff, Dictionary etc
so, what should I do instead in there?
you could have a NativeHashMap<int, DataLocation>
public struct DataLocation
{
public int FirstValueIndex;
public int ValueCount;
}
and then put all your values in a 1D array
the key is the hash of your three fields in TerrainSprite
it gives you back this DataLocation, which u can use for the colors array
I dont really understand the hash thing
no worries, ill write you some code
read this https://stackoverflow.com/questions/371328/why-is-it-important-to-override-gethashcode-when-equals-method-is-overridden and https://docs.microsoft.com/en-us/dotnet/api/system.object.gethashcode?view=netframework-4.8
so in GetHashCode I have to return terrainID, variantID and bitMaskID combined?
right
so just terrainID + variantID + bitMaskID?
woah woah
just doing that changed it from 350ms to 80ms
I'm trying to count time up to a duration for a certain action. So I store "elapsedTime" and "Duration" on and Entity. I want to expand on that and make it possible to store more then one "elapsedTime" for multiple actions.
How can I store those different values? I thought of a buffer element on my entity, but how would each system know which element inside the buffer is the correct one?
@mint iron thank you! I wasnt expecting such a big improvement from just changing that
Straight adding might be fine depending on what those Ids are, but this below is probably less likely to have collisions (but will be a bit slower)
public override int GetHashCode()
{
int hash = 13;
hash = (hash * 7) + TerrainId;
hash = (hash * 7) + VariantId;
hash = (hash * 7) + BitMaskId;
return hash;
}
it lets you store just an int in the hash map, which is going to be faster to lookup than calling equals on every IEquatable struct like MultiHashMap does. Well, maybe, i mean if the Equals method jsut returned a field and/or gets inlined then it would be the same as comparing an int. But C# also does some weird shit with equals and boxing so you have to be careful, unity was using IComparable on their collections for a while to sidestep some of those issues, but it seems maybe now they've just made burst work around it on compile.
Yes I got that but whats the difference between the GetHashCode method you sent and the one I used at first?
is it to make sure the hash is different than others?
Yes - otherwise collisions could be pretty common
Is there a simple way to destroy an entity when looping through a foreach loop?
For example in:
{
if (player.m_Collider.bounds.Intersects(pickup.m_Collider.bounds))
{
inventorySys.AddItem(pickup.m_ItemType, pickup.m_Amount);
EntityManager.destroythisthingsomehow???
}
})
.Run();```
There’s also a general c# one you can use. Something like ‘new {var1, var2 etc}.GetHashCode()’ (sorry on phone)
cmdBuffer = someCmdBufferSystem.CreateCommandBuffer();
Entities.ForEach((Entity e, in SomeType c0) => {
cmdBuffer.Destroy(entity e)
}).Run();
for the hash stuff you could also try xoring some values together too
@odd cipher here's the basic idea i was trying to explain earlier https://gist.github.com/jeffvella/1fd3b14b74dbc0208251366316d6f7ff (untested code)
Thank you, ill take a look
@coarse turtle what cmdbuffer system would I use? I haven't created any
All I want is the entity equivalent of Destroy(gameObject);
there are 3 (or 4) command buffer systems unity provides, you can pick one that fits you needs depending on the system group
in your case you can use something like this😅 cs var ecb = new EntityCommandBuffer(Allocator.TempJob); Entities.WithoutBurst().ForEach((Pickup pickup) => { if (player.m_Collider.bounds.Intersects(pickup.m_Collider.bounds)) { inventorySys.AddItem(pickup.m_ItemType, pickup.m_Amount); ecb.Destroy(entity); } }).Run(); ecb.Playback(EntityManager); ecb.Dispose();
That too works lol
you can event use EntityManager, cause you are using Run() and WithoutBurst()
just add WithStructuralChange
but keep in mind that your approach is single threaded 😅
and without burst🤔
like what the point of using ecs then😅
Well
I couldnt use multithread because I had to refer to a ScriptableObject
which isn't a blittable type
So I had to go from struct IComponentData to class IComponentData
and then it required WithoutBurst and Run
@formal scaffold you could make a different timer for each purpose, PendingDestructionTimer and then SpawnAfterDelayTimer etc, or if you only ever have one timer happening at a time, but want to share a component u could put a flags enum field with the purpose of the timer in there as well.
Yeah then the EntityManager.Destroy(e) might work for your case @dark mauve if you cant convert your scriptable obj to a runtime blob asset or something similar to that
@warped trail ecb.Destroy() doesn't exist. ecb.DestroyEntity() tells me pickup cant be converted to entity
@coarse turtle EntityManager.destroy(pickup) doesn't work either :/ (cannot convert from Pickup to Entityquery)
you could move your data into a struct inside your scriptable object, and then pass that in instead (assuming u can get it from outside the entities.foreach)
@mint iron ehh but then I can't predefine it in Editor
also the data in the struct has Texture2D which also isn't blittable
then move to struct everything you can🤔
I also had a GameObject reference in there for UI that I had to work. Spent the entirety of yesterday trying to get it to work with struct, but eventually just gave up and went for the class. It'll have to do for now
I'm doing this as as training assignment where the goal is: don't use monobehaviors and use the ecs and job system, so as long as I do that, I think I'll be alright.
Still haven't figured out the destroy entity thing though
Well this works 🤔 which is what @warped trail was stating
What's the RecurseGetRoot() function? I can't find it anywhere
no no no that's my function lol
i just stuck it in the a system that I'm working on
the destroying functionality
So I should just use EntityManager.DestroyEntity(pickup);?
well if pickup is an entity and you can't get around without using the EntityManager then that make sense
Still tells me I can't convert it to EntityQuery though
Well you have a couple of ways to destroy the entity/entities from the EntityManager
It should recognise it as entity.. not sure why it keeps telling me it can't convert it
is this vim?👀
@mint iron it seems some have the same HashCode and then it says "an item with the same key has already been added"
You can pass in an entity, a query, or a collection (array/slice) of entities for the EntityManager to destroy - pick how you want to handle destroying it
@warped trail yes 👀
It does work when I use Entity instead of Pickup as the type in ForEach loop, but then I can't access Pickup's variables
Since Pickup is an entity it should work fine using Pickup, or am I forgetting something?
hmm maybe show the code? it's hard to tell what pickup is from this context
{
Entities.WithoutBurst().ForEach((Player player) =>
{
Entities.WithoutBurst().ForEach((Pickup pickup) =>
{
if (player.m_Collider.bounds.Intersects(pickup.m_Collider.bounds))
{
inventorySys.AddItem(pickup.m_ItemType, pickup.m_Amount);
EntityManager.DestroyEntity(pickup);
}
}
)
Run();
})
.Run();
}```
That's the full function
make it like this ForEach((Entity entity, Player player)
and EntityManager.DestroyEntity(entity);
If you do that it uses both?
what do you mean both?
So if I use ForEach((Entity entity, Pickup pickup)) I can use both pickup for the pickup's variables, and entity for the pickup's entity?
protected override void OnUpdate()
{
Entities.WithoutBurst().ForEach((Player player) =>
{
Entities.WithoutBurst().ForEach((Entity entity, Pickup pickup) =>
{
if (player.m_Collider.bounds.Intersects(pickup.m_Collider.bounds))
{
inventorySys.AddItem(pickup.m_ItemType, pickup.m_Amount);
EntityManager.DestroyEntity(entity);
}
}
)
Run();
})
.Run();
}```
someone should read documentation😅
That's all I've been doing these past days. Just trying and reading and watching tutorials, but it's still been pretty difficult to wrap my head around
Well the lambda foreach doc page shows the typical structure of how to write the lambda, if you're interested in how it works under the hood - it might be worth looking into how ArchetypeChunk.GetNativeArray(ArchetypeChunkComponentType<T>) works via the source code
@mint iron sorry for ping again but are you there?
Alright. Thanks a lot for your help @coarse turtle
Arghh I thought it worked but apparently now I get "Structural changes are not allowed during entities foreach"
I have that 😦
Only on the inner loop though
But the other I dont destroy anything in
Ooh doing it on the outer fixed it
Not sure why but fine for me
@odd cipher if the hashamp wont handle collisions then you'd need to make sure all the keys are unique
either way, I tried ignoring the ones that arent unique and that worked with a semi deformed world and the timings are still 90
I think ill stick with NativeMultiHashMap, the main problem was the GetHashCode
also realized that its actually 30ms, 90 in editor
Hey guys, I have a question concerning Unity.Physics, ECS and rendering. Carrying this over from #archived-hdrp , I found out that HDRP and the Hybrid Renderer don't play well together in regards to rendering entities, mainly for indirect lighting. However, Unity.Physics (+Havok) requires entities to work and regular GOs either don't register or breaks collisions altogether. Running in Convert and Inject GO mode breaks Unity.Physics as well.
Is there a way to make use of Entities without having to give up HDRP and AFAIK; ECS systems copy over data from the GO during conversion and attempts to create a new Entity that has the EC equivalents of the GO components in-built from Unity. However, those EC equivalents don't have the exact same functionality as their GO counterparts or outright don't exist and in Convery and Inject mode, the data is copied between the GO components and the Entity components (sync). is this correct?
For what I want to do, and for learning purposes, I want to make use of Havok Physics and ECS performance but I would very much like to use HDRP.
Anything wrong/things to note about my understanding and options/tips for combining these libraries? Thanks for any feedback/help.
if you want to use inject with physics, you will just need to create your physics entities manually
https://docs.unity3d.com/Packages/com.unity.physics@0.3/manual/interacting_with_bodies.html towards the bottom has some sample code
is there a resource for how to use the new unity input system with DOTS/ECS?
@safe lintel Thanks for the pointer. One problem and clarification, this issue mainly exists for world static objects like terrain and buildings. I assume the intention is to create a completely separate entity with the same collision mesh and world data as the GO, basically overlapping the GO itself. Is this process very memory intensive as you're essentially creating the world twice?
@opaque escarp https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/d616c1b077c306e6f31b41a3970799e4b132139b/UnityPhysicsSamples/Assets/Common/Scripts/DemoInputGatheringSystem.cs this script is what i used to base my own system on
@raw mica I think for environments the idea is to have them in all layed out in a SubScene, because it then gets compiled into a big block of memory which can be loaded in one go, cutting out any kind of processing time from the equation. Obviously a problem for dynamic content but you can get away with building tools to generate enough variations in the editor, and then switch them out/connect them together or whatever at runtime.
well i guess it depends on the scale of your project. something like megacity wouldnt work with gameobjects, but a small project might not be an issue at all. running multiple physics for hitboxes on good old skinnedmesh renderers personally and its not a big deal with multiple enemies
How do I control the camera via DOTS (it should follow/lerp to the player entity)? I tried to add a ConvertToEntity component to the camera, but this seems to break with post-processing. I am using URP with a global volume. Also adding ConvertToEntity on the volume doesn't work.
The ideal scale (not my current experiment) is using sub-scenes for a dynamically loaded world. The problem is physics interactable entities, like trees (knock them down with impact force), I'm thinking as a workaround to just spawn that particular trees' Entity and simultaneously delete it's GOs on interaction/event.
But then the collisions will fail regardless if the entity does not exist in the first place.
Sub-Scene world "streaming" I imagine will become memory heavy with this.
besides hdrp what else do you need gameobjects for? i would just truck on and ignore the graphical limitations for now
The problem is the graphical limitations will ruin any form of indoor lighting without a ton of light sources since light doesn't bounce properly: (from #archived-hdrp ).
I'm trying out some things with URP right now so this is not an immediate concern, but it will be when I start using HDRP for full on projects.
well yeah this is a limitation with whats available. theres a team working on the hybrid renderer fulltime now i think so hopefully its remedied sooner than later but id just get used to it, designing some sort of split gameobject/entity world based on whats temporary might give you more problems down the road than is worth
Is this particular issue on their roadmap? I should probably go check.
anybody ran into this error when building for iOS? No member named 'get_address_of_ecb_0' in 'U3CU3Ec__DisplayClass5_1_t713C0FF0AFF2CC377EAAE683E9F7D820B8BCB45B'
What exactly is a dynamic buffer? I'm reading the manual and I'm not really understanding
I'm trying to figure out how to hold a set of data in a component, like a list, and "a variable-sized, "stretchy" buffer" doesn't really.. uh.. what? I mean supposedly this is what I want but.. ye idk
It's just a resizable list you attach to an entity.
There's a bit more to it when you're concerned about how much space it takes up inside a chunk but it's easiest to just think of it as a resizable list on an entity until you're more familiar with ECS
Ok, yeah I have yet to actually use it outside of playing around in an empty project
So I found a MonoBehaviour called GameObjectEntity and one CopyTransformToGameObjectProxy which seem to be able to sync transforms between Entities and GameObjects. Is my guess correct? And how exactly can I link a GameObject with a certain Entity? Could it be AddToEntity and why is this static? The documentation is not very verbose about it... (https://docs.unity3d.com/Packages/com.unity.entities@0.0/api/Unity.Entities.GameObjectEntity.html)
also that doc is very old. latest : https://docs.unity3d.com/Packages/com.unity.entities@0.9/api/Unity.Entities.GameObjectEntity.html
@bold pebble Those components are old and not compatible with the conversion system. I imagine they will be deprecated at some point. Linking gameobjects to entities is kinda hacky right now. Read this article to learn about it https://gametorrahod.com/game-object-conversion-and-subscene/
@zenith wyvern Thanks. That's a pretty long article. 😮
@zenith wyvern wont say hacky. you can have simple read/write system before/after simulation group that do the syncing
Yeah you can pretty much skip the first part, the "Conversion Workflow" and past that is what matters
So my goal is (just) for the camera to follow the player (which is an entity). Should I have a system which runs after physics and reads the player position and updates the camera pos accordingly?
If that's all you need then yeah that's reasonable enough. You can use ConvertAndInject to attach your camera to an entity so you can easily update it inside a system that's set to update in the right place. The article goes over convert and inject as well
@zenith wyvern When I put ConvertToEntity on my camera it will break the post processing. But thanks for the hint. I will go over the article.
@zenith wyvern For some reason the post processing will start to work again if I select "Convert And Inject GO" and then modify any property of the camera in the editor. 🤪
That sounds like something that would only happen in the editor, I'm guessing it wouldn't happen in a build
In this link (https://docs.unity3d.com/Packages/com.unity.entities@0.9/manual/ecs_entities_foreach.html) there is an example of using the entity query generated using Entities.ForEach. At what point does that ref entity query actually get assigned? From the example I would assume at the start of OnUpdate, ie it can be used for preallocation of native arrays to write during the foreach?
(the section is Accessing the EntityQuery object)
(I realise the example is explicitly saying it can be used for preallocation - it just seems like black magic for now and I wondered what was going on behind the scenes)
@last jasper It says it lower on the page, it gets set during code generation. You can use it as soon as the game runs
perfect, thanks Sark!
Does my syntax highlighting look broken? I feel like it should be more colorful
Does anyone have insight into this error? error DC0002: Entities.ForEach Lambda expression invokes 'GenerateCells' on a ClientHexGridRenderer which is a reference type. This is only allowed with .WithoutBurst() and .Run(). I know why its happening, but I don't know what to do about it. Is there some way to tell unity its safe to use a function from withing Entities.ForEach?
You could try making it a static functions
Oh I bet because its in a Package, maybe
@toxic mural Your syntax is definitely broken, try restarting your IDE or even Unity, that will help usually
I got it, it was (maybe?) because I was trying to edit a file in a package
https://forum.unity.com/threads/definitions-in-ecs.679060/ Does anyone know if BlobAssetReferences actually duplicate the data or if they just point to the ref
I dont understand this error Burst error BC1020: Boxing a valuetype `Unity.Collections.NativeList`1<Pathfinding.FindPathJob.Node>` to a managed object is not supported
this is the line if (!neighbour.isWalkable || closedSet.Contains(neighbour)) continue;
also getting this whilst the Native Container it is referencing isnt ReadOnly InvalidOperationException: The native container has been declared as [ReadOnly] in the job, but you are writing to it.
anyone?
first error is thrown when you use NativeContainers for managed objects i.e classes or structs with classes within .
second error is being thrown because you have set [ReadOnly] attribute on a native container within a job , but you are also trying to update it.
@odd cipher
but I didnt set it to readonly
also the struct used doesnt have any of that ```csharp
struct Node {
public int x, y, parentX, parentY, gCost, hCost;
public int fCost { get { return gCost + hCost; } }
public bool isWalkable;
}
where is your job defined ? within Entities.ForEach or is this standlone IJob ?
I dont use Entities, so standalone
can you share the job snippet ?
the entire code? it's rather long
just the job definition with field declaration in question.. (!neighbour.isWalkable || closedSet.Contains(neighbour)
the closedSet is just created in Execute, NativeList<Node> closedSet = new NativeList<Node>();
hard to tell from this tbh
well theres not much else going on
have you checked on forums for known issues? is this IJobParallellFor ?
just a IJob, and I tried but didnt really find much about the errors
if you do .Run( ) does it throw same errors?
yes
also are your using BurstCompile on it ? is the job getting burst compiled correctly? The burst job inspector can give some insights on managed references in a Job , when it detects it
yes, I can see the error I mentioned earlier
it should be telling you the line number
yeah I know, its if (!neighbour.isWalkable || closedSet.Contains(neighbour)) continue;
I have no idea why
neighbor is the Node struct u shared above right
yeah it is
ProjectileHealthSystem.cs(80,17): Burst error BC1033: Loading a managed string literal is not supported
i get this type of error in jobs inspector for eg when burst fails
with line number
this is happening say if i place string inside my job
do you not have any more detail in the job inspector ?
what Jobs version you are on ?
are you using explicit casting in job somewhere from Node to something else?
no
it might help if you could share job body
I can send the full code
will take a look if you can
alright
dont know if the pathfinding actually works yet cause of these issues :p
can send if you think that will help. got some time on hand , can debug it for you. upto you
what do you mean?
just meant you can share if you think that will help me figure out the issue. am trying to figure out the error in the script you shared meanwhile
nvm. my brain slipped there for a sec. btw Tile is also a struct right ?
is this from TileMap package of Unity or your own?
my own
it actually does but it works just fine in other Burst enabled Jobs
yea well those jobs wont be getting burst compiled then
but they are so
can you see their burst compiled code in jobs inspector?
burst compilation fails silently when it encounters class references in jobs.
for burst disabled/failed jobs , you will see them in jobs inspector list with greyed out listing
🤔
so,, I dont think thats the problem
btw i created a simple Tile struct and it compiles fine. except the NativeList<>.Contains extension is missing from my project apparently. Unity cant find contains method for NativeList. if i disable those calls , rest whole code compiles fine in burst
that explains it i guess
yeah, I dont know a alternative though
NativeList does have Contains extension btw
you need to implement IEquatable for your Node struct
alright, that seems to have fixed that problem, however.. this time my game just crashes
that could be lots of things. you will have to step through your code. first run it on main thread only using .Run( ) with burst disabled. then .Schedule( ) . after that try with Burst enabled. check the jobs inspector for any errors
also if you can enabled Safety Checks and Stack Trace for Jobs and Burst for better error detection
Alright, enabling that gave me this instead of just crashing The native container has been declared as [ReadOnly] in the job, but you are writing to it.
buttt again, it hasnt been declared readonly anywhere
closedSet right?
indeed
i think the correct way to allocate native containers within a job is like this NativeList<Node> closedSet = new NativeList<Node>(Allocator.Temp);
alright, it now gives me a different error "Size overflow in allocator" and crash
perhaps allocate with a predefine capacity
NativeList<Node> closedSet = new NativeList<Node>(10, Allocator.Temp);
or whatever size is relevant
make sure this one is also updated NativeList<Node> openSet = new NativeList<Node>(10 , Allocator.Temp);
yeah, did that, still same error
seems to be logic issue. i think this iterator is causing overflow while (openSet.Length > 0)
possibly
could be that this line is not working reliably due to logic openSet.RemoveAtSwapBack(currNodeIndex);
I mean honestly, I dont really know all of the logic behind it
yeah, where I got the logic from it was a bit different than that
you could take it into standard main thread environment , make it concrete , validate it then apply the job/burst to it perhaps
Remove( ) and RemoveAtSwapBack ( ) are functionally different from my understanding
/ Truncates the list by replacing the item at the specified index with the last item in the list. The list is shortened by one. you may or may not want this.
Yeah I dont think thats what was intended in the original logic
you can look into these. if that helps. these containers provide more flexibility i suppose
alright , i gotta sign off for now. hope you figure it out from here. @odd cipher
Alright, thank you for your help so far
ugh, making this pathfinding is proving to be harder than I thought, I have a working version but I need a faster one.. but I really just cant figure this out, so I guess ill have to stick with that for now
Might try again later but currently my brain just isn’t cooperating
what's the recommended way to pass in a Mesh or a Material to a system?
has anyone else noticed that loading times (the app start, specially on mobile) gets so much worse with the Entities package in the project (from ~0.29s to ~4.78s in an empty game)?? Did anyone find any way to solve that?
import physics and you'll see get even worse :p im really interested in a good fix as well. Right now I'm using the Enter Play Mode Options settings, but maybe there is a better/safer option?
Yep, but I'm talking even on a Build (outside the Unity Editor), having that the time difference is quite big... there is this option of adding #UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP and it improves a little (obviously you need to do the creation of the world, etc by yourself in that case)
Anyone know why Unity would suddenly ignore a system's entire script without any code being changed?
because the system no longer has entities that match its requirements? You can try adding [AlwaysUpdateSystem] to see if it's that
Awesome, thank you
It also suddenly stopped disposing of TempJob allocations. But 2020.1.05b just randomly does that, it seems.
Nope that isn't it. Move entity creation to another bootstrap script, and OnStartRunning() still never fires.
@hollow scroll my compile times and time to enter play mode are out of control right now, i have to wait 5-10 seconds every time i do almost anything significant, its quite concerning.
Adding the following method to a system class causes the entire script to be ignored by Unity.
Even if that method isn't called, Unity will outright ignore the entire script and never fire OnStartRunning(). It isn't even listed in the script order settings with that method in the class.
Is there a known reason for this or should I go file a bug report?
Try adding [AlwaysUpdate] to the system as timboc said. and see if update is called .
if it is, you'll know your Entities.ForEach query is preventing execution
So, it's my query. Strange.
unless you explicitly specify a RequireForUpdate, SystemBase will use the queries from any ForEach it finds in the system, to dertermine if it should run or not.
Okay, that makes sense. I have some entities instantiated and tagged in this script, and then query those tags. It's not seeing those right off, so it ignores the script.
I worried that I was separating my code too much elsewhere. Guess not!
So, what's the current best practice for running a ForEach with a specific entity query? Say for instance I have two separate ForEach statements, with some logic in between, how can I guarantee they will both use the same entity query? The particular use case is a kind of 'many to one to many' - I have some processing in between the two ForEachs. Beforehand I could Schedule(query) on my IJobForEach
One solution is to migrate to IJobChunk, but I was wondering if there was a more elegant way with the newer SystemBase lambdas
Does the one have a unique tag?
If the one is fished out of a chunk, and you have to keep it in that chunk then I think that's what IJobChunk is meant to be for.
how can I guarantee they will both use the same entity query make them have the exact same arguments and options (WithAll<T> etc) and they will use the same query.
In earlier versions than 0.9 preview, you can do .With(someQuery) also.
@mint iron I thought of this, but one of the components is readonly in one foreach and readwrite in the other - I could just mark them readwrite in both I suppose?
@gusty comet thats exactly what I did use, I'm upgrading some code to the latest version and finding that feature missing 🙂
does it matter if they use different queries?
yes in as much as i need to entityInQuery index to match between them.
I could instead key by Entity, but that seems like an ugly solution when before I could more explicitly bind the two together
Thanks for your replies - I think the answer in short is no for future entity releases, and that there is a workaround that you can match the signatures/query constraints to get it to use the same query. I guess my worry in the second case is that it is very implicit, and some other developer in the future might add some new code to one of the foreachs and introduce a nasty bug
I think I'm about to tackle a use case with similar constraints. Have you considered an Entity linked list? An Entity can be a field in a component, and it doesn't even impose that it must be shared.
I guess essentially the first ForEach was building a kind of many-to-one list (the specific case: a list of Attacks made against an Entity in that frame)
So I think the equivalent would be something like a Buffer of Attack entities which gets populated in the first ForEach
what about storing the attacks off into a collection, and then using Jobs.WithCode to iterate the list after processing to do whatever else you're doing.
and that list being held on each Entity that can be attacked
@mint iron - that is essentially what I did beforehand. The first phase was building the list, the second was doing something to the list elements, the third phase was then executing back on the attack entities
If the attacks are numeric, that sounds like an ideal component buffer use case. Then split the procedure between two systems: one to collect attacks, and the next to apply them.
if there is no structural change between ForEach indexes won't change🤔
They have other metadata like attack type and hit location, etc
@warped trail nah they wont, but the bit that bothered me was having such a critical requirement that the two queries are equal being effectively hidden in requiring that the signatures match (whereas before I could define the query explicitly, and then give it to the two ForEachs)
was it in component systems's foreach?
you could use the AndStoreAsQuery(ref _query) (orwatever its called) and then use an IJobChunk for second part :*( not sure why they removed WithQuery
@warped trail yeah
@mint iron that would also work - but then I have a kind of weird standard with one job using lambdas and the other using IJobChunk when before I could do both with IJobForEach
I don't understand why you can't just use the entity as the key in the hash, or a hashcode from it for the index?
entityindexinquery isn't a super stable way of indexing outside of that query iteration
should really be using a stable id like the entity or a user generated mythingID
actually I think that is probably the best suggestion, in that then it wont be a game breaking bug if someone accidentally changes one of the ForEach signatures
Thanks @low tangle

Playing Beat Saber on max settings, PC fans say, " "
Playing Half Life: Alyx on max settings, PC fans say, " "
Importing a Unity Store asset, PC fans go brrrrr
lol
I'm really loving ECS, and I'm really loving Scriptable Objects, but I'm mow smashing them together like dollies demanding they kiss and it's being about as productive 😛
so many different classes and variables, all of them called "ship"
Is it possible to make custom inspector output for a component? Setting a ScriptableObject just outputs the name of the field and no other data, being able to tell it what to output there would be really useful.
yep, you can!
Neato, any idea where the docs for it are? as I can't find anything on it.
its this repo https://github.com/OndrejPetrzilka/EntityComponentInspector but i had to update it for latest entities package because they changed a bunch of stuff in Entities.Properties. So here's the version i whipped up this morning.
https://www.dropbox.com/s/8sb3qj7hpji3qrf/ComponentEditorsPackage.zip?dl=0
Thanks
then u just make em like this
public class EntityArchetypeEditor : IComponentEditor<EntityArchetype>
{
public VisitStatus Visit<TContainer>(Property<TContainer, EntityArchetype> property, ref TContainer container, ref EntityArchetype value)
{
// EditorGUILayout stuff goes here.
return VisitStatus.Stop;
}
}
Whats the recommended way of working with "Events" in a data oriented environment ?
The one I use is typically a producer consumer style, produce an entity with the information, next frame, process the entity and consume it
You can take a look @mint iron 's event package - it's pretty easy to use
either event-entities as @coarse turtle says, or some sort of event queue
but basically, you do messaging
by creating something that represetnts an event, either an entity, or some messaging queue
and later systems read from this and do stuff
Hello, anyone know how to remove dynamic buffer from an Entity?
physics samples updated at https://github.com/Unity-Technologies/EntityComponentSystemSamples
ECS samples still 2 months behind
they've moved to systembase on some of the physics samples now
@south falcon EntityManager.RemoveComponent<BufferType>
is that as same as using EntityCommandBuffer?@zenith wyvern
Yeah, you can do it with ECB as well
Is there a way for an entity to copy the transform of a gameobject duringruntime? I dont want to rewrite the whole project to ECS because I have only one feature using ECS right now. But for that my entities needs the position of the player. So basically I am trying to run a Hybrid ECS project.
I am here again in the moment of need as usual
Would anyone be so kind to tell me how Unity knows if an entity component changed for the entity changed jobs?
I am wondering how it detects if a component changes and how can this detection be fast
afaik, it doesnt detect changes on a singular entity, it detects changes on a chunk, so if you do a "ref componentA" unity will assume componentA is changed and will increase the chunk's version, thats how filters 'detect' the change
@scarlet inlet chunk version numbers