#archived-dots
1 messages Β· Page 103 of 1
Maybe you should try modifying the UV property offset instead.
That's how I do animations based on the codemonkey tutorial. I have a spritesheet and pick a sprite from it by setting the correct UV width/height and offset.
Not sure about standard shader, I'm using a transparent unlit one.
Hmm. I'm looking for a shader with normal maps, spec maps, emission maps, and maybe occlusion maps as well.
what render pipeline are you using?
You can't be using both -.-
you actually CAN use multiple
it's just not supported or endorsed by Unity
plus things get complicated fast due to differences between the RPs
in URP writing Vector4(tiling_x, tiling_y, offset_x, offset_y) to _BaseMap_ST works for me
I assume there is an equivalent in HDRP
@dull copper you mean like switching between render pipelines at runtime?
yeah
I did a proof of concept with LWRP and HDRP runtime swapping a long time ago when Unity staff insisted it can't be done
after that they just said it's strongly not recommended and not supported π
hah, the scariest thing in the world - a programmer having a "hold my beer" moment π
I haven't tried on any recent version... my main concern would be if the shaders from other would be stripped etc
but that should be somewhat easy to fix as the relevant code is on c# side
I have a real reason to want that, altho I hope I never have to go there
I'm using HDRP for my main project but it doesn't scale down to low end devices that nicely
so having some crappier graphics mode using URP or built-in is something I could consider swapping into for these computers
in ideal case, HDRP would have just some super slimmed mode that doesn't do anything fancy... for example UE4 has one
Yeah, can see how swapping SRPs at runtime would be useful, just always assumed the resource management differences between them would mean trouble. (Do SRPs manage their shaders/vertex buffer layouts/textures sent to the GPU, or is that done at the lower level they all share?)
Last time I tried looking into SRPs was back in the early days when looking the wrong way caused the editor to crash, so I kinda gave up on learning them π
each have their own managers for that kind of stuff afaik
if you have both URP and HDRP packages on your project, you can just simply swap the SRP asset from the settings via script
this mechanism is originally designed to be used for swapping SRP assets for the same SRP but different default confs
but there's nothing preventing you from swapping HDRP asset to URP asset there too
after that you have to swap to compatible shaders for each material, swap sky system, tweak lighthing etc
there's like dozen things that would change there
So that would cause each SRP to have their copy of every mesh/texture on the GPU?
when I did the test, I only implemented HD template scene swap
ah, I dunno about those
anyway, one could have really funky bugs with this approach that Unity would never solve π
b/c that may kill the "swap for low end devices" use case
(apart of the whole "swap every shader everywhere" thing being kind of terrifying)
I dunno, you could just load different scene variant
you could automate the conversion 100%
I mean, nobody would do that kind of work manually
there's one thing that's kinda difficult nowadays and it's the shader graphs for URP... since nonHDRP SG's still work on HDRP, I dunno which one it would pic for the compilation target in the editor
if you use PBR Graph on URP and save it, it generates URP variant for it.. if you have HDRP and use PBR Graph, it generates HDRP variant for it, it's not the same shader on both, only same graph
of course you could just generate the shaders manually and save them as shaders instead of shader graphs for the other option
but yeah, I'd rather try to put effort in trying to make HDRP have some slimmer mode than going through all this nonsense
i do wish hdrp had more options to strip it down, and make it look super ugly but run faster
I already have two versions of every asset. One for SD (URP) and on for HD (HDRP). Different scenes for different versions. Though, if it's too much work, I will probably just have two different projects for the SD and HD versions and reuse code and assets where I can.
I can try _BaseMap_ST when I get back later, but can anyone confirm that this is the way to do it in HDRP with the standard shader?
I suspect the name in HDRP is different (but the convention is {TextureName}_ST). Look at the HDRP Lit shader
looks like the next step for entity conversion is node based tools
seems they are doubling down on gameobject > entity conversion instead of entity editor tools
ive made my peace with conversion. i just want native ecs parts faster though π
that tool looks interesting though i guess from that example such a thing wouldnt be that high up on my wishlist for dots features
@warm topaz Cannot use Quaternion.LookRotation since it will flip over when the direction changes from left to right, ended up using quaternion.RotateY, but I don't like this approach
@soft nova If you're dealing with full 3d rotation and want to reason about it found that spherical coordinates work really well
i.e. for doing logic like 'how far left is this of me', etc. and other shit that both quaternion and euler are annoying for
gameobject->entity conversion does make a lot of sense
a lot of game projects have some sort of "bake" step that optimizes in-editor into runtime friendly stuff
but at the moment its more of a bandaid and quite buggy
and has some very funny shit like only being able to have 1 component per file
great unity, let me have 50+ files each of them of 3 lines of code
Hey all, wanted to check and see if there have been any updates on foreach support being added to Burst. Per the docs it's not available but will be added in the future: https://docs.unity3d.com/Packages/com.unity.burst@0.2/manual/index.html#language-support. I'm guessing these docs are up to date and this hasn't been added yet?
Alright, thanks
I'm having trouble using an enum as the key value for a NativeHashMap. Getting the following error: The type 'RockMine.CityGen.Networks.GrowthRoles' cannot be used as type parameter 'TKey' in the generic type or method 'NativeHashMap<TKey, TValue>'. There is no boxing conversion from 'RockMine.CityGen.Networks.GrowthRoles' to 'System.IEquatable<RockMine.CityGen.Networks.GrowthRoles>'. [Assembly-CSharp].
Been searching around but no luck finding similar cases. It works with dictionaries so I assumed it'd work for NativeHashMap, but maybe there's some limitations I don't know about?
can you implement IEquatable<T> on GrowthRoles?
@mint iron can't add interfaces on enums by hand
they should exist
@verbal pewter I would think this is a unity bug
assuming that RockMine.CityGen.Networks.GrowthRoles is a real enum
it should handle it fine
It is
ahhh... yeah π
Hmmm, guess I should report it.
Not ideal but you could just use an int as the key instead and convert it
unity bug then, @verbal pewter workaround is to use int instead and cast
Alright, thanks π
Hi everyone, I am trying do this : transform.up = hit.normal during a raycast but in ECS. as Entities can't have Transform, I need to do it by hand or by using something else. I saw that there is something called LocalToWorld but I don't know if it is applicable. Do you guys know How I can do that ?
Second question : I would like to know how I can make my entity rotate around an axis. just like transform.LookAt(Vector3) but only around a given direction. I don't know if it is possible but it would make my life easier π Maybe something like Rotation.LookAt(Vector3 target, Vector3 axis)
@fast moss Entities have things roughly equivalent to transforms (Translation, Rotation, Scale). You would use them for both of those things. Link with documentation: https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/transform_system.html
The first part is essentially setting the rotation to one derived from a raycasthit normal. IIRC Rotation uses quaternions, no sure about ECS physics raycasts, but you might need to do some conversion there.
As for the second one, vector and matrix math is where I started to really fall off in math classes, but what you want is to set the rotation such that the forward vector is towards another point (getting the direction is trivial: TargetV3-OriginV3), while maintaining some 'up' direction. it would be more correct to do this as one matrix operation, but honestly if you could solve the look at problem, you could then just rotate around the lookAt axis to have your up be correct.
That's just how I would think about this; hopefully someone else has more familiarity with the APIs in question and can give you more specific directions.
@tawdry tree thanks ! I'll read this, I was looking for a documentation for the new Entities package but I wasn't able to find what I wanted π I'll try some stuffs and if I manage to do what I want I'll tell you π
Just want to clarify, is it possible to change a value in an entity component from a Monobehaviour by getting it using GetComponentObject and changing the value? Or would changing that just change the local struct's value?
Components are structs, and as such passed by value, not reference. You need to use the entity manager helpers (SetComponentData and the like) as you would from ECS. World.Active.EntityManager Should be available from monobehaviors too, IIRC
World.DefaultGameObjectInjectionWorld
I'm curious what the difference between GetComponentObject and GetComponentData is in that case?
"ComponentObject" is Unity's name for a monobehaviour that's been attached to an Entity
Ahhhhhh, so I need to use GetComponentData.
ComponentData is just to get regular old IComponentData
Makes sense, thanks π
Hey guys, do you know if there is a way to use the PlayerInputManager and still take advantage of DOTS?
@opaque hemlock typically for input you'd have a system that runs at the start of the frame and reads input from somewhere (e.g. Input.getkey or rewired or whatever new inputmanager uses) and sets input components such as playerinput that has jumpingPressed and float2 movement etc
just looked up playerinputmanager cuz apparently it's a monobehaviour and docs say
Note: These components are built on top of the public Input System API. As such, they don't do anything that you can't program yourself. They are meant primarily as an easy, out-of-the-box setup that eliminates much of the need for custom scripting.
so ideally you'd make your own version that doesn't use a monobehaviour
but if you really want to use it you could add the monobehaviour to an entity and poll it in your inputsystem
ah okay great thanks @hollow sorrel !
I've got a system that adapts player input manager and the player input monobehaviours via hybrid ECS. I just pull what I need during the Init system group phase and write it to a "raw input" component struct. Further processing is entirely in pure ecs
Hello guys, I am currently experimenting with DOTS trying to create some floating island made of cubes of different sizes.
Until now I relied on Mathf.PerlinNoise(float x, float y) function to create the 3D noise used to build my islands. But now I am looking for some performance improvements so I tried to use Unity Mathematics cnoise(float3) function thinking it would be faster, but at my biggest surprise using this function slowed the process by about 20 times.
I am simply triple looping over my island size et computing perlin noise for each point.
Am I doing something wrong? If anyone has some ressources talking about how to use Unity Mathematics's perlin noise I would be gratefull, thank you!
@zenith marsh new math lib is optimized for burst but tends to be slower than Mathf in mono
il2cpp build should be a lot faster than mono but in-editor will still be slow so would prob be best if you can compute noise in a burst compiled job so it's fast in both
@hollow sorrel Thanks for the info, so if I understand well, I should find a way to compute my noise in a job instead of doing it in a Monobehaviour script ? Then both editor and build would have better performances because it would use burst?
yes
Okay I will try to do that then thank you!
Welp, just learned that IComponentData can't have NativeContainers as fields. Now that I think about it that makes sense, but I'm left wondering what the best practice is for dealing with IComponentData structs that need to reference NativeContainers? My first thought is storing the NativeContainer on my singleton manager, but that makes me feel dirty. Are there different best practices for this?
Why do your components need to reference NativeContainers, can you replace them by DynamicBuffers?
I have two different use cases right now. One is needing to store a NativeList of Nodes and Connections for each Network. Items will be added to this list on a regular basis. The other use case is a NativeHasMap in the NetworkSettings component that stores GrowthPatternSettings. I'm not familiar with DynamicBuffers so let me look into those a bit more.
@verbal pewter https://github.com/fholm/unsafecollections
These can be put on a component
tbh is a big oversight on unitys part that the collections can't be put on components, i understand that why in the general sense you usually wouldn't want that - but ofc there's A LOT of cases where being able to pair a collection with an entity in an easy way is by far the best solution to whatever problem is at hand
any news on compiling burst to linux?
@trail burrow Interesting, thanks! To be honest, I'm not very familiar with "unsafe" code. Did some reading just now and have a general understanding, but I'm not sure I understand it enough to use those types safely. Are there any special considerations that need to be made when using them? As an example, at certain points in the program NetworkSettings gets overwritten with new data. This doesn't happen very often, but I still don't want to use UnsafeCollections in that situation naively. Would it be a bad idea to use them in situations where the data gets overwritten?
@verbal pewter well you need to free the memory by hand, like you do with unitys native collections
thats about it
The same thing would happen if you over-wrote one of unitys collections, etc.
Main difference is that the unsafe collections dont have any leak detection, compared to unitys
but the leak detection is the reason you cant put them on components... so π
Alright, makes sense. And freeing the memory is done by using Dispose()?
no, there's a CollectionType.Free(ColletionType* ptr) on each of them
i.e. UnsafeHashMap.Free(map);
UnsafeList.Free(list);
etc.
Ahhhh okay
Thanks for putting together that collection, going to save me a lot of headache along the way I think haha
np, there's a few concurrent collections coming also i've been fiddling on
mostly fairly narrow use-cases tho for those
Which ones are available there @digital scarab ?
tell me about it, i wrote the serializer for us which can handle serializing pointer/generics, etc.
it's a fucking mess
nested collections of collections of collections with pointers back and forth
Oh, ya, that's a consideration...
@digital scarab Which package are these in?
@digital scarab lol looked at the hashmap you guys have
its so similar to my code haha
i mean not many ways to do a fast unordered hashmap
just funny when even variable names are close :p
okey closer inspection, not that similar
was just alloc method (First i saw) that was similar enough π
anyway, looks good
fholm says as he hits cancel on the call to his lawyer
is joke
oh, lol i get it now
okey yeah i wish i had the patent on hashmaps
i'd be raking it in π
@digital scarab Trying out the built-in UnsafeList, but I'm not sure how to release the list properly once I'm done with it. I'm guessing it's with the Destroy() method, but I'm getting this error: Argument 1: cannot convert from 'Unity.Collections.LowLevel.Unsafe.UnsafeList<int>' to 'Unity.Collections.LowLevel.Unsafe.UnsafeList*' Which is probably because I'm trying to use it on a copy of the data rather than the pointer? Not familiar with this stuff at all haha
@verbal pewter Unless you're comfortable with pointers and unsafe code, you should just stick with DynamicBuffers
They let you attach resizable arrays to entities and they are integrated nicely with ECS
... yeah but not every problem can be solved by an array
Pretty much.
My point is DynamicBuffers should be the first suggestion. If for some reason your problem can't be solved using those, THEN you should consider unsafe code.
What is it about DynamicBuffers that doesn't work for you?
I need to be able to access the values with keys, so I was hoping to use a HashMap.
You want to attach a hashmap to an entity? What exactly are you trying to do?
the problem is looking up values on keys? π
The struct NetworkSettings has a number of GrowthPatternSettings that need to be accessible by the enum GrowthPatternType.
Are you sure NetworkSettings needs to be a component? It can't be it's own NativeContainer?
that can be solved with an array and casting the enum to an int tho
or rather a NetworkSettings* buffer
or in this case, a dynamicbuffer
and just cast to int to lookup
What if the GrowthPatternSetting has one GrowthPatternType value which casts to the value 2?
size the array on maxvalue+1 and accept the memory waste
assuming that max isnt like 521232
or something else
If in the end you decide you really need a unique container attached to your entity I suggest you read this
And use the NativeArray source as reference
Build a simple nativecontainer and go from there
Okay, will look into it. Thanks!
If you're going to use other people's nativecontainers you should still read that so you have some idea what's actually going on under the hood
@zenith wyvern the native containers still cant be put on components tho
I thought the Unsafe ones could?
yes the ones in Unity.Collections.LowLevel.Unsafe can
but native container means something specific tho doesnt it?
i.e. the Native<T> structs
and the ones in my repo can, ofc
Yes, and if he wants to start writing unsafe containers he should probably learn from the higher levels ones first, which are built around the unsafe ones
For someone with no experience with low level memory management the nativecontainer attribute is a great place to start
Ultimately it probably makes the most sense to use @trail burrow's implementation since it sounds like Unity's built in unsafe containers aren't straightforward to use.
I haven't used fholm's containers, he obviously knows what he's doing so I can't speak to that, all I can suggest is that if you can find any way to fit your problem into a DynamicBuffer, you should
Especially if you're not really comfortable with low level memory management, it will save you a headache in the end, trust me
I agree, if you can make your problem fit in DynamicBuffer, use it.
Or rather, lets put it like this: If you want to learn how to deal with memory yourself, using unsafe collections and such is a great starting point. But if all you want to do is to move on from this problem and keep working on your game then you will inevitably blow your foot off with the native mem at some point.
There's nothing to be 'scared' of when it comes to unsafe C#, native mem or pointers.
It's easy to get your head around, it's not some dark magic
But it might take a little while to change your thinking compared to dealing with C#s garbage collected reference types
Fair enough. But it sounds like that's already the case with NativeContainers? I guess my understanding at this point is that if I need to overwrite some data in one of these collections, I need to release the data that was stored in the collection first. As long as I have a straightforward method of making this happen (which it sounds like Unity's built in unsafe containers don't have) I should be good to go, right? There's always the chance of forgetting to unlocate it, which is definitely a risk worth considering. Or am I over simplifying it?
changing the data of the collection itself, i.e. what elements are in the hashmap for exampled
doesn't require you to 'free' anything
(assuming that the data itself doesnt contain pointers to other allocated memory ofc)
Basically there's a good reason Unity makes it so complicated to attach an array to an entity, and DynamicBuffers will protect you from all the pitfalls that entails while keeping it sufficiently simple
i can only answer for my collections, but what you need to remember is this:
1) When adding a component with the collection pointer on it, allocate a new collection
2) When removing a component with the collection pointer on it, free the collection
that's it
Hi
I'm struggling with garbage collection that comes from allocating NativeArray's
My voxel world checks for neighbour XYZ (-1 to +1) chunks and grabs Block Data NativeArray from there, but if the chunk is not yet generated, i have to create temporary NativeArray
but
when i actually generate A LOT of chunks at the same time, GC is slowing down the game by ~10-20 frames
and all the garbage comes from those allocated Natives
so, my question is
Disposing a nativearray should only allocate in the editor
It's the dispose sentinels afaik
Try disabling safety checks
Could be editor only yes?
can i somehow create empty nativearray?
without alloc
to pass to job
and inside job check if it's created?
because when i try to do Allocator.None it yeets an exception
and i can't just simply not allocate those NativeArray's, because - exception
@zenith wyvern i'll try, gimme a minute
If you need high throughput/lots of allocations, i would advise using UnsafeUtility.Malloc manually and just allocate the data you need, and doing voxel stuff seems like a fairly high throughput scenario
No need to restrict yourself to unitys native<T> wrappers, i mean NativeArray<T> is just a wrapper around a void* ptr + int length
this is why every chunk has it's own NativeArray of BlockData
and i just pass them as readonly for render jobs
so i don't copy them over
@zenith wyvern disabled those and still GC hits hard
Profile standalone build
@trail burrow So I was over complicating it π Thanks for the explanation!
np
@zenith wyvern gonna try compile it, maybe it wont be as laggy as it seems @ build
but in editor i'm getting around 35fps
and i don't have bad pc
Make sure you attach the profiler to it, you'll see the allocations are gone
Assuming those are in fact the source of the allocations
ok!
aaaaaand it didn't even work, lol
brb, bugfix time
@zenith wyvern ok GC is gone in build
thanks!
Is there any way to get the parent or child entity while in gameobject conversion? I mean the real converted child/parent entity not the prefab entity
ok i just connected them with GetPrimary entity
Is there a way to get isPlaying status when running a unit test I wonder? Since scene loading's async operator seems to require the isPlaying status to work (otherwise we just have OpenScene in editor), this prevents me from testing some of the functionality of my game code, and not exactly easy to mock async operator in this case...
I guess some code just isn't meant to work with unit tests and I should just manually test this area of the code.
Hm, thinking about this, I could apply the adapter pattern to this, and simulate the async operation internally when in editor mode when isplaying is false.
is there any preferred approach to debug draws (lines etc) for DOTS?
or is this still something that everyone has to improvise with?
I remember some usermade early ECS linerenderer but I doubt it's up-to-date anymore
I guess I could just use thin cylinder meshes for this purpose....
or arrows
Samples have a gizmo example which might be the way Unity see things being done for now
you mean dots physics samples?
I think they do it on monobehaviours there
those physics samples barely use dots
and afaik, you need monobehaviour to draw those gizmos too
I guess I could just populate some list of vectors in native container and sync it between dots and monobehaviours where I actually do the draws
but it really feels like there should be something directly on dots for this
Was referring to this one https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Assets/StressTests/HybridComponent/WireframeGizmo.cs but yea - obviously a nice built-in DOTS one would be handy π
btw, I assume you mean drawing in the game view? Because Debug.DrawLine still works just fine for drawing in scene view
but surely you still need monobehaviour for it?
you don't
ah
@digital scarab is that in current a18 already?
I'm fine with using 2020.1
I hope a19 is getting out soon as well for other reasons :p
but yeah, things are still tad slow after holidays, need patience
@digital scarab it'd be amazing to have a "BURST_ENABLED" and "BURST_DISABLED" constant or something so we can put [Conditional("BURST_DISABLED")] on methods and have them automatically be stripped when burst is enabled or not
Manually having to comment code in/out depending on if burst is enabled or not
is annoying to say the least
@dull copper i wrote something for debug drawing, and it can draw from within burst jobs (by using a NativeStream). I won't claim its production ready but if you just need to see some stuff easily while developing, it should be fine. https://github.com/jeffvella/UnityDebugDrawer
Is there a way to filter entities by the DynamicBuffer they have?
@digital scarab reverse would be nice also
@verbal pewter There's examples in the manual https://docs.unity3d.com/Packages/com.unity.entities@0.4/manual/entities_job_foreach.html
@zenith wyvern Very nice, thanks!
@digital scarab lol
but you have to see why it would be useful to be able to switch a methods implementation based on if burst is enabled or not for example?
i.e. BURST_ENABLED or BURST_DISABLED
@mint iron sounds good, I'll check these options out π
have you tried that on recent 0.4 entities btw?
ah, it has demo scene, I'll just try what happens
Assets\DebugDrawer.cs(1162,33): error CS0426: The type name 'BlockStreamData' does not exist in the type 'NativeStream'
well, it was expected as these APIs evolve a lot
tried with 0.4 entities and collections
mmm, its a few months old now, ill take a look
i'm moving to montreal next week π not sure im quite prepared for the cold...
/sigh they renamed it and moved to internal
unfortunately stuff like that is quite expected, hence wanting to see some official solutions as they would be kept up-to-date
very true; this is only a problem because i wrote a clear method for NativeStream; i didn't want to allocate them every frame.
I'm curious if there are any best practices for dealing with general use functions that get used by multiple systems relating to specific entity archetypes? As an example, my Network entity keeps a buffer of child Node entities. The nodes aren't related to any systems directly, they're just used within the Network related systems. My first thought is to create a helper class for the Node entities that can be accessed from anywhere. Is there a better way of approaching this?
Dunno about best practice, but as long as they have no side-effects, public static helper classes should be non-problematic. If they operate on a specific data type you could even make them into extension methods, though I don't see why you would unless you were making a library for others (or yourself, down the line) to use
And to add to that, I've seen several other people also use it.
Alright, thanks for the input. Can't think of a better way to handle them so I might as well do it π
If I have a list of lists, does disposing the parent list dispose the child lists as well?
A NativeList with NativeLists.
Speaking of extension methods,
public static void DisposeWithChildren<T>(
this NativeList<NativeList<T>> parentList)
would be one case where an extension emthod would be kinda useful.
Yeah, my situation is a bit more complicated. As an example, I have NativeList<MyStruct>. MyStruct has a field which is a NativeList. Still probably makes sense to go that route and just create a one-off extension method.
Or helper method at least. Can you even have a NativeList extension method if it's not a generic type, such as public static void DisposeWithChildren<T>(this NativeList<MyStruct> parentList)?
Minus the <T>, that looks valid
Ah, switch out <T> for <MyStruct>?
Extensions methods are just syntactic sugar.
public static void ExtensionMethod(this object extendedObejct) { /*stuff*/}
//Used like
var obj = new object();
obj.ExtensionMethod();
//it becomes this when compiling:
ExtensionMethod(obj);
As long as you have no generic argument, you don't need the <T> between method name and arguments.
Ahhhh okay, nice. It works π
So yes, think of extension methods as static helpers that have extra syntactic sugar which lets intellisense/code suggestions tell you it exists.
Yeah, I've used them in the past but hadn't tried it for non-generic lists.
I've mostly used them for giving myself more convenient access to often-used helper methods on non-owned types and enums.
In fact, 'adding methods to enums' is probably my number 1 use of them. But other that than, adding methods to built-in or library types. And in one more recent case, extending a particular type from one solution I worked on, in another solution with a specific context. (The first solution being a nuget package shared between several other solutions)
Oh interesting, hadn't considered adding them to enums.
Hmmmm. So I just finished up refactoring everything to DOTS and tried playing the project for the first time, but it threw the following error:
```Unexpected exception Burst.Compiler.IL.Helpers.MethodDecoderException: Unable to decode RockMine.CityGen.Networks.GrowthStrategies.RoadGrowthStrategySystem+<>c__DisplayClass_OnUpdate_LambdaJob0, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null::RunWithoutJobSystem(Unity.Entities.ArchetypeChunkIterator*, Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null|System.Void*, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089) ---> Burst.Compiler.IL.Helpers.MethodDecoderException: Unexpected char < while decoding assembly name reference, expecting , instead of <>c__DisplayClass_OnUpdate_LambdaJob0, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null::RunWithoutJobSystem(Unity.Entities.ArchetypeChunkIterator*, Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null|System.Void*, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
Can't make heads or tails of it. Something about Unexpected char `<` while decoding assembly name reference, expecting `,` instead of `<>?
the joys of generated code π¦
Yeah, no idea what they expect me to with this π
Uh, I suspect burst does not like generics
Does it work without being bursted? Did it work previously? What did you change? Try to isolate that.
Using a Git or other source control (even locally) for your project can make checking such things easier.
yeah to me converting to dots is not in the wheelhouse of "just change the code to how i think it should work in dots and run it expecting no errors" there are far to many gotchas in general dots and ecs theory and just... alpha quirks
Yeah, it works without Burst.
There is one extension method that uses generics. Is that what you had in mind in mentioning generics, or something else?
TBH if converting code it's probably best to jobify first, then make it work with ECS. Don't bother with burst unless it seems trivial or you need the perf. Or to learn, I suppose.
generics don't work in burst as far as i know.
The extension method should not be the cause, but where does the generic in the extension come from? Can you sahre the extension method?
My code can't be jobified. And I've finished converting it to DOTS.
That's fine too, I meant ore of a general order of things. The main thing is really to focus on perf only when and where you need it, and oeehrwise go for convenience and maintainability (ie. good code)
Here's the extension method:
public static NativeList<T> SubsetGetByIndexes<T>(this NativeList<T> list, NativeList<int> indexList)
where T: struct
{
var subset = new NativeList<T>();
for(int i = 0; i < indexList.Length; i++)
{
subset.Add(list[indexList[i]]);
}
return subset;
}```
Make the first line like '''csharp (but backticks for the apostrophes) to get C# highlighting. "cs" should work, too
No space after the word, immediate linebreak
Ah nice, thanks
Yes
Looks to me like you don't need the where clause, what happens if you remove that?
The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'NativeList<T>'
Or more like
//Non-generic
public static NativeList<struct> SubsetGetByIndexes(this NativeList<struct> list, NativeList<int> indexList)
Ah hmmm
Don't use generics (``MethodName<T /T2, T3, .../>(/arguments/)`) unless you need to
Well I was hoping to have it as a generic for future use, but if I can make it a one-off.
it still works with any struct, same as the original code
Well, any NativeList of struct
Ah sorry, you mean changing it to struct. I was thinking you meant it more as MyStruct kind of thing.
yeah i think the compiler freaks out using the T, not sure it's smart enough to catch the where clause.. didn't know you could type it as a generic struct. nice!
Actually, I'm not sure you can. It's saying that a type is expected.
Oh yeah, no. where T : struct makes no sense when you can just replace T for struct (unless you have other constraints)
Similarly, where T : class constrains to only classes, ie. by reference objects. If you don't care, just use object instead of T (again, unless you have other constraints)
Both generics and extensions methods are tools that... well, they're hammers hungry for nails, so to speak.
It's not liking this π¦ Throws an error for struct saying "Type expected."
public static NativeList<struct> SubsetGetByIndexes(this NativeList<struct> list, NativeList<int> indexList)
Hmm, that's NativeList complaining, I believe
I think you'll have to choose between bursting that code or the generic
booo π
Tried using it with List just to see what would happen and it's the same π¦
Burst or generic... hmmmmm, tough choice!
if I had any value from the generic, i'd go for that in a heartbeat, unless I specifically needed the extra perf.
could see the performance gain between the two... kinda hit or miss without jobs in my experience (and my poor coding :P)
Interesting point, guess I was assuming it'd be better by default hah. Well, fingers crossed.
Beware of premature optimization.
Which here means making worse code (harder to understand, maintain, extend, against best practice, or similar) for performance you don't need (ie. have nood profiled to see that you specifically need. Always profile first)
saw this on the forums: https://github.com/JonasDeM/EntitySelection
it's also for older ECS
especially when the API is technically still up in the air
but still cool that someone did that
ooh. nice! it'd be fun if stuff like that was even on unity's radar...
@verbal pewter well thats part of the issue with DOTS. it's touted as the savior of everything right now... so everyone assumes it'll be better at everything. It's actually just REALLY good at specific things built for it, then it's usefulness goes down from there. it's a problem a lot of people have with the "magic keywords" stuff like burst end's up being.
DOTS is great at the stuff that is typically demoed - A lot of stuff doing something relatively simple (Boids being slightly beyond that - and it shows if you try to understand the code).
@verbal pewter interesting video from over-watch about shared behavior / utility functions. https://youtu.be/W3aieHjyNvw?t=903
In this 2017 GDC session, Blizzard's Timothy Ford explains how Overwatch uses the Entity Component System (ECS) architecture to create a rich variety of layered gameplay.
Register for GDC: https://ubm.io/2yWXW38
Join the GDC mailing list: http://www.gdconf.com/subscribe
Fo...
@mint iron Thanks, will check it out.
@winter veldt Yeah, fair point. I'm still at the start of my project so the decision was to either build it in the standard way or refactor what I had to DOTS and continue development that way. Would've been nice to be able to do a side by side comparison of the speed, but that would've been doubling the work. I already know the code I'm working on needs to be as performant as possible, so going the DOTS route would still theoretically be the way to go. Or would it? Too late now, but I'm curious if there have been cases of DOTS being slower than the standard approach. If not, then I still think I made the right call.
@tawdry tree I haven't gotten there yet, but there are definitely parts of the program that'll make use of jobs in that way. Looking forward to seeing what it can do!
@verbal pewter You should really read up on generics if you're going to be writing generic functions.
public static NativeList<struct> SubsetGetByIndexes(this NativeList<struct> list, NativeList<int> indexList) It doesn't make sense to use struct as a generic parameter.
That was suggested by someone else to try. Didn't work, bummer.
If you're familiar with generics it is very clear why. Read up on it.
Putting it simply: "struct" is not a type, so it doesn't work for a type parameter (the part of the generic in <>)
When using the HDRP, what is the preferred way of creating meshes with ECS? Earlier Ive used the hybrid renderer "RenderMesh" class etc. but Im not sure how this interacts with the HDRP or if its even still a thing since the DOTS stuff deprecates sort of quickly
rendermesh is just a sharedcomponentdata that has a mesh and material and some other things. its equivalent to a meshrenderer and very much not deprecated. its definitely what you use to render an entity, regardless of the pipeline
I need the Hybrid Renderer to render the rendermeshes though right? or is that not the case
The hybrid renderer works by iterating over entities with rendermesh and position components, yes
imo hybridrenderer should be renamed dots or entities renderer or something, seems to cause a little confusion with the hybrid part
I was reading this thread which confused me a bit but what I gather is that the hybrid renderer should work fine side by side with HDRP
Yes, it works fine wherever. It's slow as hell compared to almost any other option unless you have your scenes set up in the exact right way.
But it does work.
I could just make a system and call Graphics.DrawMesh I suppose
And in that thread I certainly wasn't implying that it's going to be deprecated, it just hasn't been updated in a long time. I've seen a couple of posts from Unity people saying that it's being actively worked on and a big update is coming....at some point.
Yea I see, Ive worked with ECS before so I was just referring to deprecation in general. Ive had to relearn stuff a few times and now again I think depending on how they are doing the iteration
archetypes chunks or whatever it is now
Well Unity has been pretty clear that Hybrid Renderer is here to stay
So no worries about it being deprecated
I find it a bit frustrating that the samples seem to do all kinds of conversion, I just want to write pure ECS I dont have any need for game objects atm but I cant find a sample that does that
The idea moving forward is that you used gameobjects/prefabs/editors to represent everything at edit time. When you press play everything gets converted to entities and at that point it is "pure" ecs
Despite the name Hybrid renderer is in fact as "pure" ECS once you hit the play button
Oh okay, so it is in fact the "future" that you are meant to do the conversion. That explains a lot then.. Still for my purpose since Im going to do a lot of runtime generation of meshes etc. so I need to generate these from code either way
Very much so yes. And speaking from experience you will not want to use the hybrid renderer for anything procedural right now
I see, Graphics.DrawMesh it is, maybe instanced if I can be bothered :p
Thanks for the help π
@zenith wyvern are you by chance using ecs with urp?
I am yeah. I don't think I'm really utilizing any URP specific features though
To be honest I will probably be porting to Project Tiny once it has better support for procedural meshes
do hierachies give you problems with rendering?
I don't really have hierarchies atm, most of my stuff has been basic test cases so I haven't really needed to get that far. What problem are you having?
just scale going kinda bonkers in a simple child parent conversion. i know urp isnt their target and people have had other issues with it, but its still kinda disappointing
Ahh okay, sorry I haven't messed with the transform system hardly at all. You could always poke at the Transform conversion systems to see what might be going wrong
oh its static tickbox causing issues
does the same thing in hdrp, wonder what happens
How do you guys handle global settings? If I use a Monobehaviour so I can throw in materials etc. in the editor I would have to make it a singleton or something since Id need an object reference to access them, but the settings cant be constant since then they cant be accessed by ComponentSystems etc
ScriptableObject with Resources.Load or Addressables
Yea okay, so no drag and drop, but it might be the way to go
I just have a few components converted into the scene (managed components for mesh/material references, structs for simple values)
then access them via GetSingleton<SomeSettings>()
I wrote a converter, that converts scriptable objects to blobs, and I use that for my global settings now that only the ECS worlds will touch
and just apply blob refs to singleton components
So, I have a bunch of entities rendering via the hybrid renderer - how can I assign per-entity shader properties - color, texture, etc? Is there an example somewhere that does this elegantly? Or do I just loop through each entity on the main thread and set material properties there?
heres a thread on it - not sure if urp is supported yet https://forum.unity.com/threads/per-instance-material-params-support-in-entities-0-2.782207/
thanks!
last comment was that DOTS team is focusing with HDRP support till next summer at least
so, I wouldn't expect huge amount of URP support but I'd expect some patching to make it compatible
Yeah, was about to say 'focus on HDRP' doesn't mean they won't do anything for URP, just that their effort won't be focused there. (less stable, less features)
i have a small problem, is there any way to bypass it?
I'm trying to edit nativearray while job reads it. It's set as [ReadOnly] in job. Can i somehow force the edit, or i have to wait for the job to finish and then edit it? (i.e. enqueue the edition)
NativeDisableParallelForRestriction if you want to write to disable the write restriction
thanks! i'll read about usage of it!
nope @safe lintel
InvalidOperationException: The previously scheduled job Chunk:Job_RenderChunk reads from the NativeArray Job_RenderChunk.blocks_CurX_PluY_CurZ. You must call JobHandle.Complete() on the job Chunk:Job_RenderChunk, before you can write to the NativeArray safely.
Unity is again looking feedback on DOTS, now to evaluate new sample projects: https://forum.unity.com/threads/user-research-looking-for-developers-for-60-minute-remote-interviews.807183/
@sonic oyster The error message is telling you the problem. You're trying to write to the array before a previous job that uses the array has completed. If you can't figure out that error you need to take a step back and learn more about how job dependencies work
Sorry but I'm not sure what you mean by "bypass" it
yeah.. bypassing it would be.. not editing it in a job..
Then you need to tell whatever you're passing it to that you're accessing it as read only
Or call complete on the last job that reads from it.
Or pass in the last job that reads from it as a dependency on the job that writes to it.
Like the error message was telling you.
[ReadOnly] on a variable in a job marks it as read only
Or WithReadOnly() if working with entities.ForEach π
huh
this was a really weird full version number bump:
## [DOTS Editor 0.2.0] - 2020-01-14
* Updated package dependencies```
one would think they could have just done that on 0.1.1
btw, 2020.1 package manager gives nicer dependency list now:
you can now also see which things are using the selected package
(instead of only listing packages it depends on)
is being used by looks very useful
the only thing I dislike is if you install the top level 'entities' package kinda like a meta package it only puts that package in your manifest
I had a problem on a new 2020 project trying to get all my packages to a proper version and couldn't manually update collections because it was using the one entities said to use
Anyone else encountering this exception in their DOTS code?
System.ArgumentException : All entities created using EntityCommandBuffer.CreateEntity must be realized via playback(). One of the entities is still deferred (Index: -1).
I'm only creating ECBs from EndInitializationEntityCommandBufferSystem in this isolated test
so I don't understand how this is possible
hm
Invalid Entity version: 0
EntityCommandBuffer was recorded in Server.Game.Systems.ServerStateMachine and played back in Unity.Entities.EndInitializationEntityCommandBufferSystem.
So my ECB is getting played back, but the entity version is 0?
weird
ah, I figured it out
I was storing the entity as a reference in my singleton component, the entity created via ECB (so it's just stored as (-1, 0)
I had to set it in a query next frame to get the real entity
rather than continue to use the (-1, 0) ECB created version
makes sense
I noticed though, that running unit tests against Netcode, I often get an exception where I need to update OnDestroy() on RpcSystem to do m_ReceiveSystem.LastDriverWriter.Complete(); before m_RpcTypeHashToIndex.Dispose(); is called, because there's a job dependency there requireing the Complete() before Dispose()
Is there a way to GetPrimaryEntity() from outside of a IConvertGameObjectToEntity ? I'm trying to instantiate some entities i've loaded from file and i'd like to convert my referenced prefab in an entity like in the Spawner of unity Samples but in the oppposite way. I've tried to recreate an GameObjectConversionsystem on the fly with World.GetorcreateSystem and getprimaryEntity on it but we can't create this system like this (it return an error) .
Well, GetPrimaryEntity is a concept of the GameObjectConversionMappingSystem
public Entity GetPrimaryEntity(UnityObject uobject)
internally it maps between the instance id of the gameobject to an entity
it uses ConversionJournalData to store those mappings
public bool TryGetPrimaryEntity(int objectInstanceId, out Entity entity)
If you already have entities though, isn't Blob what you're looking for?
I use a Spawner which convert gameobject to entities then instantiate them with some Data, i save some Data on a file, reload these Data and i would like to instantiate the prefab and set component on it from those loaded data. So no i don't have these entities i'm trying to instantiate them
right, I have no good answers there, so please share if you find any solution π
Ho really ? i was trying to use the GameObjectConversionUtility with ConvertGameObjectHierarchy and looking for what a BlobAssetStore is since it's needed to create a GameObjectConversionSetting
the conversion stuff is really only meant to allow you to create things in the editor, and have them converted to entities when you hit play. i don't think its meant to be used in any other context really.
i believe the conversion stuff is literally created in it's own world and referenced once then deleted, that's why DefaultGameObjectInjectionWorld is a thing i think
I was trying to rebuild the FPS sample and using it to learn more of ECS & DOTS. However when moving to newer versions of Entities I have more peformance problems.
In the older version they use this:
var entityArray = Group.GetEntityArray();
var dataArray1 = Group.GetComponentDataArray<T1>();
var dataArray2 = Group.GetComponentDataArray<T2>();
var dataArray3 = Group.GetComponentDataArray<T3>();
var dataArray4 = Group.GetComponentDataArray<T4>();
var dataArray5 = Group.GetComponentDataArray<T5>();
But in the new one I would have to use 'ToComponentDataArray' (https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/component_group.html), this one requires me to give a alloc type. But this seems to kill my peformance more drastically.
Am i replacing the 'GetComponentDataArray' with the wrong thing?
@azure nacelle you mean the old fps sample for Unity 2018?
or the new dots shooter sample that was just released a while ago?
oh right the new thing is 3rd person.. so I guess you meant the old one
I ported most of the fps sample to 2019.1 a long time ago, but that change wasn't there yet: https://github.com/0lento/FPSSample/tree/2019.1-update
I'm being really dumb... been exiled to shader land and am just returning to systems so it's probably just that.
I have jobs where I set eg a NativeArray to a public job variable and that's written to within the job, then readable after completion of the job. For some reason I'm not getting an int out of a job the same way and I'm sure it's just me being dumb about it but I'm stumped
I suppose I could just add another component to do it that way thinking about it.
k nm I was being dumb ^^ π
If I understand you correctly @wary anchor I think the usual way is to use e.g. a NativeArray with a single element. I believe there's an intention to make it a bit easier to get return values out from jobs via the foreach syntax at some point in the future.
yeah I found that, thanks @amber flicker
@dull copper sorry notification didnt pop up for me. But yeah i mean the old one, had some peformance issues with it in the new version.
I didn't know the new one was made public yet, that's huge fpr me too, thanks!
@azure nacelle more about it here https://forum.unity.com/threads/dots-sample.796308/
Im sorry to bother everyone. I wonder how I would pass a readonly reference to systems for a bounding box struct.
I need to check if an entity is outside said bounding box
Hmm how is it set up?
I imagine you would likely compile the job without burst and run instead of schedule since you have a reference type - but that's me thinking out loud π€
Entities.WithAll<...>().ForEach((some-args) => {
// Some logic here with the reference type
}).WithoutBurst().Run();
Could I add the reference as a component to each entity?
I think ISharedComponentData will work
you can store reference types in components now, if you use AddComponentObject, probably a better option than sharedcomponentdata
oh nice, thank you!
Anyone know of some performance benchmarks of the unity hybrid renderer? Last night in a secondary project I was testing out terrain generation just spawning lots of cubes (with instanced material (9000->300 batches) and it was still abysmally slow
Something like 200ms just traversing them in presentation system. Only 1ms to actually render
I did testing way back and don't remember it being this slow
Thats uh 700k cubes
I wonder if a custom Graphics.DrawInstanced would be sane
@dull copper you're a champ, thanks!
I was just thinking about static/frozen tags. thanks you for confirming @digital scarab
does much better but I cant quite structure the whole frozen scene batches data. guess I'll have to wait for that update. we talking 1 or 3months+ on it?
Had the same problem, my dynamically spawned environment took 20-40ms to render with RenderMeshSystemV2.
Ended up writing two simple systems:
- ChunkSystem: Creates chunks and sets visibility according to player distance: Culled, Billboard , LOD
- RenderSystem: Does culling/LOD selection based on player distance and view angle. Renders with Graphics.DrawMeshInstanced
-> 1-4ms instead of 20-40ms
dang alright
There is no link to any page?
docs arent updated yet, its just in the package manager
https://docs.unity3d.com/Packages/com.unity.entities@0.5/changelog/CHANGELOG.html
they sometimes lag behind by a few hours
I got the changelog from the .exe file in the downloaded package
## [Entities 0.5.0] - 2020-01-16
### Added
* Added AndroidHybrid.buildpipeline with RunStepAndroid
* EntityManager.MoveEntitiesFrom now has the full method overload combination of output, filter, remapping parameters.
### Changed
* `Entities.WithReadOnly`, `Entities.WithNativeDisableParallelForRestriction`, `Entities.WithDeallocateOnJobCompletion`, `Entities.WithNativeDisableSafetyRestriction` and `Entities.WithNativeDisableUnsafePtrRestriction` now check their argument types for the proper attributes (`[NativeContainer]`, `[NativeContainerSupportsDeallocateOnJobCompletion]`) at compile time and throw an error when used on a field of a user defined type.
* Log entries emitted during subscene conversion without a context object are now displayed in the subscene inspector instead of discarded
### Deprecated
* Adding removal dates to the API that have been deprecated but did not have the date set.
* `BlobAssetReference<T>`: `Release()` was deprecated, use `Dispose()` instead.
### Removed
* `EntityQuery.cs`: Removed expired API `CalculateLength()`, `SetFilter()` and `SetFilterChanged()`.
### Fixed
...```
fixed list was tad long
cheers @dull copper
## [Collections 0.5.0] - 2020-01-16
### Added
* Added `UnsafeRingQueue<T>` providing fixed-size circular buffer functionality.
* Added missing `IDisposable` constraint to `UnsafeList` and `UnsafeBitArray`.
* Added `ReadNextArray<T>` to access a raw array (pointer and length) from an `UnsafeAppendBuffer.Reader`.
* Added FixedString types, guaranteed binary-layout identical to NativeString types, which they are intended to replace.
* Added `FixedList<T>` generic self-contained List struct
* Added `BitArray.SetBits` with arbitrary ulong value.
* Added `BitArray.GetBits` to retrieve bits as ulong value.
### Changed
* Changed `UnsafeBitArray` memory initialization option default to `NativeArrayOptions.ClearMemory`.
* Changed `FixedList` structs to pad to natural alignment of item held in list
### Deprecated
* `BlobAssetComputationContext.AssociateBlobAssetWithGameObject(int, GameObject)` replaced by its `UnityEngine.Object` counterpart `BlobAssetComputationContext.AssociateBlobAssetWithUnityObject(int, UnityEngine.Object)` to allow association of BlobAsset with any kind of `UnityEngine.Object` derived types.
* Adding removal dates to the API that have been deprecated but did not have the date set.
### Removed
* Removed `IEquatable` constraint from `UnsafeList<T>`.
### Fixed
* Fixed `BitArray.SetBits`.```
π€
no update for DOTS samples
I didnt check the other packages, was there anything new in hybrid rendering for example?
Anybody knows if the hybrid renderer works with HDRP? I tried some time ago and it wasn't working. Also, can you use lightmapping with it?
Hybrid Renderer works with HDRP
but limited features right now I believe? Don't think lightmapping is supported yet but I could well be wrong.
Ok thanks, I guess I'll try it again then. But if it doesn't support lightmapping it limits my use cases a lot.
it's very bare bones.. and doesn't perform well either... generally would recommend sticking to traditional rendering for now
*unless you have mostly static renderers
(in subscenes)
wow
@winter veldt You were right, too much chunk fragmentation hurts performance
I removed most ISharedComponentData for that reason
haha ok. i posted because it looked like that was the last message to me. hit enter and pages of msgs appeared magically.. so i thought i might as well delete it π
In my RenderSystem i got a huge performance increase by just removing all ISCD. Having too many chunks with only a few entities are a bad idea π
yeah, took a bit of learning to get the concept of chunks. there's the way you want it to work to make it easy for you.. and the way it actually works
I'm hoping the later version of rendermesh will support either mode? Maybe doing something fancy with auto-evaluating if there are many instances of the same mesh or something?
Hello guys. One simple question. What is the current state of DOTS on webGL builds? I created a simple project of creating 30K spheres from code with basic physics (needed for raytracing) and I have great performance in editor. however in webgl build nothing gets rendered
This is done by using RenderMesh @amber flicker. There is one chunk for each Mesh + Material combination.
I'm saying.. in the future perhaps RenderMesh could be an ICD instead of ISCD dynamically?
Maybe once there are material and mesh components?
@gusty comet i really don't know, if you have the hybrid render package added.. then it must not be supported yet
hybrid renderer is not supported yet in WebGL?
I couldnt find any solid answers on the web
not sure. i just know a lot of people don't add hybrid renderer and then see no rendering of entities. if you've done that, then it must not be working with webGL. i don't use it, just didn't want you to get radio silence and think you were being ignored
thank you for your answer. I was prepered for radio silence when asking non-popular things on experimental features though π
tha thing is that i wanted to achive better performance than DrawMeshInstanced + collider gameobjects for raycasting
on webgl however that do not support compute shaders for now
RenderMesh is currently horribly slow for anything that isn't set up exactly like Megacity, you shouldn't expect it to give better performance in most cases
Not sure about webgl support though, I haven't tried it
Your best bet is probably to stick with normal mesh renderers for now
You can improve performance a lot by combining meshes if possible or making use of batching
I know but thats not enough, thank you though
combining spheres into a bigger one is one thing i try to implement right now
@flat talon there werent any changes to other packages
they only updated the dependencies
@gusty comet as a general rule, don't expect any new features to be supported for WebGL. Best case scenario --latest Chrome on desktop computer, it's based on a version of OpenGL ES from 2012 (WebGL 2.0), or for many browsers it's based on OpenGL ES from 2007! (WebGL 1.0) the year the iPhone was released. Nor is this a problem specific to Unity, it's a WebGL / W3C / Web standards problem.
The good news is WebGPU is poised to become the modern graphics API for the web to succeed WebGL, with compute shader support, command buffers, HLSL based shader language, lower level abstractions, etc
I would be curious as to what would be the downside of using FixedList
Like everywhere
One I could see at the moment would be the size of the IComponentData struct which should be small
i dont quite understand, is it a list with a max size of whatever the type is(32,64,128 etc)?
From what I'm reading, I would assume so
Basically a nice wrapper around an unsafe byte array
ah ok
huh thought it arrived in 0.5
Not having to create IBufferElement thingies for simple usecases is nice
Yeah I've missed that update in 0.4
is there a vector3/float3 like type that fits into it? brief test shows neither of those work
They bumped Burst to stable on 1.2:
## [Burst 1.2.0] - 2020-01-15
- Update to stable version.```
Anyone else struggling with compile times switching to jcs entities foreach? Mine are getting insane (I am generating hundreds of systems tbf but anywhere from 30s to a few minutes - only 4s of which assembly reload time).
jcs?
JobComponentSystem
ah, I didn't know π
sorry π
Any thoughts on how to randomly instantiate an object from a list of objects using ECS?
i did feel like it increased but i dont have anywhere near the number of systems that you have
how and why are you generating hundreds of systems?
Well, more like hundreds of jobs in many systems. It's a Tween library - every property tweened requires multiple systems. Code is generated for each user-required Component (MB or ICD). I believed it should have in theory been the most performant (majority of systems would never run) and given the reduction in code, I thought foreach was the way to go. However in a lot of instances I had to duplicate a job rather than switch on the presence of a tag like I can with IJobChunk. In theory, the lib will rarely need to be recompiled so wondering whether to stick with it or go back to how I had it before with IJobChunk's written out in full, less jobs but more switching per chunk.
The most frustrating part is that nothing seems to be cached - everything's compiled from scratch each time.
sounds kinda exhausting to keep track of π
Easy compared to the rest π - been working on it for a year so far π
I think the caching issues should be improved either in 2019.3 or 2020.1
not exactly sure when that's supposed to land
ah thank you - I'm on 2019.3.0f5 so may give 2020 a go
regular dots works just fine on current a19
HDRP is still special case there but if you don't use it, then that's not an issue
It looks like the Rotation component in ECS is localRotation?
How do I convert it to worldspace rotation
I have a LocalToWorld component
I read this:
For an entity without a parent you can set the rotation to the world rotation and then you need to recalculate the LocalToWorld matrix. This can be done by creating a new float4x4 matrix from the Translation and Rotation values.
But, I have no idea where to go from here
My rotation code is:
rotation.Value = Quaternion.LookRotation(float3.zero-translation.Value, localToWorld.Up);
Which of course doesn't work π
if you want world space rotation - I think you should just get it from the LTW matrix
I think there's a property which allows you to grab said quaternion value in the LTW matrix (I forget what's it's called - it might be like localToWorld.Rotation)
as for setting a rotation - I typically update it in the LTW matrix π€ (honestly not sure if that's recommended if the Rotation component gets copied to the LTW matrix)
new quaternion(localToWorld.Value)
Thanks @digital scarab - ok to dm?
hm, I get this now after updating to entities 0.5:
InvalidOperationException: Trying to get iterator for Unity.NetCode.NetworkStreamConnection but the required component type was not declared in the EntityQuery.
For this code:
var connectionSingleton = GetSingleton<NetworkStreamConnection>();
HasSingleton<NetworkStreamConnection>() works as expected
If I set up a manual query, it works.
var connectionSingleton = _networkStreamConnectionQuery.GetSingleton<NetworkStreamConnection>();
Entities .5?? @remote coyote
At least GetSingleton isn't generally broken. I just updated my (networked) game and it still works π After reading your issue i got some fears @remote coyote
@remote coyote
public T GetSingleton<T>()
where T : struct, IComponentData
{
var type = ComponentType.ReadOnly<T>();
var query = GetSingletonEntityQueryInternal(type);
return query.GetSingleton<T>();
}
No docs yet :( (more accurately no changelog on unity's latest page)
internal EntityQuery GetSingletonEntityQueryInternal(ComponentType type)
{
for (var i = 0; i != m_EntityQueries.Length; i++)
{
var queryData = m_EntityQueries[i]._QueryData;
// EntityQueries are constructed including the Entity ID
if (2 != queryData->RequiredComponentsCount)
continue;
if (queryData->RequiredComponents[i + 1] != type)
continue;
return m_EntityQueries[i];
}
var query = EntityManager.CreateEntityQuery(&type, 1);
AddReaderWriters(query);
AfterQueryCreated(query);
return query;
}
@remote coyote Looks like it should solve itself. It's weird.
Yes Jaws, I didn't understand why it wouldn't. It worked previous to the 0.5 update. But my workaround works so, I'm good for the minute.
Its GetIndexInEntityQuery that actually throws that exception, but I don't have time to look more into it atm.
Question about disposing NativeContainers. I have a NativeList<MyStruct> extension method Filter that returns a NativeList<MyStruct> with a subset of the original list's values. It would be called using: myNativeList = myNativeList.Filter(filterValue). Do I need to dispose the original list within the Filter method, or does overwriting the value to the same variable handle this?
Though I guess there are situations where I wouldn't want to dispose the original list, such as:
var allValues = new NativeList() { value1, value2, value3 };
var filteredValues = allValues.Filter(filterValue);
So putting it in the Filter method doesn't seem like a good idea anyway. Hmmmmm.
@coarse turtle @safe lintel thank you so much!
annnndd now I guess I need to know how to update localToWorld.Value
gosh this is a little confusing π
what is the best source of documentation on the topic of ECS rotations?
I typically use that to update LocalToWorld's rotation value (create 3 rotation matrices for the x,y, z axis and multiply it to the localToWorld.Value float4x4)
I typically update localToWorld.Value
Also, thank you for posting a link to the math, that is really really helpful
great! I shall try this tonight
once again, thank you so much for your help
I remember digging into the source code and there should be a system like LocalToWorldTRSSystem or something like that - which should build the LocalToWorld matrix so you can probably dig through its source code too
Fantastic
i might write a little article on this, it is very interesting
and hopefully I can save somebody some time in the future
in the entities docs theres a big section on how the transform system works
You can also use https://docs.unity3d.com/Packages/com.unity.mathematics@1.0/api/Unity.Mathematics.float4x4.html#Unity_Mathematics_float4x4_TRS_Unity_Mathematics_float3_Unity_Mathematics_quaternion_Unity_Mathematics_float3_ as an easy way to assign back transform changes
Hello here, does anyone know how Unity decides the number of worker to spin according the CPU? I am having some weird results. For example I have 6 workers on I7 which is fine, 3 on I3 which is fine, but still 3 on I5 why?
might be a lot of components that could spare you modifying the ltw @gusty comet
oh cool @safe lintel https://docs.unity3d.com/Packages/com.unity.entities@0.4/manual/transform_system.html
Wish I saw this earlier π
Every time i see the graphs in that link my head hurts
So I suppose animation is still not supported in ECS?
Like switching run animation to idle etc
No idea about it of its current state + ECS
Very primitive vertex animation with no support of blending
Thanks folks!
is there a way to use Entities.ForEach in a ComponentSystem to access GO components?
I'm trying to do hybrid ECS where I attach the "Convert to Entity" script to my GO and set it to "Convert And Inject Game Object", essentially so I can use Systems to drive the components' behavior
for the animation you don't really need to wait for the UnityECS support, you can use this too: https://assetstore.unity.com/packages/tools/animation/gpu-instancer-crowd-animations-145114?_ga=2.39530667.927516563.1579262831-1609202245.1579262831 .It's data oriented and use compute shaders to do the animation. We use GPUINstancer in place of UnityECS rendering already. (although I guess a proper ECS support would make things simpler)
@glass tiger Entities.ForEach((GameObject go) => {});
Look at the EntityBuilderQueryDesc struct for the order of args if you want to do like gameObject, icomponentdata in a query processor
thanky @coarse turtle
Hi guys!
Is there a way to check if an entity is already modified in an EntityCommandBuffer?
(I mean... if an entity is already added to the internal " nativeArray" that the ECB uses.)
why do all entities and worlds get removed whenever I make changes to a script during play mode?
is it a configuration thing or does it happen for everyone?
Is it possible to remove safety checks when doing something like this? Obviously, the 2 jobs would never touch the same entities
var job1 = Entities
.WithNone<CompX>()
.ForEach((ref Translation pos) => {...}).Schedule(deps);
var job2 = Entities
.ForEach((ref Translation pos, in CompX x) => {...}).Schedule(deps);
Oh wow! thank you! @safe lintel @zenith wyvern @coarse turtle
does ECB still can't work with burst?
@frosty siren I figured it out today you have to update burst manually to latest in the selection
@mystic mountain thx for clarification
@everyone
Has anyone here managed to get a dots build running in the browser/WebGL? Is this actually supported? It seems like the EntityCommandBuffer is leaking memory, works fine in a windows standalone. Confirmed bug from unity, but I haven't seen other people complain about this, so I'm wondering, am I the only one here looking to get a dots browser build working? How is nobody else blocked by this/complaining about this being completely broken in 2019.2 and upwards?
I haven't touch webgl - i'm mainly on mobile atm π€
I will be switching to focus on browser at some point but I'm just going to use project tiny once it gets a bit further since it's being built with dots from the ground up for a browser.
I will be switching to focus on browser at some point but I'm just going to use project tiny once it gets a bit further since it's being built with dots from the ground up for a browser.
@zenith wyvern I think it will be a very long time until Tiny catches up to the full unity runtime. I think unless build size is a strong desire, going the Hybrid approach is probably the best. It's just that the damned thing doesn't work in browser it seems.
@coarse turtle Well if you plan to eventually, best you take a look and let Unity know of any issues you encounter soon enough that they're fixed by the time you actually plan on doing the move.
Seems like maybe I'm one of the first to look at dots on webgl? Just tried an android build just now and that one worked fine, interestingly.
My current project is very small scale so Tiny should be a good fit for me when it gets a bit further, but yeah it's definitely not appropriate if you need most features of the engine
Aside from the leak bug you could use an alternative solution for rendering and still utilize dots/ecs for the rest. But unless I'm mistaken threading doesnt work at all on webgl right?
If I remember right any job scheduling code just gets forced into main thread in webgl
@zenith wyvern I think threading works now, not sure. But the dots bug isn't rendering related, it's more basic than that, the ECB has a memory leak. ECB has nothing to do with rendering.
i build it with threading enabled, it works for a while but then runs out of memory. But the same issue happens with threading disabled, so Im pretty sure it isn't caused by threading
Oh sorry for some reason I thought you said there was a rendering issue, my mistake. According to https://docs.unity3d.com/Manual/webgl-gettingstarted.html?_ga=2.211098077.991780498.1579302510-1893865380.1480951604 threading does not work in webgl. And yeah I understand the problem isn't threading related, my point was you lose a big benefit us using dots in webgl, so it might explain why it hasn't been a big focus for people
@alpine sphinx @zenith wyvern that doc linked above mentions only Javascript not allowing for threading, but Webassembly / Wasm will allow for threading Though there are have been some significant challenges in making that a reality, some of them have been out of unity's control such as browser support for it, but it will happen sooner or later.
https://blogs.unity3d.com/2018/08/15/webassembly-is-here
Scroll down to the "Multi-threading" section of this blog post for an official word from Unity about it in 2018. Not sure how far long it has come since then, though.
another point i mentioned yesterday on the topic of @gusty comet asking about WebGL support for the DOTS Hybrid renderer is even though DOTS + Wasm + WebGL is technically possible, it makes very little sense to invest in a API such as WebGL that has been completely stagnant for nearly a decade. So it's more likely that DOTS + Wasm + WebGPU is the target we will be working with in the coming years.
I guess I misspoke, I meant WASM build
In fact you can download Chrome canary today on Windows or macOS and start developing with an early draft of WebGPU with compute shader, SPIR-V, GLSL, HLSL support, reduced CPU overhead for draw calls etc.
i just have a wasm build with dots hybrid, it crashes, and i'm extremely surprised how nobody complains about this
@alpine sphinx once the draft is complete and browser support is widely adopted (Google, Mozilla, Apple all are on board) then it makes sense for Unity to get heavy into DOTS with Wasm threading support + WebGPU
it doesn't make a lot of business sense for them to do that now with Wasm + WebGL when that will very soon be deprecated
double work
@inland root well right now nobody can deploy dots in the browser, so it does make business sense to fix some basic bugs
@alpine sphinx by all means I wish it worked now and the more bug reports the better. But DOTS isn't even production ready yet, it's still a futures project. It makes sense for them to target modern APIs, not a soon to be sunsetted APIs I feel your pain and I push for data oriented design and multi-threading efficiencies at every opportunity. but I have to be realistic on timing and current demand. DOTS is only "needed" by a certain minority of developers and projects that are willing to risk writing production code on WIP subject to change framework + toolchain. The, DOTS on the web is even smaller piece of that pie. So, that's why it seems nobody complains about this.
Not to mention the web standards groups.. the W3C that develops Wasm, and the GPU for the Web Community Group that develops WebGPU. All of these hundreds of companies and organisations that are members of these groups have to deliberate and agree on these standards before any progress can be made on architecture, implementation, etc.. It's a very slow process that Unity and everyone else is beholden to.
We have to be extra vocal about our needs because of this, and it feels like it's constantly an uphill battle. But don't lose hope!
## [DOTS Editor 0.3.0] - 2020-01-17
[Changed]
* Updated package dependencies
[Fixed]
* Fixed multi-selected GameObjects conversion toggle issue
* Fixed inaccurate conversion message
Just wanted to see what people thought of this idea. Generating a simple addition job for each numeric type in Unity. I created enough by hand and got sick of it!
Here's the text template: https://raw.githubusercontent.com/johnsietsma/InfPoints/master/com.infpoints/Runtime/AdditionJob.tt
And another idea I wanted to sanity check. A NativeValue native container that uses Interlocked synchronisation for thread safety. Generate classes in a similar way to above. It just seems nicer then using 1 element NativeArrays for counters, etc. What do you think?
Hm, odd case. I first Get a dynamic buffer, and I have a valid copy of it. I then call CreateEntity with archtype, count and temp job (batch call), when I do this, the buffer no longer is valid and I have to Get it again. Is this intended behavior, I wonder?
I'll set up a reproducible little snippet for this when I have a bit more time.
entity creation invalidates native arrays, it's intended
buffers probably fall under that category too, but in general, i know for a fact it's intended to invalidate nativearray of components you fetched previously, for example
ah, makes sense. That is indeed the exception I got (NativeArray no longer valid)
thank you
Are we aware of the reasoning behind why entity creation invalidates native arrays?
@remote coyote
When you create the entity you are really asking for a chunk with x archtype. so your entity is really x memory location within that chunk (bit more than that but keep it simple). When you add the buffer, or do anything to change the archtype, it will move that data to the chunk that matches it. This invalidates the buffer pointer stored inside the buffer struct.
Dynamic buffers if small enough, can be stored within the chunk as a wide/fat component just like the rest, so that linear processing can keep them more cache coherent (not have to fetch external memory if your lucky). Thats what the [Internal something(100)] attribute is for.
So when your getting it again you are saying, lookup this entity, find the current chunk and return the
buffer within the chunk or external buffer location elsewhere.
Theres also another tricky situation as well, with EntityCommandBuffers. What they are is a basically a native list of bytes, that you slowly fill up with operations. When you add a dynamic buffer to one, you are basically asking for a stretchy byte[] casted to your type within the tail of them
I haven't really looked into their internal type much, as they pretty much just work great
I highly suggest when constructing types, you follow a natural order of
CreateEntity(optional:archtype)
Add/Set Component
...
Add Buffer
Resize Buffer
Memcopy, Add to the buffer
...
Hello, i was trying to learn Entity system and i cloned the samples from https://github.com/Unity-Technologies/EntityComponentSystemSamples but i get the following errors when i press play button, i see that many ECS related packages updated recently, i was wondering if it was something about that or something else
http://prntscr.com/qpezlz
Last 2 errors just simply repeats
"Burst failed to compile the function pointer" error basically means you have the 1.1 ish Stable version of burst install
you should go into the package manager and select show more versions on it, and update it to the newest
i have 1.2.0 on Burst
unitys loading hold up
hm, yeah thats correct
forgot they brought stable up to match
last few times I got that error, it was that
oh, what version of unity?
2019.3.0f5
Have you tried restarting Unity? I don't know if it's still like that, but has had issues where you needed to restat Unity or you'd get package-related issues
well I'm kinda stumped on that one and need to start work.
I'd suggest double checking all packages are up to date then restarting unity to get a domain reload
alright i will try that
this
new CollisionFilter
{
BelongsTo = 1u << 1,
CollidesWith = 1u << 0
}
should do the same thing as this, right?
if it is the same, i'm having trouble with something else π¬
ah just realized that this likely belongs in #βοΈβphysics .... whoops
figured it out. turns out i had the parent object rotated, which caused the child to be rotated as well, which didn't let it collide with anything π€¦
ah, glad you got it. your bit shifts are correct on the filter as well
thanks for the confirmation on that!
1u = unsigned int32, value of one aka:0...01 in binary, << bitshift to the Left, 0 or 1
for the non zero one simply moves 0...01 to 0...10 giving you a value of 2
double thanks for the explanation. im new to the whole bit math stuff π
Has anyone managed to get a browser wasm build working with dots? hybrid, not tiny, i know tiny works. EntityCommandBuffer seems broken in wasm
@low tangle thank you for the breakdown. Makes a lot of sense
if i instantiate an entity from an entity prefab all SystemStateComponentDatas are not copied with the entity. Is this working as intended? Should SystemStateComponents always added after the entity is spawned?
Sorry to jump in with another question. I was wondering if there are any examples of passing traditional data into ECS? i have an octree that I wrote in C#, and I'd like to be able to query and update it from ECS jobs.
How does one handle locking/blocking
or even.. passing the tree references into ECS jobs and systems
oh cool
(I'm very new to ECS and I'm just guessing)
so initialize it as a component.. and make it a shared component?
thats a good idea, I am really new as well
thanks for sharing your ideas btw
I wonder if unity handles the locking of the data as it is being shared...
I'll go read and see what I can find π
if you use a ComponentSystem, all of those run on the main thread in sequence, but if you use a JobComponentSystem instead those execute in parallel, scheduled automatically according to what their queries declare
oh nice! thank you!
sure thing
I want to make a simple 2d game and am trying to figure out whether to go hybrid or pure ecs
classic UnityEngine components have SpriteRenderer, Rigidbody2D, Animator, maybe some other stuff
but there is also https://github.com/fabriziospadaro/SpriteSheetRenderer and I could use the new physics package and just ignore the z-axis
maybe I'll try to go down the pure ecs route and figure out how hybrid works if I get stuck missing a feature somewhere
Sorry to jump in with another question. I was wondering if there are any examples of passing traditional data into ECS? i have an octree that I wrote in C#, and I'd like to be able to query and update it from ECS jobs.
@gusty comet
You can't use reference types inside jobs. You could try remaking your tree as a NativeContainer
Or build it using entities and dynamic buffers
Uh oh haha. That sounds like a neat puzzle though.
So a dynamic buffer would be a leaf of the tree that you can query
Someone was doing something like that here https://forum.unity.com/threads/wip-octree-in-pure-ecs-bufferarray-based-with-source-code-u2020-1a-entities-0-2.546240/
Would this be the dynamic buffer doc? https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/dynamic_buffers.html
oh wow
Yeah but the latest version is here https://docs.unity3d.com/Packages/com.unity.entities@0.4/manual/dynamic_buffers.html?q=Dynamic Buffers
Unfortunately google still leads to old version docs
Cool, thanks so much. I'll read through these and the example. This should be an exciting challenge π
I would personally recommend trying the NativeContainer approach, it's complicated but seems like the right fit for what's meant to be an entirely self-contained container
And it will let you use your container in jobs like you'd expect
https://github.com/fholm/UnsafeCollections @trail burrow has a repo for native collections if you want an example to learn off of
fantastic, this is great!
Uhh, when you try to pass a reference type to a job it literally says "Job structs may not contain reference types"
Or am I missing something there
@zenith wyvern Can just use a static reference?
And you can just GC PIN it and pass the handle
Works fine
It seems like you're kinda being pedantic there but sure
If you want to bypass the safety system and use unsafe code sure, there's lots of things you can do, that might not be the best place to start for someone just getting into dots
@zenith wyvern you are not bypassing "safety system" by using unsafe context
Not all NativeContainers offer the best performance / burst compatibility
With the same attitude I could say that DOTS is not the place for someone just getting into Data Oriented Design
Writing a nativecontainer forces you to work within the confines of the safety system, throwing exceptions when any jobs tries to access your unmanaged memory without obeying the rules of the safety system. If someone is new to dots, that seems like a good place for them to start so they can understand why those rules exist. Performance should not be your primary concern when you're learning imo.
@zenith wyvern All DOTS ever talks about is performance lol.
it's the #1 reason people use it.
So yes, performance should be considered right away.
Because performance is how you get to clean memory layout and structure
which is what DOTS is all about
Performance is the end goal of dots, not the starting goal (at least it seems that way to me, not trying to speak for Unity). First and foremost they want to expose jobs and ecs in a beginner-friendly way, which by definition requires people to work within the confines of the safety system. Telling a beginner to start working manually with unmanaged memory outside the confines of the safety system seems pretty contrary to what Unity is trying to do.
If someone wants to that they're better off not using jobs at all.
@digital scarab DOD principles is easy
T[]
done.
π
Make everything a very fast O(1) access and O(n) iteration and ur done
@digital scarab Is there an official word on when we'll be able to put collections on components btw?
I know the whole "you really shouldn't do this", etc. arguments ofc. But sometimes its just the best way to solve a problem
Yeah so there will never be any safety features around that?
I mean, like you know, I have my own collections anyway for now
So I will just keep using them
We're also adding fixed size list and hashmap to our stuff, that lives inside a component
how does FixedList work in 0.5?
okey, so same way we wrap them π
[FieldOffset(12)]
private fixed Byte _MyBuffTest_[36];
public FixedArray<AssetRefMyBuff> MyBuffTest {
get {
fixed (byte* p = _MyBuffTest_) { return new FixedArray<AssetRefMyBuff>(p, 4, 9); }
}
}
old code here from last fall, dont have latest code base on laptop i realized
@digital scarab Not the same problem as i was having tho
If i'm in case when one entity must change little data (just one field) of another very rarely, will it be enough for performance to use ECB.SetComponent(targetEntity, data)? How u do it?
(i watched this video https://youtu.be/KuGRkC6wzMY)
yeah looking forward to that
just made a massive terrain system with dots
would love to have floating origin
grr why isnt burst working in the editor
Hi Everyone! I'm trying to store an image in a Component (implements IComponentData) , but I've had not luck with Textures or Sprites as they aren't Blittable. Any thoughts?
if you use AddComponentObject you can have object components, but you wont be able to burst jobify it
hmmm could I store the image path in a string and just load it from a resource when I need it (I'm really only using the image in a GUI Canvas)?
otherwise @safe lintel 's solution sounds good. Thanks!
Hello guys, I'm currently dealing with how to implement input, should I implement different systems for diferent group actions, for example:
Group A) character movement, this system is in charge of processing axis and actions related to the parent entity with the physics body.
Group B) (in my case there's one main attack and will be, probably a second or third attack) should I group them all? Or create a system for each one as they may spawn from different objects?
Or should I group all the input process in the same system and create different jobs inside the system with different Component targets per the input target action?
What do you think would be simpler and more msintenable? And also which one is just more practical.
Thanks in advance for your feedback
Hi, question for someone from unity working on dots, what's the plan with dots hybrid ecs in wasm/browsers? Right now that target doesn't work. I've already sent the bug reports, but when can I expect someone from unity to actually work on that target? Just so i know how to plan my project's timeline. Right now that target seems abandoned...
i still keep a close eye on tiny
@digital scarab thanks, i tried project tiny and it's way too lackluster at the moment. You can actually build webgl dots hybrid players and they almost work, with a few crashes here and there, whoever implemented it implemented the ability to build it for web too in scriptable build pipeline. It's just some crashes here and there.
Since you can do non-ecs builds for web, there's no reason not to support the hybrid web platform. Each of them separately work on the web,
i think its super interesting to have a toolset optimized for web
as normal webgl export was super slow. Instant load is a great selling point
but those of us that care more about having the features rather than the build size, need the hybrid platform. We can't afford to work in tiny because we have to reimplement too many systems from scratch, instead of delivering the game. We simply don't have the budget to do that
it's going to be years until the tools available now in unity will make their way to tiny. hybrid seems like a necessary compromise until then
having hybrid dots is already better than using just monobehaviours on the web simply due to the way dots manages and accesses memory. Even if we just do singlethreaded dots, which monobehaviours already were singlethreaded. And it also allows us to write code that can run on multithreaded dots platforms. My company wants to focus on writing game logic entirely in dots (with just peripherals like UI or input writen with monobehaviours, or any other glue code that we need to interact with third party libraries or the OOP packages in package manager, like Cinemachine). If we don't have hybrid available, targeting web would just force us to use classic unity and write monobehaviours for game logic, duplicating our work, or simply forcing us not to adopt dots, and stick with monobehaviours, even for platforms that do support dots
And another thing, it actually took me less effort to fix the crashes here and there in the entities package when targeting web, than it would take me to write all the missing systems tiny is missing. Hybrid for web seems to be almost there, just needs a bit of love from you guys. If hybrid for web comes with caveats, i'd rather work with those caveats than struggle with tiny's closed, limited set of libraries and doing everything from scratch.
Could you please bring these points up at your meetings, or bring them to whoever has the power to make hybrid for web a reality?
the beauty of DOTS is that it is its own little isolated World, pun intended. There's no reason for it not to work on every conceivable platform, even microwave or smart fridge processors
the thing is my hybrid build runs in the browser in URP for 5 seconds (including animation, shadows etc), then crashes with some memory issue, so it's pretty close to working
I don't even need it to be ready to publish yet, I just need it to not crash miserably so I can keep an eye on this platform, while i develop and debug it on pc
so rendering doesn't even need to be flawless, just need it to render things enough that I can see none of the gameplay is broken in webgl
and when it's ready it's ready, just need to know this platform will be available/worked on, that it will be a thing, and i'm not just backing myself into a corner, a dead end, here, by needlessly hoping hybrid on web will work one day
right, but it would be a great relief if I could know for certain someone's actually looking into this target. Because right now even the builds I manage to make, they only work with release target, they're not even debuggable. I couldn't find any official answer on the forum in the vein "it's safe to hope that you'll eventually be able to use hybrid dots in a wasm browser build, doesn't work right now, but we're working on fixing issues and making this platform work"
Here's the hybrid build, the counter in the top left corner is done in ECS as a test that ecs is running in the browser
well the point would be that people can actually start developing on this platform, even if they can't release on the platform yet due to the renderer
like the way console manufacturers give people devkits ahead of the console release, so they can make their games
Alright, thank you!
isnt the goal of the new tiny (3d) that it will be more compatible with desktop and stuff?
with target not being only webgl, but small scale mobile games
hello, suppose i'm making a system and I want to only query a component X of a specific group of entity, what is the usual way to flag them ? shall i create an empty component assigned to this group of entity that my system will query in addition to the component X ?
or is there a 'cleaner' way ?
@mighty whale you could split them into chunks - although if its a small subset of entities this might be a bad idea (e.g. chunk has component X with a certain condition, while a different chunk does not)
if you're dealing with small subsets of entities you might want to consider tagging entities with component X
well in my case the subset might be of size 1 lol
tagging would be better than splitting them off into their own separate chunks
yeah alright i'll tag them with a component
success! managed to get a hybrid dots build working in the browser with no memory crash. Trick is to avoid EntityCommandBuffer.Concurrent and use EntityCommandBuffer directly inside the jobs, and then force the jobs to Complete() on the main thread
wrote a wrapper to abstract this away depending on platform, and now I can target pc and web with dots hybrid. This was painful, but it's doable, in case anyone else wants to get this working to some degree.
I want to repeat my question as I didn't got any answers yesterday I hope to have better luck today:
Hello guys, I'm currently dealing with how to implement input, should I implement different systems for diferent group actions, for example:
Group A) character movement, this system is in charge of processing axis and actions related to the parent entity with the physics body.
Group B) (in my case there's one main attack and will be, probably a second or third attack) should I group them all? Or create a system for each one as they may spawn from different objects?
Or should I group all the input process in the same system and create different jobs inside the system with different Component targets per the input target action?
What do you think would be simpler and more msintenable? And also which one is just more practical.
Thanks in advance for your feedback
I'd say make one system per attack. Generally I'd ask myself would I need all systems running, or can some systems run while others are disabled? If the answer is yes, then the code is independent and should sit in separate systems for better flexibility. I'd imagine you could create an attack that a player can perform, but also maybe an enemy
but maybe some enemies/characters can't perform some attacks
so having them in separate systems gives you better granularity and would help you decouple the code better, just my 2 cents
@proud cape i would advise listening for the inputs in one system
and putting them in a kind of globally accessible object (be it singleton or whatever) that will be used by all the other systems that relies on input
the main advantage of this is every systems that previously had inputs were forced to live in the main thread and this is will no longer be the case after that
and it will also be much easier to change the way inputs are taken if they are all gathered in a single system
but @alpine sphinx is still right, after storing the inputs in a globaly accessible object, you still have to make modulable systems that can run independently when it makes sense to do so
For example i got a system PlayerInput that does just that
namespace Systems {
public class PlayerInput: ComponentSystem {
protected override void OnUpdate() {
PlayerAction.mouseX = Input.GetAxisRaw("Mouse X");
PlayerAction.mouseY = Input.GetAxisRaw("Mouse Y");
PlayerAction.attack = Input.GetMouseButtonDown(0);
PlayerAction.use = Input.GetMouseButtonDown(1);
PlayerAction.forward = Convert.ToInt32(Input.GetKey(Settings.bindings["forward"]));
PlayerAction.backward = Convert.ToInt32(Input.GetKey(Settings.bindings["backward"]));
PlayerAction.left = Convert.ToInt32(Input.GetKey(Settings.bindings["left"]));
PlayerAction.right = Convert.ToInt32(Input.GetKey(Settings.bindings["right"]));
PlayerAction.jumping = Convert.ToInt32(Input.GetKey(Settings.bindings["jumping"]));
PlayerAction.crouching = Convert.ToInt32(Input.GetKey(Settings.bindings["crouching"]));
}
}
}```
(later on in developement it'll be a bit more complex but its job will remain the same: storing inputs)
and then for example i got another system, PlayerControll, that will use some of the values from here to do its job
namespace Systems {
public class PlayerControl: JobComponentSystem {
private struct PlayerControlJob : IJobForEach<PlayerCamera, Moving> {
public void Execute(ref PlayerCamera playerCamera, ref Moving moving) {
moving.heading = math.normalizesafe(new float3(
PlayerAction.right-PlayerAction.left,
0,
PlayerAction.forward-PlayerAction.backward
), float3.zero);
moving.heading.y = PlayerAction.jumping;
playerCamera.viewRotation += new Vector3(-PlayerAction.mouseY, PlayerAction.mouseX, 0);
playerCamera.viewRotation.x = Mathf.Clamp(playerCamera.viewRotation.x, -89.9f, 89.9f);
moving.lookingAt = math.normalizesafe(
Quaternion.Euler(playerCamera.viewRotation) * new Vector3(0, 0, 1),
Vector3.forward
);
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps) {
PlayerControlJob job = new PlayerControlJob();
return job.Schedule(this, inputDeps);
}
}
}```
So my answer is
- make a system that stores all the input in one globally accessible object
- do multiple systems when it makes sense and call this globally accessible object instead of Input directly
I see, this morning I was thinking about doing it similar to that, since I wanted later to add ECS multiplayer a single system to listen for input then send RpcCommands and individual systems listening for related inputs.
Thank you guys for your feedback will play with the ideas and see what I can get out of it
(also i would advise watching this GDC talk for ECS architecture in games https://www.youtube.com/watch?v=W3aieHjyNvw )
In this 2017 GDC session, Blizzard's Timothy Ford explains how Overwatch uses the Entity Component System (ECS) architecture to create a rich variety of layered gameplay.
Register for GDC: https://ubm.io/2yWXW38
Join the GDC mailing list: http://www.gdconf.com/subscribe
Fo...
input is just data and should be within the ecs world
have a single system the gathers your non ecs data (input.getaxis etc) and put it into a entity with said data. or it can stripe it across all instances of that component type
one step to bridge from outside to inside (entites world), and a single location to update whenever you have to adjust your inputs (often early on, then never later in game dev)
since its also within this single system, you can reason about when exactly in the frame your input is updated.
you can then also disable input by adding a conditional anywhere for any reason and gather and check that data within the same input polling system.
this also helps stick to single responsibility and keeps all of one type of action inside a single small system (kernel) that does one thing in a linear action
for my game, I have two of these systems: desktop, vr
from there up to 20 different systems might access that component produced (CoreInput, VRInput, DesktopInput) I'm currently in the process of updating and fragmenting them more
For whoever else is interested, I finally managed to get DOTS hybrid working in the browser, I've explained more in detail what it takes to do so in this forum post, with a sample project
https://forum.unity.com/threads/dots-hybrid-sample-for-the-wasm-browser-target.812331/
can anyone recommend how best to draw a lot of quads with ECS? I've seen a lot of things like 'draw 4 million cubes' or whatever but the ECS RenderMeshV2 is getting real slow at around 60000 (256 * 256)
Are the materials all GPU instanced?
and what are the batch sizes?
and have you looked at the entity debugger to see where it is running slow?
The materials are instanced and the batch sizes are low. In the entity debugger it's rendermeshv2 and if I keep adding quads it just keeps slowing down
Hybrid Renderer is only good in specific use cases right now, see this thread for details https://forum.unity.com/threads/starting-using-ecs-and-added-4ms-to-my-frame-time.808065/
Short answer is use Graphics.DrawMeshInstanced or DrawMeshInstancedIndirect
Graphics.DrawMeshInstanced performs worse, if anything, Just drawing a 30x30 grid of quads puts my CPU at 60ms
I must be doing something wrong
it also says it's drawing 1.3M tris for ... 900 quads. weird
ah, I was indeed doing something wrong
@last lintel are you using instanced enabled materials?
I was, it was something else, too long to explain haha
np keep coding!
Can I use ragdoll with pure ECS?
I have this system which generates "error DC0035: Entities.WithDeallocateOnJobCompletion is called with an invalid argument entityList of unsupported type Unity.Collections.NativeList`1<Unity.Entities.Entity>. It can only be called with an argument that is marked with [NativeContainerSupportsDeallocateOnJobCompletionAttribute].", looking at examples I don't see what I'm missing.
[UpdateInGroup(typeof(ClientSimulationSystemGroup))]
[UpdateBefore(typeof(GhostSimulationSystemGroup))]
public class ResolveControlledEntitySystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
NativeList<Entity> entityList = new NativeList<Entity>( Allocator.TempJob);
NativeList<int> clientIdList = new NativeList<int>( Allocator.TempJob);
inputDeps = Entities.WithNone<ControllingData>().ForEach((Entity entity, ref ClientIdData clientId) =>
{
entityList.Add(entity);
clientIdList.Add(clientId.ClientID);
}).Schedule(inputDeps);
// Update PlayerState ref to controlledEntity
inputDeps = Entities.ForEach((Entity e, ref ClientIdData clientId, ref ControllingData controllingData) => // TODO Check if we need ControllingData here later
{
int index = clientIdList.IndexOf(clientId.ClientID);
if (index > -1)
controllingData.controlledEntity = entityList[index];
else
controllingData.controlledEntity = Entity.Null;
}).WithDeallocateOnJobCompletion(entityList).WithDeallocateOnJobCompletion(clientIdList).Schedule(inputDeps);
return inputDeps;
}
}
Follow up, how to ScheduleSingle from lambda?
Fixed my issue by using arrays instead
[UpdateInGroup(typeof(ClientSimulationSystemGroup))]
[UpdateBefore(typeof(GhostSimulationSystemGroup))]
public class ResolveControlledEntitySystem : JobComponentSystem
{
private EntityQuery m_group;
protected override void OnCreate()
{
base.OnCreate();
m_group = GetEntityQuery(ComponentType.ReadOnly<ClientIdData>(), ComponentType.Exclude<ControllingData>());
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
int entityCount = m_group.CalculateEntityCount();
NativeArray<Entity> entityArray = new NativeArray<Entity>( entityCount, Allocator.TempJob);
NativeArray<int> clientIdArray = new NativeArray<int>(entityCount, Allocator.TempJob);
inputDeps = Entities.WithNone<ControllingData>().WithStoreEntityQueryInField(ref m_group).ForEach((Entity entity, int entityInQueryIndex, in ClientIdData clientId) =>
{
entityArray[entityInQueryIndex] = entity;
clientIdArray[entityInQueryIndex] = clientId.ClientID;
}).Schedule(inputDeps);
// Update PlayerState ref to controlledEntity
inputDeps = Entities.ForEach((Entity e, int entityInQueryIndex, ref ControllingData controllingData, in ClientIdData clientId) => // TODO Check if we need ControllingData here later
{
int index = NativeArrayExtensions.IndexOf(clientIdArray, clientId.ClientID);
if (index > -1)
controllingData.controlledEntity = entityArray[index];
else
controllingData.controlledEntity = Entity.Null;
}).WithDeallocateOnJobCompletion(entityArray).WithDeallocateOnJobCompletion(clientIdArray).Schedule(inputDeps);
return inputDeps;
}
}
Are you by chance not up to date on the Collection package and running on 2019.3? I know the built-in native collections in 2019.3 support dispose jobs for example
yeah, they have had that for a while now, but usually if you want a list to deallocate after a job you will have to use list.Dispose(dependency)
Is there any way to efficiently searching for a particular entity's component? Getting all entities by making a query and then perform the value-based search linearly might not be a good idea.
If you need frequent access you can obviously tag it with another component or similar. Otherwise it's worth considering whether the data needs to be with an entity or not.
I'm familiar with tagging (or blank components), but sadly it's not the case. The component that I'm trying to perform the search is already very primitive (something like player.attackTarget in traditional OOP approach, but many entities have that).
To put in into a more clear problem, let's say: given that I have a AttackTarget component with only an Entity value inside, and I want to get all the entity that is trying to attack a particular one.
Your only option is to add another tag to further reduce your query or query all relevant entities and exit out when you find the right ones. There's a post about this here https://forum.unity.com/threads/query-a-value.801915/
But it doesn't seem like they're too interested in implementing it. I suggest you add your voice to that thread if you want something like this
@rough moon "I want to get all the entity that is trying to attack a particular one" - e.g. foreach() if(attackTarget.Value == target) allEntitiesAttackingTarget.add(entity) is the most efficient way within the ECS paradigm if there's no archetype difference. You can make the allEntitiesAttackingTarget container persistent, write to it in parallel and only update it when you change attack targets for example. Optimisations will be very specific to your task (for example, how/when does the attack target change and what is the data used for etc). I'll also just say that linear search through components is designed to be incredibly quick - so perhaps profile before overly worrying. If you're doing this very frequently, there will be ways to cache it or add additional structures to optimise. For example spatial hashmap e.g. boids. This is part of the pain of shifting to DOD way of thinking - there aren't many general rules about how to architect things as they're data-flow specific.
How can I use intellisense in VSCode for unity dots?
There is no autocompletition
When I manually complete the Linear word, it works..
hmm probably the VSCode editor package for unity might've not generated the looks up for the physics package?
hi how can we create a new component by copy ?
like, i have to create a new entity, and one of its component must have the same values as the one passed to the function
i was thinking it would be easy but got no relevant results on google
i'd say EntityManager.Instantiate(entity) but it sounds like you only want a specific component?
hmm probably the VSCode editor package for unity might've not generated the looks up for the physics package?
@coarse turtle mmh..
var entity = CmdBuffer.CreateEntity(withSomeArchetype);
CmdBuffer.SetComponent(entity, new T { });
Guess you will need to consume a "messaging entity" or some queue of data you have to set the data via the CommandBuffer
@mighty whale The component passed to the function is a copy, so you can just add it to your new entity.
thanks, i actually just realized that what i tried to add wasnt exactly a component lol
but it's solved
Great π
also is there a way to have a fixed size list in a component :/ ?
currently we use a DynamicBuffer, but this forces us to use IBufferElementData instead of IComponentData
There's a fixed list that you can use in the collections package
you can place that into a struct : IComponentData
I haven't used it though
public static Entity create(DroppedItem item, int3 pos) {
Entity entity = _entityManager.CreateEntity(_archetype);
// ...
_entityManager.SetComponentData(entity, item);
return entity;
}
but i get an error 'Components.DroppedItem' must be non-nullable blablabla
how can i get around this ?
@mighty whale Is DroppedItem a struct?
it is a IComponentData
let me grab the code
here
using Unity.Entities;
namespace Components {
public class DroppedItem: IComponentData {
public int amount;
public int id;
}
}```
@tawdry tree
also thanks for helping 
Well, components should be structs, like
public struct DroppedItem: IComponentData //...
That's the non nullable value type or whatever it's complaining about it not being
It would be easier if it just called it a struct, though...
is there an easy way to rescale a RenderMesh or a mesh π€ ?
Nothing is easy with DOTS π
Re. NativeArrays<int> - I'm chasing milliseconds and 8.4 ms are going to 1254 updates of the NativeArray. These 8.4ms are nearly 50% of the time spent in this specific function. I have enabled Burst compilation, disabled the safety checks. Is there something more I can do to reduce the time setting values in the array takes?
No, not yet, mostly because Unity fails to build
Is there a way to enable Unity collections checks in a development build?
@digital scarab ok, and that isn't disabled when safety checks are disabled in the editor menu?
oh, ok.
@digital scarab I've not yet found a solution for this problem so I can't profile a player build...
Unable to find player assembly: C:\code\World2\Temp\StagingArea\Data\Managed\Unity.PerformanceTesting.dll
UnityEngine.Debug:LogWarning(Object)
Unity.Burst.Editor.BurstAotCompiler:OnPostBuildPlayerScriptDLLsImpl(BuildReport) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:166)
Unity.Burst.Editor.BurstAotCompiler:OnPostBuildPlayerScriptDLLs(BuildReport) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:46)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
@mighty whale Do it in a model editor? Any of them should do, and if you don't want to download one, search for "rescale mesh online tool" or something.
If it has to be in code, iterate over all vertex positions and multiply each dimension (x,y,z) with the relevant factor. Sounds like something you could use a ParalellForJob for, though not sure if you'd gain anything.
@digital scarab Argh, my bad. Copied the wrong message.
@digital scarab ```
BuildFailedException: Burst compiler (1.1.2) failed running
stdout:
Burst requires Visual Studio (installable via Add Component in the Unity Installer) or the C++ build tools for Visual Studio, along with the Windows 10 SDK in order to build a standalone player for Windows with X64_SSE4
Unable to retrieve windows 10 sdk base
stderr:
Unity.Burst.Editor.BurstAotCompiler+BclRunner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, UnityEditor.Build.Reporting.BuildReport report) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:659)
Unity.Burst.Editor.BurstAotCompiler+BclRunner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, UnityEditor.Build.Reporting.BuildReport report) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:597)
Unity.Burst.Editor.BurstAotCompiler+BclRunner.RunManagedProgram (System.String exe, System.String args, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, UnityEditor.Build.Reporting.BuildReport report) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:571)
Unity.Burst.Editor.BurstAotCompiler.OnPostBuildPlayerScriptDLLsImpl (UnityEditor.Build.Reporting.BuildReport report) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:286)
Unity.Burst.Editor.BurstAotCompiler.OnPostBuildPlayerScriptDLLs (UnityEditor.Build.Reporting.BuildReport report) (at Library/PackageCache/com.unity.burst@1.1.2/Editor/BurstAotCompiler.cs:46)
UnityEditor.Build.BuildPipelineInterfaces.OnPostBuildPlayerScriptDLLs (UnityEditor.Build.Reporting.BuildReport report) (at <0a2a5ea3c8ab4e3394576dd407a984f6>:0)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
I've already got VS installed, Unity did that for me
yep, all packages are up-to-date
hm, there's a Windows 10 SDK in the VS installer - will try to add that
Btw, is BurstCompile-attribute still needed?
oh, sweet. Installing the Win10 SDK manually fixed the build issue
@molten plume the message is correct
you are missing c++ build tools for visual studio
yeah, like I just wrote - installing the sdk fixed it
ah, sorry I missed that
is it possible to pause the profiler when profiling the player?
oh, found the record button π
huh, the player is more laggy that the editor :\
Hello Guys.
I've having issues with a LifeTime component i created, it's fairly simple and made in a ComponentSystem to not have issues with Destroy
The issue is that i set the lifetime to be based on a maxAttackRange/Speed after debugging it the initial lienar speed for PhysicsBody is set to the correct values on creation, but the bullet always goes further than what maxAttackRange says it shoud be, like for about a half
And here it is how I'm creating the bullet https://hastebin.com/ovaciqesoq.cs
Btw guys I have seen you share Code directly here, what is the syntax for it?
@mighty whale use a Scale or NonUniformScale component. the entities documentation has much more info on transform components that are probably easy to overlook.
Yep i used a Scale component it worked just fine thanks :)
Hello Guys.
I've having issues with a LifeTime component i created, it's fairly simple and made in a ComponentSystem to not have issues with Destroy
@proud cape
I made some tests and it looks like the ecs Pyshics is making the bullet move faster than the AngularVelocity vector implies, I made some custom move by speed and acceleration systems as tests, and they do work as expected but the objects with Physics body do move faster than what i inted
@safe lintel thanks
how do you perform a query on classic object components in a system when doing hybrid ecs?
@glass tiger If im not mistaken as an ECS component just pass the GameObject component to the generics methods
hmm, I'll try it
I was trying to use ForEach but maybe that syntax doesn't work with it yet
I tried
Entities.WithoutBurst().ForEach<SpriteRenderer>((
SpriteRenderer sprite
) => {
Debug.Log(sprite);
});
but it gives Error CS0308 The non-generic method 'ForEachLambdaJobDescription.ForEach(Invalid_ForEach_Signature_See_ForEach_Documentation_For_Rules_And_Restrictions)' cannot be used with type arguments Assembly-CSharp
documentation on hybrid ecs seems to be scarce to come by
Did you end it with .Run()?
otherwise it'll still be trying to schedule a job with a managed parameter
hold on
wait, removing the generic stuff made it work, what on earth
Yeah I was about to check that
the IL Manipulation doesn't like you putting things in the generics, as I think it does some type wrapper stuff with them
finally got it working with GO components, ECS component refs and read-only
Entities.WithoutBurst().ForEach((
SpriteRenderer renderer,
ref Translation t,
in PlayerMovementValues movementValues
) =>
{
Debug.Log(renderer);
}).Run();
I spent so long trying to figure this out yesterday, apparently I just had the order of the args wrong before
it seems particular about the order you specify them
that's a relief
The template for this if im not mistaken ask for classic components first then components thats why I think you had this issue
yup, that seems to be the case
I tried looking at the ForEach overloads but I wasn't able to comprehend them
and I'm still not sure what the generic versions are for lol
is it possible to store materials and meshes in shared component data so they can be used in Jobs?
I tried putting an SCD together as a test but they were passed as reference types and obviously it didn't like that
(trying to remind myself how not to pass something as a reference type hahaha)
@last lintel check this example https://docs.unity3d.com/Packages/com.unity.physics@0.2/manual/interacting_with_bodies.html#creating-bodies-from-scratch
I'm not sure I follow what's happening in that example. and isn't RenderMesh associated with the hybrid renderer? I'm trying to use Graphics.DrawMeshInstanced and that takes a Mesh
entityManager.SetSharedComponentData(entity, displayMesh);
This can be done for Mesh too