#archived-dots
1 messages ยท Page 208 of 1
Your missing the add job handle bit
Would be amazing if unity could make that more automatic
System.AddJobHandleForProducer
After your foreach
Pass in Dependancy
But also your using run, you don't need a ecb. Is that cause your testing?
@shut hare here's the docs, the last line in the sample is what your missing
https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/entity_command_buffer.html
I'm just trying to figure things out man ๐
Yea I get that
oh i see, i wanted to start without the multithreaded bits it feels easier i thought this line was for the jobs workflow
Ecbs is for jobs
But even single threaded they are faster
As unity can group all your changes into one big execute
Sadly it doesn't seems to work ๐ฆ
protected override void OnUpdate()
{
var ecb = system.CreateCommandBuffer();
Entities.ForEach((Entity entity, in DespawningEntity despawningEntity) =>
{
ecb.DestroyEntity(entity);
}).Run();
system.AddJobHandleForProducer(Dependency);
}
It should
Maybe just change run to schedule
Are you sure your creating that system?
I'll try that, yeah like this
destroyDespawningSystem = ECSWorld.CreateSystem<DestroyDespawningSystem>();
That's not quite enough to get that system running
You'll also need to add the system into a update group
Sorry can't help more, g2g. Good luck
np man thx
Is there a way to modify the prefab entities?
I want to initialize some data on startup.
I must use a system and not the conversion pipeline, because I need many systems to do their own initialization based on what component there is on the prefab.
you could convert the data so it's easier to modify
Figured it out. .WithEntityQueryOptions(EntityQueryOptions.IncludePrefab)
How can I write to a native queue from multiple threads? As far as I have seen I cannot use AsParallelWriter again when another system is already using a parallelWriter. So I cached the parallelWriter and even added manual dependencies to the systems so that the reader depends on all the writers and completes the combined writer handles before reading. But I still get this error: "The previously scheduled job HitVFXSystem:OnUpdate_LambdaJob0 writes to the Unity.Collections.NativeQueue"
I don't think it's possible with a nativequeue
From what I have found so far that seems to be the case. If I understand correctly the NativeQueue can be written in parallel from a single job and not multiple jobs. I suppose this is due to the necessity for the writing order to be deterministic?!
What I am trying to do is basically building a custom command buffer to spawn pooled VFX effects. It would be great if it was possible to just extend the ECB. Or maybe NativeStream will work for that usecase?
why would you want to extend the ecb, do you mean you want to extend its length of running time?
No I am trying to have custom commands
You could also call it command or message queue
Like this example from the UnityFPS but with entities und jobs: https://github1s.com/Unity-Technologies/FPSSample/blob/6b8b27aca3690de9e46ca3fe5780af4f0eff5faa/Assets/Scripts/Game/Modules/Effect/VFXSystem.cs
In this case they just use a Dictionary but its obviously neither threadsafe nor burstable
Found a thread where somone is using a similar system to queue audio messages: https://forum.unity.com/threads/event-system.779711/page-4#post-6743209
but this does not work as soon as more than one job is writing to the NativeQueue
yeah I haven't really looked into this stuff yet sorry
Ok thanks anyway ๐
are there any data types that allow you to write to a single list in multiple jobs ๐ค
that would just be unsafe and result in race conditions surely
Thats what I am currently trying to figure out
I think NativeStream might work
Thats why I was also looking at extending ECBs as they basically are lists that can be written from multiple jobs
Internaly the ECB Systems use a NativeList<EntityCommandBuffer>
so its basically a List of lists
interesting, I guess an ecb is just queuing up commands so its not likely to conflict
yeah since each writer creates its own unique list there should not be a problem
can't you do that yourself create a list in multiple jobs then add them all together at the end
I am currently trying to figure out if this works
but if I remember correctly it is not possible to nest native collections
yeah I remembered correctly ๐ฌ "Unity.Collections.NativeQueue`1[VFXSystem+VFXCommand] used in native collection is not blittable, not primitive, or contains a type tagged as NativeContainer"
Couldn't you use the same pattern? A list of NativeQueue?
Thats exactly what I tried leading to the error above your message
Oh
you cannot nest native collections
it works for ECBs as they use some pointer vodoo and are not declared as native containers by unity
well I have to see if these are nestable
Unity just uses a managed list to hold ECBs inside the EntityCommandBufferSystem
Oh yeah lol
Idk how they are going to solve that for ISystembase
Probably do some pointer vodoo lol
Or maybe not all systems will use ISystemBase?
They use NativeList<EntityCommandBuffer>
but a EntityCommandBuffer is allowed to be in a NativeList a NativeQueue is not allowed
maybe because they made ecbs burstable?
Does the entity command buffer not hold a dispose sentinel anymore?
But couldn't you just use a List<NativeQueue> instead?
Well thats so simple it might actually work ๐
When working with DOTS I also tend to forget managed stuff ๐
dunno why we still cannot nest nativecontainers
other than safety system
just because we can shoot ourselves in the foot doesn't mean unity shouldn't let us
Ohhh
m_PendingBuffers = new List<EntityCommandBuffer>();
#else
m_PendingBuffers = new NativeList<EntityCommandBuffer>(Allocator.Persistent);
#endif```
Cuz leak detection
๐คทโโ๏ธ
yea but that's what i mean
if we already can disable that
why not allow nesting containers
Oh wait so you mean even when safety is disabled you still can't do it?
I think you can, but that gets rid of all safety checks
I need some quick help... I receive a packet from my server and i implemented some sort of serializer which converts the packet to a struct. I tried to add that deserialized packet via "manager.AddComponent(entity, deserializedPacket)"... Yeah... it tells me that generic types need to be known during compile time. My deserialized component is not generic... i just dont use the <> when adding that because i dont know what type the deserialized packet is. What should i do now ?
How can i add a component without "<>" to an entity ?
Thats tough because ECS needs the type in order to add the component. Maybe you could look into the internal type index. AFAIK ecs creates an id for each type. So maybe you could send this typeID with your package and use it to add the component
Do you convert it to a specific type of struct? Or is the deserialized data an object?
Well of course i know the type... by "myDeserializedPacketComponent.getType()"... but i cant use the generics because i dont know what type it will receive ^^ And i also dont wanna write a huge switch statement.
Packet -> Deserialising -> MyComponent : IcomponentData{} -> Add to entity | Thats the current flow...
Maybe AddComponent(Entity entity, ComponentType componentType) will help?
you can create an componentType from a Type
Ok this is getting interessting ๐ And how ?
hmm why not just parse the data as bytes into their desired struct types? ๐ค
ofc that assumes you have a schema for the bytes
public static ComponentType ReadWrite(Type type)
Thanks im gonna try that out ! hopefully i dont run into the same issue when i wanna update them next ^^
man i went down that rabbit hole, got around it using dynamic types and reflection, so I don't think it works out as a performant solution(but my needs were just a runtime editor)
Yea I too have fought with ECS and dynamic loading of types
Was a massive pain ๐
@stone osprey For my networking, the first thing i send is the type id, i then have a massive switch statement which creates the exact struct and loads data into it, then attaches to entities as needed
So nothings dynamic/reflection based
and i use code gen to create that switch statement ๐
But doesnt "AddComponent(Entity entity, ComponentType componentType)" work for you?
or the one that takes the typeId
it didnt as i was boxing all my structs into a common interface
and interfaces are not sturcts
or something like that ๐
ok I see
i was adding components that had fields too
not empty tags
honestly was super annoying
Thanks everyone... i think "AddCOmponent(entity, type)" did the trick... atleast i dont get errors anymore ^^
Right after that i trigger a SetComponent(entity, struct) which works fine without knowing the generic type
i never actually tried that combo... i was too focused trying to get AddComponentData working so its a single opperation
wait... or probably it does not work fine at all
:/
The typical showcase effect... i run it again and i get weird errors... one moment
my other requirement was to use jobs and burst, so again that would be why i landed on the switch statement
Fuckkk... "SetComponent(entity, struct)" does not workkkkk... the same exceptionnnn as i would have used the "AddComponent" without generics
Any other ideas ? I clearly dont wanna have a huge switch statement here xD thats too much pain
What exception do you get? Is your struct boxed?
There is an internal method called SetComponentDataRaw if you can modify the package source
"All Component Type must be known during Compile time"
Im using .SetComponent(entity, data) from an command buffer
What is data in this case, an interface?
Just an object... for example a HealthComponent or any other component...
So basically everything that extends IComponentData
Just imagine that i dont know the type, thats why i use IComponentData... that picture was just a test if it works or not.
Ehh idk about entityCommandBuffer but you could do something like that when you use the EntityManager and make SetComponentDataRaw public:
Yea that was the error i got
I didn't test that tho so there might be something I'm missing
hence the massive super switch ๐
@north bay Thanks, i think that it works fine when i use the entitymanager instead... but i really, really hoped that theres some way to get it working with the CommandBuffers... because it would be perfect for networking :/
ill be happy to share my code gen bits
Thanks... but im really searching for a cleaner way ^^
Is there any performance impact when we call "EntityManager.SetComponentData()" on the main thread ? Im just using an ECB here because i was told it has better performance
Well did you register the generic components?
@sturdy rune Its not even generic... Look at the second pic above ^^ "new Identity()" is not generic. But im casting it to an interface, because i dont know the type during runtime. So i basically try to call .SetComponentData<...>() without knowing the generics. Thats what is breaking my neck right now
Ah got it. Forgive my naivete but why do you not know components vs components associated with a system
@sturdy rune Long story, but i basically receive them as packets from a server and need to attach them to the entities.
Thats why i dont know their generic type
And i dont wanna have a huge switch statement there
Yea I could understand why haha. I would have thought the components would be known on both sides anyway, and you would receive a generic component that indicates what type of component needs to be added i.e. you've serialized the message and now need to deaerialize - why go straight to adding component? Are you that concerned with performance or is there a real reason
But I guess there is your problem you don't want a huge deserializing switch
Lol
The server uses a different language... java... thats why i deserialize them and dont know their generic type. Just lets say theres no other way ok ? ^^ I dont wanna lose the focus on the main problem. I have some object and i know it extends IComponentData and i wanna attach it to an entity. How do i do that without generics ?
I see... this is only achieveable by using reflection... damn, i really hope that unity adds such features some day. Every ECS i know supports this
If i understand you correctly, if you need to add arbitrary IComponentData object then you can have it as IConvertGameObjectToEntity on a separate gameobject. Then you can manually grab this gameobject and entity you want and use convertion utility on them. That way you can build some "Component prefabs" and inject it at runtime. But it is not efficient.
But there is no way to get IComponentData types that entity has on itself at runtime. And i want this feature from i know DOTS.
@frosty siren Thanks... but thats not the problem here. I receive plain data from the server which i need to attach on an entity without knowing its generic type at compile time.
I cant convert anything... because i only receive plain structs from the server
And i need to attach them to an entity without <>...
oh, ok, i see
I don't think you can do that without modifying package source
all i can imagine is have some mapping that will match value from server and IComponentData type that need to add. But there is no way to get values.
That would work... but its very inflexible and if theres one think i hate then its hard coded stuff.... i think the best bet is to go with reflection, even if its much slower
you can avoid inflexibility by using a little bit of codegen ๐
Your deserialized component is boxed as an IComponentData interface right?
mmm yes code gen ๐
Make sure to pin it before you pass it to your reflection method
yummi
In fact its pretty easy... the last method inside that method is what i need
will make it all so much better
BUT OFCOURSE ITS PRIVATE
WHY THE HECK IS EVERYTHING PRIVATE, PROTECTED OR INTERNAL ?
I bet they don trust us to use them properly
i think they only public stuff they are 100% sure is good for us to use
as in default high performance
and highly tested
dots made basic game stuff so easy to avoid spaghetti code but when i need to use more advanced things that are internal or private, my code turns into spaghetti again ๐ฅฒ
i hate unity for that mantra
yup
i understand your pain, mate
they should do what that scriban templating tool did
they have a optional define that changes things from internal to public
sooo good
if unity added that, then us crazys who want the internal private stuff could just add that define
i tried to fix Companion stuff's performance and i have finished with 1900 new files in project because there is no way for me instead of cache package and edit Unity.Entities package BECAUSE all is private
yea im trying to stay far away from editing unitys packages
also i have no clue how to maintain those changes
but the real good thing is that it so simple to read code now
like when theres a update, how do you bring in unitys update without losing all your stuff
remember, backup, and paste after every update if need
was that by chjance the companion gameobject transform gc allocations?
there must be better ways then copy pasting things :/ i keep thinking git must have something, but no idea how to do it
not only this, but yes
how complex a fix was it? i think i remember seeing something on the forums but cant find it now
mmm, few lines of code
hope they exist
The real problem is that system updates ALL entities with companion components and you can't exclude entity. So i have changed query a little bit.
Tried to use CopyTransformToGameObject system which is far more optimal but it produces a really weird results (i have described it in last reply https://forum.unity.com/threads/ijobparallelfortransforms-wrong-indexes.1078088/)
Quick question... whats an managed component ?
a class instead of a sturct
(use them if you want to develop a game ๐ )
๐
yea im too harsh on them
i have to use some for my networking, as i store the connection stuff in one, and somewhere inside that is a unity safty check thing, which prevents use inside a struct IComponent
more like instant noodle code
mmm instant noodles
Is there any way to acess "SetComponentDataRaw()" ?
Or does this also require reflection ? It tells me its internal :c
edit it to public?
actually you could try the InternalsVisibleTo thing
ive discovered a nice way of extending things via partial
I used a ton of reflection to get access to that stuff but that was before I knew that and havent yet refactored
Its like... Oh you wanna use the ECS ? Of course... but only in MY WAYYYYYYY angry unity noises
@safe lintel InternalsVisible to ?
Never heard of that... whats that ?
dont you need to use that inside the Entities package tho?
exactly my emotions a few days ago
@stone osprey ooo just checked, entity manager is partial
tertle's post explains it in more detail with an example
so you can nicely extend it,
Make a new folder in your project
Put a asmref in their pointing at Entities
then create a cs file, and give it the same namespace as EntityManager
finally give the class the same signiture as EntityManager
inside your new class you can make public methods 'wrapping' the internal/private ones from Unity
boom, nicely exposed unitys internal stuff without directly editing their package
๐
let me know how it goes
ive just started doing it for some of my stuff which im building into packages
but havnt tested on unitys stuff yet
@ocean tundra Hmmm... ok first problem ๐ Whats an ASMRef ? xD And where do i create one ?
in the create menu
Ah the definition file ?
Ah in unity ^^ found it, thanks
yea sorry, should have been more clear
@ocean tundra Thanks, so that worked so far ^^ the only problem is... my partial class cant find ANY of the internal methods from the EntityManager
close and reopen editor?
and see what unity says
asmref is a unity thing, not normal code, so your editor might be unhappy
i think it kinda worked tho, your partial EntityManager has a ton of references/usages
what code editor are you using?
if it's private then only works if it's in same assembly
ah
So... first of all, it doesnt like the Equatable stuff
Tells me that its already implemented
oh maybe your not ment to copy interfaces
just rereading this
second... it somehow does not find ANY other methods from that class
Only those i wrote
XML comments
interfaces
generic-type parameter attributes
class attributes
members
yea so that would be copied, so dont need the interfaces
What does unity say if you ignore your code editor?
im thinking your code editor dosnt understand asmref, so it cant merge your files
i use Rider and it was confused untill i cleared my caches
Another funny side effect is this... Somehow it tells me that theres stuff missing ๐
Unity is fine... well it shows me all those errors now.
Like that Entitymanager has no world anymore
sorry ill give it a try shortly
worked fine for my package and type
maybe the folder structure matters?
@ocean tundra Not sure... im using rider, this is the current structure ^^
All those red underlined stuff only due to the entitymanager error xD
Im gonna try invalidate caches and restart now
Hmmm... weird... what interface bit ?
Oh i already removed that ^^ But well... still those errors everywhere
Im gonna try to restart unity and rider... probably that helps
This is also interessting
yea for some reason it hasnt merged your partial entity manager
instead created a new one
is your asmref set correctly?
as your using rider your entitymanager partial shouldnt be grayed out like that
thats indicating there isnt another partial type
Im gonna check that ref again... but im pretty sure that i set it correctly :/
and my folder looks different in rider to yours
i have that little unity.entities indicating its part of the entities package
Huh ? Why does your folder looks like that ? ๐ฎ
maybe this:
That fits
Do you have your code editor set as rider?
Yes
I did
close and reopen of both unity and rider did nothing?
what unity versions/rider version?
im on 2021.1.0b3
I bet its some very, very stupid misttake somewhere
but i dont think that would be the cause
asmref have existed for a while now
my asmref raw:
"reference": "GUID:734d92eba21c94caba915361bd5ac177"
}```
Oh its not over yet xD
nooo
delete the cs file
Probably my folder is at the wrong place
and delete the asmref
start clear
make a folder
and then add the asmref
not the cs file
then finally after unity has finished compiling add the cs file
im thinking maybe you added the cs file first?
which would have triggered a ton of compile errors
and then added the asmref, but that didnt fix them for some reason
oh and make sure you start from 0 errors
Oh man... yes that was the problem i guess ^^ Im gonna start fresh again... lets see how it goes this time
oh unity.. and its wonderful weird issues
Im gonna kill myself
Sooo... i did a fresh start
Added a folder, added the reference file
Waited for unity... then added the cs file
Then waited again and replaced the default created class with the entitymanager
AND
THIS HAPPENS
well
Sooo :
ARGH
It doesnt even know any of the Unity.Entities stuff
Like IComponentData, its missing
What? If this really works this is a game changer. The internal stuff annoys the hell out of me ๐ฌ
looks like i wasnt the first to even discover this :/ weird your having issues
Every single thing from Unity.Entities is missing now xD Interfaces, stuff like EndInitializationSystem... Even the entity struct itself
But... i can start it ๐ฎ
No errors shown in unity
so its just rider dying?
It looks like its only rider
go File => invalidate caches and restart
Oh i did that the fourth time in a row xD the errors stay
JetBrains Rider 2020.3.2?
2020.3.3
ill update
Thanks ^^
looks like theres 2020.3.4, ill update to that
Thats also still interessting... Partial is still grey
Oh i see, im gonna update too
yea its all good for me
Mine is still updating ^^ well... actually installing... somehow takes ages
yea took loads longer then i thought it would
Annnnddd its still the same ^^ wuuuu
got to be something in your caches
How does your solution look like ? Mines like this
Im gonna clean the solution/rebuild it
probably that helps
Well cleaning works... rebuilding fails due to the resharp errors
mine has a library folder
under library package cache
Well its in there... as it should
Hmmm... i probably should
This is also interessting
It doesnt... find the .Entities
I removed the partial struct in this test here
This is also weird
That could atleast explain the many errors
yea i dont have that
the rest of my project is all sturctured with asmdefs
maybe thats it too?
i dont actaually have anything in assembly-csharp
nope sorry i do, just not much
like 3 files
and yea they have some .Entities stuff
I dont use any asmdefs ^^ just the package manager... The error above only happens when theres a .cs next to the asmref file. Without it... theres one one reference to unity.entities
But as soon as i place a .cs file next to the reference file... it starts to throw errors at me
It wont find Unity.Entities anymore
any cs?
Yep any...
or the partial one
Any
maybe theres a bug with asmrefs in older unity...
Well... i can run the editor... so im not sure if its really unity. But i also dont know how close unity and rider are coupled
@stone osprey sorry im all out of ideas
delete all library stuff/caches and .csprojs manually?
Its ok, you helped a lot ^^ Well... im also out of ideas... but i actually dont wanna delete too much stuff, last time i did that the project was completly broken ๐
make a new test project
and see if its in there as well
and maybe update that project to see if its unity?
I think im gonna try that new test project stuff tomorrow... im also a bit in fear regarding the unity update... last time i did that i was forced to update the entities package which resulted in a lot of changes xD
I am just so curious about your component design to understand why this is such a challenge lol I feel so naรฏve
I am using dotsnet though and modelled my netcode after the examples there... not sure mine is so complex
Well thats right xD im not using dotsnet at all, im using smartfoxserver. Thats why its such a challenge. Besides that, im gonna try that tommorow, its already late here and i should go to bed soon ^^
and im building my own netcode ๐
yea im kinda crazy
lol
working really well tho
but ive ripped it all appart to put into packages
having some annoyances with that ๐ฆ
have done some socket/transport work in the past in c++/python but I uhh, I wouldn't go that far that's for sure
lol
Me neither ^^ i havent that much freetime :p
im honestly finding the core networking kinda easy
not sure if ive done things wrong ๐
will see when i start stress testing more
but i generate a ton of code, and im having trouble with bits of my code relying on generated whcih relys on users code
is queuing and message sequencing
im using Unity.Transport, which mostly handels that
ahhhh
and before in my earlier prototype i used eNet
yea the new unity netcode is good too I have just started getting into it
dotsnet is awesome though so far
easy
easier than mirror
yea me too
how does one create a new queryable archetype at runtime?
for example, if I add the component Group1, it will create a new archetype with the Group1 component, which I can then query all entities of Group1 by querying Group1
I use the Group1 component as a way to collect all my entities that belong to that group together
but if I don't have a predetermined tag to query, how can I group entities together?
the use case is creating groups of RTS units. I want to create groups which when ordered, will move in a formation together
I have read about using NativeArray of entities, but iterating those entities would be random access. if I could modify the archetype with a group identifier instead, I could query the archetype with said identifier, and iterate the archetype with no random access
tldr, how can I create a collection of entities in dots such that I can iterate the collection with no random access. (the collection being a group of RTS units)
You can achieve that with shared components. You could have
struct SelectionGroup : ISharedComponentData
{
int groupID;
}
Then you can filter by group id on the main thread before you run your foreach
I don't know if that's the right solution to what you're trying to do, but it's a solution
is there a lot of overhead to filtering?
@odd ridge I'm pretty sure it's actually quite quick
As shared component split up your Entitys into different chunks, so the cost is when adding/removing/changing shared components, not when filtering
Itโs pretty much the same as adding a tag - if this selection changes often youโll have the cost of changing the archetype. If itโs for few operations on the selected entities. itโs usually better to iterate all and add to a native container. If they will be grouped over a longer time itโs likely worth the cost if the change in archetype. Itโs all a trade off.
Is it normal for DOTS physics to take this long without even doing anything with physics?
Does IJobForEachWithEntity have the 6 argument limit too?
As in the same as ForEach
hi, does anyone have an example of how to use Unity.Mathematics.noise using shaders?
i tried doing it without shaders, but the performance is really bad.
แตหกหข สฐแตหกแต
What can I use to make something like this
NativeHashMap<ulongNativeHashMap<ulong,InventoryBlockData>>
Using NativeMultiHashMap means that it should be iterate through values and it can be thousands of them
NativeHashMap<ulong, UnsafeHashMap<ulong, InventoryBlockData>>
Having a little issue here...
I wanna call "SetComponentDataRaw" via reflection ( because i cant manage to set up those stupid asmrefs )... But it requires a pointer... how do i pass a pointer into the method info ? ๐ฎ
I'm looking at 2021.1.0f1 release notes here and I'm super puzzled by this entry: Burst: Burst enters RC phase.
but it's already been released a long time ago?
or do they mean something other than release candidate with RC here?
must be for another version of burst that's "verified" for 2021
still if that would be the case, they would've included a version number
I would be very... very glad if someone could look at my issue here : https://stackoverflow.com/questions/66764051/invoke-methodinfo-with-void-as-a-parameter i need to invoke a EntityManager internal method via reflection and i have no damn clue how i pass a void ptr to it... glad for any help, thanks
Quick question... does anyone know how we convert an object to an struct ? I passed a struct to an method via a (object) cast. Now i would like to get a ptr to that object, because i know that its a struct at that point. But well... its casted to an object :/ Any ideas how i could get a ptr to that struct easily ?
unsafe {
var handle = GCHandle.Alloc(cmp, GCHandleType.Pinned);
var adress = handle.AddrOfPinnedObject();
var ptr = adress.ToPointer();
var sizeOfComponent = UnsafeUtility.SizeOf(type);
var parameters = new [] {entity, cmpType.TypeIndex, (object)adress, sizeOfComponent};
SetComponentDataRawInfo.Invoke(em, parameters);
handle.Free();
}
Thats my code sofar... but i would love to get rid of the GC handle. Because i now that cmp is an struct that was casted to an object... any ideas ?
Simple answer, you can't.
As soon as GC takes over the memory (which it does by you boxing the value) you have to pin the object to get an address to it.
Oh damn... thanks :/
Did you disable all safety checks, debuggers and such?
You are right that might actually be the problem here
well ok now its down to 0.655 ms ๐
entities are grouped in chunks depending on the value of the shared component? as if it was a unique tag?
thanks, I must have missed this in the manual, I'll check it up
yes, grouping units should be something that last for a least a couple minutes, unless the player spams grouping for no reason
my concern was that, if I would use a native container, the foreach would have a cache miss on every iteration, because there's no way to tell where in memory those entities are
Yes they get one (multiple if too many) chunk per SharedComponentValue. I think grouping units in an RTS is a prime use case for SharedComponents
not really sure why it's much better than adding a 'selected' tag unless there are many groups?
I would probably prefer just iterating everything and using a native array. IMO you should only resort to shared components if you need to separate by chunk for performance reasons
Like if you have a lot of performance intensive work that needs to be done on your groups of entities per frame. Selection groups doesn't sound like it fits that criteria
Has anyone made use of RenderingLayerMasks with the hybrid renderer? I have a scriptable render pass that sets the renderingLayerMask on the FilteringSettings passed to DrawRenderers(). This works fine on game objects, but the entity equivalent is not getting filtered correctly. I can see the BuiltinMaterialPropertyUnity_RenderingLayer is set correctly on the entity in the inspector.
When I switch the filtering to use traditional layer masks instead, it works great. However, this layer is stored in the RenderMesh shared component, which isn't ideal if I want to turn the render feature on and off on specific entities at runtime.
This is the code I'm using to only draw render layer 4 (mask = 8)
uint renderLayerMask = 8;
var filteringSettings = new FilteringSettings(RenderQueueRange.all, -1, renderLayerMask);
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings);
But all entities are getting rendered. For example, here is an entity on render layer 7 (mask = 64):
Currently profiling my dots project... Is the Behaviour-Update part of dots ? Or does it belong to normal Monobehaviours ?
Dont mind the huge blue spike there... thats what im trying to solve... some part of my code produces a lot of script slowdown for some reason
And sorry for the tint ( Its the tint color for my play mode )
DisposeSentinel is part of dots, right ? Is so... what the heck is wrong with my game ? When do those DisposeSentinels get created ? I have literally hundreds of them flying around for some reason
And they are clearly not good for performance... is there any way to see where those are getting created ?
Any ideas ?
They are part of leak detection and can be quite expensive if you have full stack traces enabled.
Try to set leak detection to on or off
@stone osprey also make sure burst is on, I think for new projects it defaults off
Alright thanks ^^ im gonna try to switch them off
Well that worked ^^ Oh... i got a weird exception right here : ArgumentException: System.ArgumentException: A component with type:{0} has not been added to the entity. Thrown from job: Unity.Entities.EntityCommandBuffer._mono_to_burst_PlaybackChainChunk
It happens inside the Entity Command Buffer
Thats the full error... any idea what exactly causes it ? That stacktrace doesnt lighten me up
Turn off burst
And run it again
You'll get exception details
Your ecb is trying to manipulate a component that doesn't exist on the entity
Ah ok, thanks... how exactly do i disable burst ? Theres no "one/off" button as far as i can see
Or just uncheck every option here ?
Untick enable compilation
Alright thanks ^^ im gonna try it again...
Alright... i now get a "full" stacktrace of the entity command buffer "Entity has no component type of... exception"... BUT how do i now find the place where i add/set those components that cause this exception ? Is this exception caused by an add or set/remove operation ?
Error log
Its also quite interessting... that error log does complain about multiple components at the same time... not only one
"Identity has not been added... NetworkLocation has not been added..."
In "Uknown"
That's weird
I've never seen that
It's supposed to say the system name
Hmmm... probably i call that buffer from the main thread at some point... that could explain the unknown atleast. What could explain the many listed components ? Is that normal ? ( Identity, NetworkLocation, NetworkRotation... not been added )
And is this caused by a .SetComponent operation ?
SetComponent or RemoveComponent
Hmmm... I delete a bunch of entities once they leave the area of interest... thats a feature from my server framework. So what happens when i buffer .SetComponents() operation for an entity... but that entity gets deleted before the buffer is able to set those components ?
Would that explain that error message ?
If that happened I think the exception would just say "The entity is null"
Errors from command buffers are extremely unhelpful in my experience
Well such a exception would make more sense... And at the current state i never remove any components. So it why the heck does that happen... and i always call ".HasComponent" before i set one.
To make sure that this actually does not happen ๐
Impossible to tell from the stack trace
Do you use ecb outside of systems?
If so, you might want to use Entity Manager instead
I use it outside the ecs for networking stuff. One of my scripts receives packets, converts them to components and uses a ECB instance to Add/Set components to an entity. That could be a possible reason. I only use an ecb here because i was told it offers better performance and does not interrupt the game flow
Yeah but operations from ecb aren't executed immediately
They are once the ecb is executed later in the frame
So if you do an ecb operation followed by a main thread operation, the ecb will not have been executed yet
For exemple
HasComponent<D>() //false```
From my understanding, at least
Alright thanks... im gonna check the logic flow from my code. If that doesnt help im really gonna switch to the entity manager instead ^^
@stone osprey If you can stick with ECB, but maybe you need to make your own networkECBBarrier system
the default ECB systems playback at certan points (start/end) of their containing groups
For my networking im currently using EndSimGroup, but that does introduce that 1 frame delay
im planning on grouping up my networking systems and having a EndNetworkingECB group, that way users can update after that group and there wont be a frame delay
Are you making your own netcode solution?
Interesting. How come?
umm cause im crazy ๐
no mainly cause i want to make huge RTS type games (sims/managements/rts)
think rimworld/factorio/age of empires
i dont think unitys netcode is up for that yet
and the other option DOTSNET looks close
but i found some cool stuff about how planetary annihilation does their networking and loved it
That's fair, it was mainly made for 1st/3rd person action games anyways
decided to see if i could make it, that was ages ago now. worked great
im honestly not too sure, but i dont think it would handel syncing the number of entities i want
@fluid kiln ??
For netcode
Oh yeah that's a big one, true
That'd be dope
oh
But in RTS anyway it shouldn't be 1 ghost per unity
yea i actually have never needed that
Have you even tried? ๐
my sim is Server => Client
client only receives the data they need for the things on screen
if your interested heres the artical descibing it
https://www.forrestthewoods.com/blog/tech_of_planetary_annihilation_chrono_cam/
Technical deeptime into the unique networking architecture of Planetary Annihilation.
netcode 'might' be able to handle it all fine
but honestly having tons of fun building this, and when i started the first prototype netcode was like 0.2 or something, so broken
Since all the networking wizards are here, I have a conceptual question. I'm tryhing to make a top/down RPG but with the same combat system as LoL. I have a hard time coming up with what should be in my Input Buffer and how to attack / cast abilities
Yeah it's completely fair, it's your own funeral ๐
SO far the only thing in my input buffer is the destination the client wishes to go to
@fluid kiln lockstep or client server?
But now I'm tryhing to code abilities, should their cast be through RPC?
netcode right?
Idek what that means haha, netcode, server authoritative
Hmm, I'd say as a naive approach you would have a bool for each type of attack (auto-attack, ability 1, ability 2, etc), and also the position where they clicked
yea based on my understanding of netcode, client would send a rpc to server to trigger the ability
Hm an RPC might also be a better solution ๐ค
But the thing is, when I play with a client not on LAN, some frames of the Input buffer are lost
So "buttons" like "InteractedThisFrame" can be lost
Not lost, but overwritten
I think
Like not all the frames in input buffer are guarateneed to be processed I think
That's why it's better to put streams like "direction"
when you say not on lan, your talking about client/server in the same host(unity process)? not over the internet?
Different processes yeah, I guess LAN wasn't right
I like the idea of RPCs for buttons anyway, but idk I'm in an awkward spot cause I'm trying abstract as much code as possible for players and npcs
But like if auto attacking sends an RPC every x second for every attack for the player, how does it work for the npc? I don't want it to send RPCs
Yeah, definitely seems like RPC isn't too good considering how often the data needs to be sent
Command stream seems a lot better
yea i built the same bug in my netcode ๐ client/server both in the same host (player clicks host and plays, no dedicated servers) when i sync stuff from/to local clients I override the whole buffer ๐
but my buffer is actually a ton of smaller buffers, every 'command' (rpc) is its own
something like auto attack would be a state, not a rpc , the rpc would be to enable/disable auto atack
I figured, but since an auto attack is just automatic casting of the ability "Attack", I would need a completely different logic for it than other abilities
hmm yea thats annoying
I'd like it to be homogenous to any other ability
maybe its more that any ablitly could be marked as 'auto cast'
Oooh
99% of abilitlys wont
I can definitely go off that, thanks!!!
So... Thats why i got that weird ecb exception... I have a system removing entities which are outside the players... "Chunk", but those can still receive updates because of the server settings... So that entity is marked for being deleted -> Deleted but still existing because of SystemComponents or however they are called -> Update coming and buffering .Set operation -> ecb tries to set a component to an entity which barely exists... Its alive, but not it components and it gets removed later on. Damn i wish theres a nicer reactive system solution
Sooo... i have a bunch of entities i clearly dont want to iterate over by using Entities.ForEach() or queries. Is this somehow possible without adding .Exclude(); on every single query or system out there ? Some automatic tag which makes systems and queries ignore all entities with it ?
Ahhh thats exactly what i want... So theres a "Prefab" component out there by default ?
There's Disabled or Prefab
Thanks ^^ is there any difference between them ?
Prefab is meant for prefabs, you probably want Disabled
Functionally no. Just about what fits better in context
And you can filter for them separately in your queries
Actually I guess Prefab is different since Unity will remove the prefab component from the copy if you instantiate a prefab entity
Thanks a lot ! Prefab works like a charm in my case ๐
Thats actually a huge advantage of unitys ecs... some other ecs i used in the past did not support that by default... which means i needed to "hack" myself into some methods for overwriting them
I forget like everything about dots and programming in unity ๐ฆ this stuff isn't like riding a bike
@tight blade just takes time to make it stick ๐
and then time to make it unstick, I'm afraid
Anyone know how I could grab a reference to a particular game object in a system startup?
TimeToStick > ToToUnstick
I've been programming for years now, i cant imagine it would ever unstick from my head ๐
GO or Entity?
You could call GameObject.Find... methods in OnCreate
For GO you need a component with an Entity field and then in the editor you can map the GO in the component's field
but you need to be 100% sure that the scene containing that GO is the first one loaded
better to look into the conversion worldflow (subscenes) and use that
GO. I need to populate a scene object with a compute buffer and then have the system grab the reference that way
The hardest thing about using an ECS is to decide if a feature should be implemented as entities, pure data structs or OOP classes.
err, sorry, compute shader
not compute buffer.
I haven't come up with any other way to get a reference to a compute shader into a system
especially as im networking, everything server should be pure, but client is where GOs will need to exist
There's no easy way since gameobjects don't exist in OnCreate. You either hook into scene management callbacks or attach your data to an entity as a hybrid component https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/hybrid_component.html
oh does oncreate happen before inital scene load?
You can get the hybrid component inside OnUpdate
Yes, ECS has no concept of scenes
yea but i thought that unity would load the initial scene first, then ecs stuff starts
huh. hmm. actually maybe I could create some kind of convoluted conversion workflow whereby I passed the compute shader reference to another system during conversion?
well the " convoluted conversion workflow " already exists ๐
You shouldn't be passing it to systems, systems can query for it
GetSingletonEntity<MonoHoldingMyData>()
that must be a hybrid concept, because that seems to be an entity query for a monobehavior
okay, thanks. yeah thats probably easier than what I had in mind. I was thinking that I would assign the conversion system itself a reference to a compute shader which it would take the value of from the first (and only) mono which it converted
and then something else would grab a reference to the conversion system
and take the reference that way
and that's all terrible
Ideally you should never be referencing anything to do with conversion at runtime
You want to convert all your data into ECS friendly stuff during conversion then query for it at runtime
gotcha. sounds like a hybrid component is the way to go then
There's a good thread about this discussing possible better solutions. We're stuck doing annoying stuff like that until Unity has a better process for pushing data into systems
thanks, guys. So glad you folks are still around
Any way to call a method from a burst foreach? Say the method is in the same system and is burstable
I tried putting [BurstCompile] but it still says that the method is a reference type
I'm just trying to abstract some logic instead of copy pasting in my foreach
It can't be static because I need GetComponent and HasComponent
as I recall, calling methods is not an issue when actually creating the jobstruct longform
must be a static method
Could I pass maybe World to the static method and use World.HasComponent? Is that fine?
EM reference inside a foreach makes it non burstable no?
you can burst compile with references to EM now?
Oh it's a struct now??
you still cant use most bits in burst ๐
oh wait, has component calls via EM are rewritten via code gen
you probably wont get that via a static method
so you need to write it manually
i think it uses a ComponentDataFromEntity
so make that outside the Foreach
then pass it down to the static method
I'll try outside the foreach
Ha it seems to work
Cool ๐ So if you create a local variable for EntityManager outside the foreach
You can use it within the burst foreach
Nice
yea that would make sence
i would double check the code gen output
make sure HasComponent is rewritten
blergh... cant quite... So, in this example, AddHybridComponent is doing what with that monobehavior? I notice the example didnt bother to recover the primary entity or anything before calling that
is it just creating a singleton entity that I could query for by that monobehavior?
I mean that's surely what I'd like it to be doing
wohoo! That is precisely what it seems to do!
well okay, that was a lot easier than I had expected
alright. operation "port my burst jobs to a compute shader" is underway
about 6 months deferred from its original planned start date
Let me fill buffers of entities in the editor PLEASEEEE
How do you fill a buffer of entities via IConvertToGameObject?
You can get the entity of a converted gameobject by calling GetPrimaryEntity on the conversionSystem.
If the referenced gameobjects aren't part of the conversion process because they aren't inside the same subscene or child objects you have to use IDeclareReferencedPrefabs to hook them into the conversion.
The Unity.Entities.EntityManager has been declared as [ReadOnly] in the job, but you are writing to it.
Bro what the only thing I do is GetComponent and HasComponent ;_;
You can't use entity manager inside bursted jobs. Use GetComponent/SetComponent
I'm trying to pass it to static methods cause I want to abstract some code
Not looking like a good idea so far
If you're calling these from jobs then you need them to take a command buffer or a ComponentDataFromEntity
No, if you need to read a component from an entity you need to use a ComponentDataFromEntity
@stone osprey Hey did you ever get the partial + asmref working?
how do I avoid boxing when using a list of interfaces that are structs?
for example
IComponentData[] list = new IComponentData[5];
list[0] = new TestComponent(); // this boxes
how does unity deal with this? don't they also store a contiguous array of icomponentdatas in each chunk?
this must have been longest delay in a long time before new entities version.. there probably hasn't been any info about 0.18 yet?
0.17 released over 4 months ago
still waiting for that dots blog post too ๐ค
I think it's only been 2 months hasn't it
yeah more like 2 months
yes exactly, I have many groups
would you rather use a dynamic buffer component or a native array? also, can native arrays be stored inside a component?
I guess it depends on how it's being used. If you need to store these groups or share them between jobs or systems then you should use dynamic buffers
But no, native arrays can't be stored on a component.
Only Unsafe ones
There a how-to guide on diagnosing burst related crashes in standalone players?
Analyzing the crash.dmp file wasn't all that helpful
The crash seems to be a result of burst
ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF9E8FAA0D8)
0x00007FF9E8FAA0D8 (UnityPlayer) (function-name not available)
0x00007FFA1A85C247 (KERNELBASE) UnhandledExceptionFilter
0x00007FFA1CD95070 (ntdll) memset
0x00007FFA1CD7C776 (ntdll) _C_specific_handler
0x00007FFA1CD91F6F (ntdll) _chkstk
0x00007FFA1CD41454 (ntdll) RtlRaiseException
0x00007FFA1CD90A9E (ntdll) KiUserExceptionDispatcher
0x00007FF9ED09154F (lib_burst_generated) Ordinal0
0x00007FF9E91D320C (UnityPlayer) UnityMain
0x00007FF9E91D387F (UnityPlayer) UnityMain
0x00007FF9E91D17AC (UnityPlayer) UnityMain
0x00007FF9E91D280C (UnityPlayer) UnityMain
0x00007FF9E91D18D7 (UnityPlayer) UnityMain
0x00007FF9E91D1BE7 (UnityPlayer) UnityMain
0x00007FF9E91D2D30 (UnityPlayer) UnityMain
0x00007FF9E92BE678 (UnityPlayer) UnityMain
0x00007FFA1C807034 (KERNEL32) BaseThreadInitThunk
0x00007FFA1CD42651 (ntdll) RtlUserThreadStart
Though the dmp file points to something else entirely (probably a crash resulting from the burst memory exception, or just happens to be executing at the same time)
Doesn't look like they ran out of memory either
in module UnityPlayer.dll at 0033:e909f254.
40% physical memory in use.
16287 MB physical memory [9723 MB free].
9914 MB process peak paging file [9626 MB used].
4096 MB process peak working set [2509 MB used].
System Commit Total/Limit/Peak: 18767MB/21919MB/31501MB
System Physical Total/Available: 16287MB/9723MB
System Process Count: 178
System Thread Count: 2270
System Handle Count: 85084```
Hmm, I had a somewhat similar crash in player a while ago, it was due to a missing singleton. Could be the same? The error message was the same, but the callstack explicitly said that this was during a GetSingleton call, so it may not be as well. At least worth it to look through your scripts to see if you're missing a RequireSingletonForUpdate somewhere
Can't find "ConvertToEntity and Subscene workflow" thread on forum. Does companions works with subscenes? In editor they work, but my build crashes, so i trying to find reason.
https://forum.unity.com/threads/new-subscene-converttoentity-workflows.638785/ i guess it got unpinned? speculation but wonder if the next update will bring what topher was talking about for whole scene conversion?
@hollow sorrel I dont think you can ๐ฆ
maybe some unsafe pointers somehow but thats still way outside my skills
Sorry this was a reply to your boxing question
@ocean tundra No i did not solve that problem :/ i just wrote some reflection magic which works fine. Im gonna try it again once i update my unity version ^^
Sweet let me know if it works
I had very simlar errors yesterday, and they were caused by a namespace mismatch, but we 100% checked that :/
I'm loving DOTS. Just had 20x as many fish spawn on boids, and it looked like the Death Star. I have a large monobehavior script for controlling my player. There is a totally different play style with DOTS. As I edit this single monobehavior file, I want it affecting both GameObject Unity and Entity Unity depending on what play style is enabled. My question is: How do I send data from monobehavior to change iComponentData? Thank you.
You can get the EntityManager of the default world via World.DefaultGameObjectInjectionWorld.EntityManager.
Thank you. ok, then how do you set a variable with that?
you can then manipulate entities e.g. create entitiy queries via CreateEntityQuery
Lets say I had an icomponentdata of positionX
EntitiyManager can do all the stuff like SetComponentData on an entity
Thank you
Then I should be good to go.
One more question: In order to be compliant with the havok engine, how should I set position/velocity/acccleration in DOTS?
I did not use havok physics yet. But I guess you can set the velocity on the physics body
Ok velocity seems to be stored in its own velocity component not the physics body
try setting the velocity component value
glad to help ๐
God bless you, and all you guys here at the Unity forum.
Should i dispose UnsafeHashMap as values of NativeHashMap separately or code like this will work correctly and UnsafeHashMap will dispose automatically?
public class UserInventoryController : MonoBehaviour
{
private void Awake()
{
UserInventory.InventoryStorage = new NativeHashMap<ulong, UnsafeHashMap<ulong, InventoryBlockData>>(500,Allocator.Persistent);
}
private void OnDestroy()
{
if (!UserInventory.InventoryStorage.IsCreated) return;
UserInventory.InventoryStorage.Dispose();
}
}
Yep, Unity intends to keep the same API between com.unity.physics && com.havok.physics, allowing to presumably switch easily later, if you need. cc @remote crater
@half jay you need to dispose them all separately
What should I use instead of JobComponentSystem?
Yeah, found it thank you
Can you read the position out from the Translation component?
or do people create a Position component?
using 2020.3.1 lts
Translation is the position component
Yeah that made sense
I just found an old code that was made for basic collision
and it had Position and JobComponentSystem
and I am trying to remake what it did
do you know what ToConcurrent() does/did?
It's the deprecated name for AsParallelWriter. Gives you a wrapper for a container that is safe to use in parallel jobs
Did the input system change?
Input.GetMouseButtonDown(0); seems not to work?
or it just doesn't work with ecs?
if you're calling it on the main thread, it should work out of the box, but it also depends on whether you have the new input system active or the old one active (or both). I don't think you can call Input.GetMouse(...) on a different thread though
I don't think calling it in a job will work
yeah I could call it outside
If you use the ForEach WithoutBurst and Run it will work
[BurstCompile]
public struct CheckRaySpheresIntersection : IJobProcessComponentDataWithEntity<MySphereCollider, Position>
{
[ReadOnly] public Ray ray;
public NativeQueue<Entity>.Concurrent collided;
public void Execute(Entity entity, int index, [ReadOnly] ref MySphereCollider collider, [ReadOnly] ref Position pos)
{
if (CheckIntersection(ray, collider, pos))
{
collided.Enqueue(entity);
}
}
}```
Entities.WithName("Update_Displacement").ForEach((in MySphereCollider collider, in Translation pos) =>
{
if (CheckIntersection(mouseRay, collider, pos))
{
collidedEntities.Enqueue(entity);
}
}).WithBurst().ScheduleParallel();```
How do I get the entity reference in the foreach?
Am im missing something? I have this entity hierarchy. Entity A parent for B. And LinkedEntityGroup of A include Entity B. After destroy A. Entity B still alive
I made entities manually not through conversation
For a linked entity group the "root" entity must be the first element in the buffer
so a should be the first element then b
ahh
@zenith wyvern Sorry, I read that page but somehow I skimmed that I can just have it in the argument
Does anyone use Odin with ECS conversion workflow
I started to very recently
is there a small multiplayer dots sample to learn from?
do you guys use the physics package for collision
or do you have to make your own collisions?
physics package
is it easy to use with pure ECS?
What do you mean by "pure ECS"?
I am not using the convert script?
I am guessing you can add collider components?
for my raycast I used a basic AABB system
but probably there is an easier way with physics
I think it would be very hard if you weren't using gameobject/prefab conversion to handle adding all the correct components to your physics objects
I am defining 4 native arrays in OnUpdate but I am getting this error. I think I have done the same thing in other systems so I am not sure what the issue is?
thanks
If you enable all safety checks the log should give you an "Allocated from" exception that gives you the exact line of the leaking container. Somewhere your function returns before that container is getting disposed
Yeah I have burst safety checks on and leak detection full stack traces on also. The error shows the lines which is how I found it was from those declarations. There is only a foreach after. I thought you didn't have to manually dispose native arrays in that case? I am wrong?
You have to dispose any native container you allocate with TempJob or Persistent. No exceptions.
ok thank you
@north bay what is the difference between Odin on asset store and the GitHub one. Are you finding it work ok with conversion workflows
So does DeallocateOnJobCompletion not deal with this?
It should
I thought you said you were using a ForEach though
That's an attribute for a job struct
This is for a different system as I am now going through plugging leaks
That attribute only works with native arrays, you should prefer just using container.Dispose(jobHandle) after your schedule the job
Yeah that is what I have done for most of them now. For this issue I am running a main thread system with several sequential forEach's. Do I have to add jobhandles to each and chain them so I can dispose the nativearray at the end?
You can just pass in Dependency
At the end
As in the Dependency property, assuming you're not doing anything unusual with your job handles
Oh wait if it's a main thread system there shouldn't be any job handles involved
If that's the case just dispose it without passing in anything
Oh cool, I didn't know you could do that
So for physics at least the mesh and the collider is better to be converted?
This is causing an error saying that it has been deallocated
Can you show the code?
Ok I warn you that it is very awkward code, It is also long. You mentioned previously a way to share long code?
hatebin
pastebin?
Ok I have pasted into that but how do I share it? I couldn't see anything online...
Copy the linke from your address bar
are you sure? https://hatebin.com/
click the save icon?
Yeah I did
it should append to the url
suppose it could be, try pastebin instead?
Works on chrome for me
oh, its possible chrome does just hide the url but if you click and copy it, it should be the proper thing?
Yeah doing the same thing in edge for me
I discovered something weird. An Entity variable cannot be set to null. How do I set it so its 0, null or not there?
were you using Entity.Null ?
I never check, but I assume it's read-only, based on how ECS works
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Yeah I need to fix something because I thought I could do that too.
oOOoooOoh like setting an Entity reference to null xD I read too fast sometimes
Don't allocate a native container in a system constructor. If you're allocating a temp array for a job you need to do it at the start of OnUpdate and Dispose it at the end of OnUpdate
If you need a reusable container to be used every update allocate it as persistent in OnCreate and Dispose in OnDestroy
Oh right, that makes a lot of sense
In that same code I am using if statements to run code depending on if certain entities exist, currently I am doing:
but this doesn't work when I don't make the entities, is there a way of checking an entities existence in this sense?
HasComponent<Whatever> will return false if an entity is destroyed
destroyed/never instantiated?
if(Exists(pistonEntity)) ?
It's an entity manager function not a system function
When i use a native/unsafe hashmap... and allocate stuff with ".persistent"... i always need to dispose it by myself right ? Which means if i replace a component with a unsafeHashMap without disposing it... it will create memory leaks ?
yea that sounds right
Ok thanks ^^
I posted this in www.reddit.com/r/unity3d , but it is so cool. Cool Video: https://youtu.be/Ws-7rqluv6w Take the left fish out on the boids example. Then raise the number until your system gets low performance. 2.5 million fish looks crazy, but also just 1fps. 500k looks ok at 7 fps. I'm posting this just because what Unity made as a demo project is soooo cool to tinker with numbers.
ECS DOTS lets you have 10-1000x as many poly on screen by unlocking cores. So as more and more people play these games, they'll buy CPUs with more and more cores. Maybe in 6 years we have 1024 cores and stuff, so then we are able to render 1000x-100,000 more objects.
Download ECS examples that you can import right into your UNITY hub, from th...
If you wanted to stress test your computer: Import project to unity from official unity git: https://github.com/Unity-Technologies/EntityComponentSystemSamples
From what I can see in this, the entity must exist at some point. Is there a way to find if it exists at all?
@stable siren Can you explain your question more?
If you destory a entity .Exists with the same entity will return false
that destoried entity is 'gone', and will be reused at some point in the future
I want to only run certain code if the piston/Diaphragm exist. This was my first attempt, I then tried manager.Exists(pistonEntity) but I don't think that works either
i would probably use both depending on how the setup works
if your piston entity or diaphragmEntity starts off 'null' or you destory and recrreate in runtime code
start with the != ENtity.null
then if that passes do a Em.Exists
(tho this may be unnessessory as EM.Exists probably does a != null check, but i cant look at the code atm
so i think GetSingletonEntity will throw if the entity dosnt exist
But when I don't spawn them in (I have them starting as a gameobject) then an error is thrown and the logic doesn't seem to work
yes exactly
oh perf
About what percentage of your systems are burst? Because I feel like I'm putting too much effort in writing bad, not reusable code just for the sake of using burst.
Should I aim for a high percentage or does it matter not?
+/- 90 id guess. burst everything you can, I dont know what bad not reusable code has to do with being burst compatible though
yea same for me
Some things I just have no idea how to do
Like dynamic buffer lookups
Writing for loop every time?
Can't even use a predicate
maybe a bit higher then 90% if you count all the code generated systems
i dont know what a predicate is ๐
nothing wrong with a for loop
Yeah but like for example I have a dynamic buffer of abilities, each of them have an ID component
Because I'm using netcode, everywhere I need to reference an ability I hav eto use its id
pretty sure you can make linq style code compatabile
So every I reference an abiltiy I have to write to same for loop GetComponent<ID>
I tried to make linq style extensions
But you can't use any form of delegate
Because they're oop
Also can't have dicitonary components
look at native lists sort
But Id on't think that's burstable
double check that, i think it is
is ID part of netcode or your own code?
but not at my pc to see what i did
Well like, because the ability itself is an entity but not a ghost, I can't send it as an entity, I have to reference it by ID
oh so it is burst compatabile
So whenever the client or server receive the ID, I have to loop the buffer....
im not using netcode but id be really surprised if it was built into netcode and not burst compat
BUT not a delegate, instead you make a struct and implement ICompare or something like that
ha yeah I understand
Yeah I did that with sort
But honestly rather than loop through the buffer I should have some way to store a dictionary
Where I can just do buffer[abilityId]
I could use an unsafehashmap but
It's unsafe and that intimidates me ๐
is the ability ID global for everything?
you could have a native hash map in a system
No cause an ability is an entity and every character that has this ability has an entity
but if your Ability list is attached to a entity and the id is to something in there its a bit harder
Since things can be added to it such as Cooldown etc
i see so you have
CharacterEntity
- Child Ablitiy1
- Child Ablitiy2
- Child Ablitiy3
?
Pretty much yeah, I have another entity to hold the abilities
and the character entity has a buffer linking to them?
Character
Abilities
Ab1
Ab2
Yeah
Character has a component that references to the Abilities entity
THen i can do GetBuffer<Child>
I wouldn't count on it, but yeah maybe I could use index
yea thats where i was going