public unsafe struct StaticPointer
{
public void* Pointer;
public static T* Create<T>(T value = default) where T : unmanaged
{
var instance = new StaticPointer();
var size = UnsafeUtility.SizeOf<T>();
var align = UnsafeUtility.SizeOf<T>();
instance.Pointer = UnsafeUtility.Malloc(size, align, Allocator.Persistent);
UnsafeUtility.MemClear(instance.Pointer, size);
T* typedPointer = (T*)instance.Pointer;
*typedPointer = value;
return typedPointer;
}
public T* As<T>() where T : unmanaged => (T*)Pointer;
public T GetValue<T>() where T : unmanaged => *(T*)Pointer;
public ref T AsRef<T>() where T : unmanaged => ref *(T*)Pointer;
}
#archived-dots
1 messages Β· Page 79 of 1
@mint iron burst supports generic static methods right ye?
yeah
kinda of
the generic has to be in the method rather than containing class
which is probably why their TypeHelper<T> is still a class and blocking any kind of entity create/destroy while inside burst
@mint iron yeah, that's what i mean - all my generic methods are void Bar<T>() not Foo<T>.Bar (in a type)
yeah thats fine
I have e.g. ComponentDataFromEntity<Bob> bobs; set in an IJobChunk - to try and avoid a somewhat expensive bobs.Exists(entities[i]) I wanted to set a simple bool: bool hasBob = chunk.Has(BobType) - the problem being that BobType and the CDFE are declared both type Bob so Unity throws an error thinking the job uses the same type in different ways. One way to get round this is to use multiple entity queries and set the property in update instead but it would be nice if I could avoid that - any thoughts?
Just using .Exists in the first iteration of the chunk works for now π
I like what you do @trail burrow
? π
perhaps I'll use an unsafe structure in my asset
any kind of speed increase is always appreciated
I use a lot of HashSets to run my coroutines
Array, Heap, Dictionary, List, MemoryPool, Queue, RingBuffer, Stack - List/Queue/Stack are also available in 'fixed size' versions (i.e. where they can't expand)
oh and two concurrent queues also, one SPSC and one MPSC
@lyric gust yeah UnsafeArray
do you know how much faster an unsafe array is than a safe one?
that's not the point of them tho
does it index faster, or just alloc faster?
https://gist.github.com/fholm/ee4c5ed057c398653dcb96200ad094bc here is the unsafe array
the point is that they are compatible with ecs components/other struct-pointer based systems
that can't deal with managed arrays or even NativeArray<T>
I thought ecs could deal with NativeArrays
@lyric gust you cant put a NativeArray<T> on a component
for example
and you cant take a pointer to NativeArray<T>, etc.
that... sounds inconvienient
I'm trying to wrap my head around ecs, still haven't built something in it
but the examples use native arrays a lot
so the ecs framework passes you a native array, but you can't create a local variable of that type?
the only way to use local collections is to make them unsafe.. is that right?
https://forum.unity.com/threads/error-nativearray-bool-fails-in-bursted-job.695653/ This thread seems to indicate that you can allocate native arrays, but that it didn't work in older versions @trail burrow
Got NativeArray has been deallocated error when trying to add entities to the nativelist
public class InventorySystem : ComponentSystem
{
public NativeList<Entity> items;
EntityQuery someGroup;
protected override void OnCreate()
{
var query = new EntityQueryDesc
{
All = new ComponentType[] { typeof(ItemComponent) }
};
someGroup = GetEntityQuery(query);
EntityManager entityManager = World.Active.EntityManager;
}
protected override void OnUpdate()
{
Entities.With(someGroup).ForEach((Entity entity, ref NameComponent r) =>
{
Debug.Log(r.Value);
items.Add(entity);
//Debug.Log(items[0]);
});
}
}
what am i doing wrong?
Uhm, are you ever initializing the nativearray?
oh thanks
public NativeList<Entity> items = new NativeList<Entity>(100, Allocator.Persistent); fixed error
Yeah, that
its like second day i learning ecs, sorry for stupid questions
public NativeArray<Entity> Entities; //Declaration. 'This variable should exist'
void SomeMethod(){
Entities = new NativeArray<Entities>(); //Initializing. Doesn't ACTUALLY exist before this!
}
I'd say that is more of a general programming thing, but I've made sillier mistakes π
By the way, are you sure you need that to be persistent, ie. last over multiple frames?
Just checking, because you should avoid making persistent nativecollections unless you need to.
its doesnt work with Temp or TempJob or without allocator... same NativeArray error
so i think Persistent is my way?
You need to declare it in the OnUpdate method if you want it to be temporary, I think
oh its not working even with Persistent now
what a mistery
a will try in OnUpdate
it worked few minutes ago tho
so
void OnUpdate(){
var entities = new NativeArray<Entities>(Allocator.TempJob);//Like so
//Use as needed
entities.Dispose(); //Dunno if this is actually necessary?
}
i think its good now
thanks
btw it will erase nativelist every frame?
why it doesnt work if i put it in OnCreate()
cant get it
oh its working nowπ
does b6 have the ui change fix thing?
https://bintray.com/unity/unity-staging/com.unity.tiny/0.16.0-preview
## [0.16.0] - 2019-06-14
* Several improvements when generating a DOTS C# project solution
### [Samples]
* Fixed Browser Interop sample
* Updated Hello World sample
### [Editor]
* Fixed delete shortcuts that were missing in OSX
* Fixed duplicate disabled entity bug
* Creating a new empty child Entity by hierarchy drop-down menu will now properly expand the node
* Dragging scenes inside the unused portion of the hierarchy will not load it
* Fixed WebAssembly.instantiateStreaming bug on Safari (iOS or desktop)
* Text: Fix issue with text and TMP resources not imported
* TextMesh Pro should be initialized without the user needing to import assets
### [Runtime]
* Adding the AudioSourceStart component will now restart the clip
* Volume field of AudioSource is now a slider```
what is project tiny?
ok.. read the blog on it, a better question is "what does it have to do with ecs?"
@lyric gust it's using ECS at it's core
hmm.. it seems to have samples in the package manager whereas I can't find any for ecs
it's also only thing that has full ECS editor mode right now
ECS samples are on github
check the pinned message here for link
the last time I tried that they were all for an outdated version
I guess I could look again
dots samples have almost always been updated for the latest version
they literally update the repo within few hours from new entities package release
interesting.. when I imported it there was a bunch of errors
what's with all the UI package errors with 1019.2.0b6
if you mean ugui thing
that change has been there since all 2019.2 betas and recent 2019.3 alphas
just update your packages
@minor sapphire
Hi guys, do you have some sample of how to create a data cache efficiently, in the RenderMeshSystem V2 they just save the chunk position that was culled, but in a case where I just want all the data of the EntityQuery but I know they won't move a lot, I wanted to cache the data as the address of the chunks. Or maybe it's completely meaningless because Array from the EntityQuery are kept until there is some changes?
yep that worked, update, close, restart
We are planning to have a 3rd drop around mid-august.
DSPGraph is a fancy way of saying "Audio System" yeah? lol
I think this explains the reason behind the wording https://www.youtube.com/watch?v=kDE-KxQBiYQ
Come learn about a new C# job-based audio rendering engine, which has been developed for Unity. You'll get an introduction to this low-level audio renderer a...
I think I watched this a while back
you can have graphs that don't come with visual node tooling
but DSP Graph has at least some visual preview ability if I remember right
I saw some nightmarish graphs from megacity π
lol
As long as I can have audiosources at the scale we have come to expect from dots...
I hate seeing people's profiler screenshots when they have like 15 workers lol, so jealous
heh, majority of the gamers will not have 8 core tho
is there release notes for 2019.2.0b6?
I got them https://unity3d.com/unity/beta/2019.2.0b6
I'd assume 4 or 6 when it comes to more 'core' gamers (heh), the kind that at least have a beefier laptop or maybe a budget desktop computer. It's by no means a guarantee, but most of newer machines probably have hyperthreading (or whatever the term for having two 'virtual cores' per physical core is), too.
Depends on your target audience, really.
@tawdry tree heh, currently os devs start to disable hyperthreading
cause of security risks it adds
I didn't know that, but I also never saw it as particularly useful, since with 4+ cores you already have more available cores than most games effectively use.
HT is great when you do bigger builds
can someone tell me what has changed between .31 and .33 for singletons? In .31 it was enough to have the struct with singleton datacomponent added to the entity (used with ConvertToEntity) and use
this.SetSingleton(new SingletonStruct
{
Data = data
});
inside the system which is filling that singleton, but in .33 it broke.
Is it possible to use MaterialPropertyBlocks with ECS currently? I was under the impression that it wasn't but it's been a while. I suppose it doesn't work with RenderMesh component but it would work using Graphics.DrawMeshInstanced where a system builds a material property block per entity?
hybrid renderer?
there was some talk about mpb being wip but part of the plan
a while ago
(I expect it to be working by now if using hybrid renderer, but would not be surprised if it did not yet)
As far as I know you still can't do per instance data using the provided hybrid renderer. You can of course do your own rendering with DrawMesh and do whatever you want, including per instance data
You still can't pass nativearrays to any of the DrawMesh-es though so it involves copying a lot of data around to make it work
I was just taking a look at someone's sprite renderer project on the forums and was confused as to how they instanced it. I appreciate the info! @urban rivet @zenith wyvern thanks!
I'll have to consider how to handle the draw mesh calls then...
https://bintray.com/unity/unity-staging/com.unity.tiny/0.16.1-preview
## [0.16.1] - 2019-06-18
### [Samples]
* Fixed fonts in Browser Interop sample```
Hi In the last couple of days I started working with multi-threading using the System.threading namespace.
So I started wondering if it was still worth using it after the release of the job system and the entity-component-system.
In any case could you tell me the differences between the job system and the classic threading system?
As with oh so many things, the answers it probably 'it depends'
But using just one method will simplify things and means you don't need the reference to System.Threading.
The job system is specifically made for Unity, for games, and has a lot (a lot) of safety checks built in to make it really hard to mess up, and to work well in a game engine's update loop.*
*runs every update (or at least started from update), as opposed to 'from we start it until it's done'. The nongame version is often faster overall (total average work done per time), but could lead to stuttering if not handled right.
The job system is nice since it handles dependencies and some busywork for you. If you are 100% confident in your ability to write threaded code without any race conditions then doing it yourself should be faster.
Think I finally finished up all my unsafe collections
array, list, ringbuffer, queue, stack, set, dictionary, bitset, heap and three concurrent specialized ones (mpsc queue, spsc queue and spsc memory pool)
@trail burrow you making data structures for the job system/burst?
knowing how hardcore fholm is about everything, this doesn't surprise me in the slightest
its a job highly needed
data structures are super important to have. And the more, the better
as if you have more you can select the best for your needs
i miss a dense-map or similar type of thing on unreal code, end up allways implementing my own
and a few others
@vagrant surge yes
They are all burst and job compatible, and can be put inside components on entities
@dull copper lol
thats really , really nice
Still have a few more specialized collections I want to implement
Like sorted dictionary
Maybe a BVH
what about a sparse-set/flat-set/indirect
where you have a hash set as usual, but the actual data is stored in a contiguous array
and the hashed thing is the index to the dense array
so when iterating you can iterate the dense
The hashset is implemented like that
Yes, you can iterate through it in a linear array
great
My dictionary is faster than the standard .net one by about 33% and than NativeHashMap<T> by about 4x
how is the native hash map implemented?
I have no clue, I did a standard hash map and optimized the hell out of it
Theirs have concurrency support of course
then it matches with the 4x
to have concurrency i think you need to basically make it like a lockfree linked list
if your hashmap is openadressing, the x4 makes complete sense. Thats a similar delta to what you can see from c++ unordered_map to one of the abseil hashmaps
But you can't put theirs in a component so
how do you deal with the dynamic memory?
It's all using native alloc
you can't reuse the bvh from Unity Physics?
tbh, I've not even looked at it's code
but people claim it's quite fast now
@dull copper no, look at that license and then I won't dare to look in their code lol
Yeah have you actually read it? :p
yes
So then you know why I can't look at it and port it to something that can run outside of unity also
but if you can't accept it, you can't use about any of the new packages
ah, you can't reuse it elsewhere, no
that's not usually an issue for a Unity user
Oh I can use it, I can't just port it to some elsewhere
but I can see your point
especially if you want to run custom backends without unity parts in them
Ye
can you easily port these data structures tho?
you'd think your implementation is super specific to this use case
The ones I made now?
Yes they're not tied to unity at all
All the unity alloc is isolated in one file that can be switched to pinvoke
ah, that's nice
Nothing else touches unitys APIs
great stuff there
also implementing a few specialized ones like UnsafeHashMap_4ByteKey and UnsafeHashMap_8ByteKey
names of them... is a work in progress lol
π
tends to happen lmao
how do you deal with destruction, btw?
do unity ecs components actualyl call destructors? so you can clean up the resource properly
@vagrant surge they are all unsafe, backed by native memory, cleaning them up is the users responsibility
yes if you dont know what you are doing π
but useful anyway
and even if you do, at times π
im just used to C++ where my containers get automatically destroyed
UnsafeHashMap* map = UnsafeHashMap.Allocate<int, int>(BENCH_COUNT, true);
for (var i = 0; i < BENCH_COUNT; ++i) {
UnsafeHashMap.Add(map, i, i);
}
basic usage of the map for example
just from my bench test, so nothing fancy
they are very C-like, so dont expect any fancy .NET stuff, you can blow your foot off easily
i see. So the maps themselves are heap allocated. Its like in C++ you had a pointer to a std::vector
https://hatebin.com/mhroncfmfe here's the stack as an example of how they work
i can see a lot of use for them. Specially when used with singleton or chunk components
most of them can be allocated in two modes, either dynamic or fixed size
some can only be allocated in fixed size mode, i.e. array... or some can only be done in dynamic mode like the MPSC queue
they all make strict use of data-alignment and cache line sizes where needed for optimal performance
unity ECS inside unity ECS when
could stuff like cachesize be automatic?
i think you could query the cache sizes dynamically with some instruction
@vagrant surge no it cant, there's a global constant used for it
it's set to 64 bytes by default, but you can of have a flag to compile it differently for different archs
i also allow you to do some more nasty things, like get the pointer to a value inside of a hashmap for example, so you can both read and modify the value with only one lookup in the hashmap
public static bool TryGetValuePtr<K, V>(UnsafeHashMap* map, K key, out V* val)
where K : unmanaged, IEquatable<K>
where V : unmanaged {
var entry = FindEntry(map, key, false);
if (entry != null) {
val = (V*)GetValue(map, entry);
return true;
}
val = null;
return false;
}
lmao great stuff
these are mostly written for my own personal use, but I will dump them on a github under MIT once i've tidied the last pieces of up
it also lets you re-interpret the collections
like you can create a UnsafeStack<int> and use it as a UnsafeStack<float>
or UnsafeHashMap.Allocate<int, short> and get values from it with UnsafeHashMap.TryGetValue<float, ushort> or we
as long as the type sizes line up, it doesnt care
i wonder has anyone figured out how to get lower level jobs or methods run with burst? i have code that works fine for directly scheduling without IJob. But im not sure how to wire in a burst compiled function.
@mint iron there is no way to burst compile anything but jobs atm
there supposedly is a generic 'burstcompile' for static methods/delegates comming
but it's not available yet afaik
afaik you can hack current setup to run burst outside jobs but it's definitely not supported by Unity
and yeah, they've mentioned few times they'd want to ultimately support something like that officially but it doesn't seem to be high on their priorities atm
realistically thinking, it has to happen at some point because there are still plenty of code that would benefit from burst which you can't practically jobify
yeah you can put [BurstCompile] on static methods, and it will show up in the burst inspector, but i'm not yet sure its actually running the burst version of the method in burst when you call the method. I'm not sure how to tell aside from try to make something slow and see if there's any speed difference with and without the attribute.
i was able to get a job scheduled from within a burst function heh
that code produces the expected output (5) and here's the asm: https://hatebin.com/wfdqklmofq and https://hatebin.com/iphvoqorfk but i can't tell if the initial call to Run() is actually in burst π¦ it could have compiled all this and then just called the managed version.
anyone had an error like this when building? :
ArgumentException: The Assembly nunit.framework is referenced by Unity.PerformanceTesting ('Library/ScriptAssemblies/Unity.PerformanceTesting.dll'). But the dll is not allowed to be included or could not be found.
Looks asmdef related maybe? Trying to combine the performance testing and ECS?
I just meant are you trying to run performance test on ecs content? (given this is in the ecs channel?)
nah, I'm just trying to build my ecs project
perhaps this is completely unrelated to ecs in the first place? hmm
@minor sapphire yes
use older testing packages
I've only seen that if I've manually updated the testing packages to newest
there's issue on some of the new ones
@minor sapphire json "com.unity.test-framework": "1.0.13", "com.unity.test-framework.performance": "1.2.0-preview",
those work for me
you may get away with newer test-framework, can't remember why I rolled both back
I got it wrong the first time, so I'll try again to make sure
I also have json "com.unity.ext.nunit": "1.0.0", on my manifest
but I think that's there by default for all now
oh hey that is not in my manifest!
it's probably not on the older editor versions
I also only have Entities, Hybrid Renderer and Unity Physics packages here from DOTS stuff
so if you've manually updated to never collections, mathematics etc, that might be a difference on our setup too
I just take those as dependencies automatically
oh, I have Burst here manually too, but that's because I had to do one line edit to Burst 1.0.4 for latest 2019.3 alpha
there was small api change that's not on burst package yet
check that you don't have newer other packages I listed
but yeah, it's probably rooted on the actual perf testing framework thing itself
all I know is that I got rid of that error by rolling those two packages back
interesting
I'll have a look through source control at previous versions of the manifest to see what's going on
I'd test which one it is on my end but I've updated HDRP from master recently so this would build the project 1-2 hours π
well, it might be faster since not everything is new on it
I'll check tomorrow, 1:30am now haha. Thanks for the info.
being able to burst-compile static functions would make so much sense, and be so damn useful
for everyone
i think I've got it working now in a reasonable form, but the catch is its using the runtime compilation, because its the only way so far to get the function pointer. If there were a way to figure out the location of the precompiled version we could wire it up.
I can't find the burst dll anywhere, the configs say it should be named lib_burst_generated. Its possible they're doing a dynamic assembly for the editor; like they seem to be for the Burst test cases.
## [1.1.0-preview.2] - 2019-06-20
- Fix issue where uninitialized values would be loaded instead for native containers containing big structs
- Fix issue where noalias analysis would fail for native containers containing big structs
- Fix issue when calling "internal" methods that take bool parameters
- Add support for `MethodImplOptions.AggressiveInlining` to force inlining
- Fix issue in ABITransform that would cause compilation errors with certain explicit struct layouts
- Disable debug information generation for PS4 due to IR compatability issue with latest SDK
- Implemented an assembly level cache for JIT compilation to improve iteration times in the Editor
- Implement a hard cap on the length of symbols to avoid problems for platforms that ingest IR for AOT
- Add support for `FunctionPointer<T>` usable from Burst Jobs via `BurstCompiler.CompileFunctionPointer<T>`
- Add `BurstCompiler.Options` to allow to control/enable/disable burst jobs compilation/run at runtime.
- Add `BurstRuntime.GetHashCode32<T>` and `GetHashCode64<T>` to allow to generate a hash code for a specified time from a burst jobs
this changelog is bit wonky tho, it doesn't contain 1.0.1 - 1.0.4 changes
so, they probably missed the notes from those due to some internal branching
@dull copper is this burts? ecs? jobs?
- Add support for MethodImplOptions.AggressiveInlining to force inlining sexxxxxxy
new burst package I linked above π
@dull copper do you know if you can stackalloc in burst?
you can
Function pointers? Yes please!
interesting, i thought that burst already inlined the hell out of almost everything
Any reccomendations on good places to start with ECS? About to start a new project that I think would be well suited, and would love to use it as a platform to learn.
(burst) "error: External and internal calls are not allowed inside static constructors" that's new... π¦ there goes the fun.
ohh.. finally we get agressive inlining?
I've been asking about that for a year
@onyx swan check out the pinned messages on this channel
If i have a dataset that looks like this as a ridiculously large matrix, is ECS / DOTS capable of showing a couple million points simultaneously by going through each row of my matrix at each frame? for example point #1 has an x y and z value prescribed in each row, so at each frame it'd plot position xyz <- mymatrix[time.frameCount, 1:3]. thanks!
I want to get an idea of what scale it'll break at
you would want to use structs rather than a matrix
ECS will then move your data elements into a good order
so each point would have a structure with an x float[], y float[] and z float[]?
@lyric gust
@dull copper , I used "com.unity.test-framework.performance": "1.0.9-preview",. I noticed that's what the dependency for entities was
now it works
huh, that's weird
because when I had that, I specifically reset the values to what the other packages had on dependencies
but yeah, you are right, it has 1.0.9 π
maybe this will fail if I build it now π
but yeah, default dependencies worked for me back then
oh man that main thread utilisation issue from a last week has found some kind of resolution!
https://forum.unity.com/threads/ijobparallelfor-jobs-tend-to-not-use-the-main-thread.682078/#post-4671458
The fix/improvement is targeted for 2019.3, and should see main thread help more when waiting for job completion!
Ty @lyric gust
@minor sapphire I lol'd at the start of the response
"this isn't a bug in the code" "but code didn't do what it was supposed to"
what's important is that it's getting fixed
appreciate the persistence of you guys on this π
lol yeah I reckon. working as intended, but intention is not ideal so let's make it better? π
I'd still classify that as a bug, but still, at least it's getting fixed π
most of the issues are like that, oversight in the actual usage scenarios
of course there are actual programming errors too
but I get probably more the latter
@clear stream You can't use arrays in ECS. The most efficient way would be to use one job that acts on a single x, y, and z. That job can run N number of times in a parallel manner using IJobParellelFor
Wasn't there an attribute to stop systems from being created by default?
Isn't it [DisableAutoCreation]
@lyric gust so each job is for one point, and has a huge list of Vector3?
@stuck saffron That was it, thanks!
@clear stream In this case you run the IJobParallelFor X*Y*Z times, once for each point, so it's the same job, just ran a lot of times. IIRC the .Schedule function for IJobParallelFor goes something like (totalIterations, iterationsPerRound, Allocator)
is there any way I can use a rotational spring force and slerp drive forces on the same configurable joint?
I want to simulate opposing muscles, but I don't want to create another configurable joint in the same position todo it
the configurable joint wont seem to allow it
I got the results I wanted by using a configurable joint for the flexor muscle, and a hinge joint w/ spring for the hydraulics
Hi all, I am very new to unity. Currently I am making a mobile game. My prime concern is performance efficiency / optimization of the game on various mobile devices. Since using prefabs are way more easy than just importing the asset as game object, is there any problem in importing all-most all possible assets as Prefabs? Will it lead to performance issue or large file size?
using prefabs is generally for the best
one tip for performance is to reuse assets
so like, instead of deleting the object when the enemy dies
just reset it to a default state and move it out of the way/hide/deactivate it
there is this garbage colelctor script, and anything you delete will add to its work
basically (i think) the game needs to check and see what memory space has become freed up as the result of object deletions
so re-use as much as possible
@timber ginkgo thanks π
Jobs/ECS: Is there any way to make a ParallelFor job use .Add on a NativeList in parallel jobs? There's no need to read or write other than to add an element to the list across the jobs.
@worldly gull The technique Chriscrass mentioned is called 'object pooling' if you need/want to look it up you should find plenty of useful results (maybe add 'unity' to the search terms, too'
@next kiln I believe the correct way is to use yourList[jobIndex] = (insert value here). That should work, at the very least. Of course, if the job isn't guaranteed to set the value you will end up with empty indices, but you'll have to consider whether that's a problem depending on your circumstance.
So I'm trying to figure out why my Slerp drive loses all power in the Y axis when it is rotated 90 degrees in the X axis (1 in radians(
any thoughts?
so it doesnt lose total power, but it behave very peculiarly
im thinking that when it is raised 90 degrees, what was once the y axis then becomes the Z axis, so none of the force is transferred (the z axis is locked)
any solutions?
yea looks like that's what's happening
same thing happens with X and YZ drive mode
And I found the fix
Apparently having a non zero "limited" range of motion in the Z axis (opposed to "locked") solves the issue
there's also some funkiness where switching back and forth between Slerp and X&YZ drives saves the current drive settings and applies them ontop of the drive you have switched to
although that is probably an artifact of editing a live environment
Trying to find a good solution for working with per instance material properties (via MaterialPropertyBlock)
I found this thread: https://forum.unity.com/threads/materialpropertyblock-support-in-meshinstancerenderersystem.562369/#post-3773455
and this code: https://github.com/tertle/com.bovinelabs.rendering
I tried converting it to current apis and I'm not getting any actual errors and it kinda works except it seems to be using the same property to draw all of them instead of the specific property for each entity (so they will all draw the same colour even if I set each instance to a different random colour).
Does anyone have and experience/advice/up to date working code for doing something like this?
Hi all, Currently I am making a mobile game. My prime concern is performance efficiency / optimization of the game. When enemy gets destroyed there should be a particle explosion. Which will be better to use, a png sequence animation or particle effects? If am using particle effects will it cause any recognizable performance issue.
might depend on the complexity of the effect? but sprite sheet animation will likely be faster, particles themselves are batched sprites in effect anyway. but.. has this got anything to do with ECS? should this be in general code?
@minor sapphire in general code
Yeah I mean maybe post this question in channel #π»βcode-beginner
I maybe solved the problem. I had to use a different mesh for each object, if they are all using the same mesh it won't work. Shouldn't it be the exact opposite?
Completely breaks batches though of course so hmm
How would I go about iterating over all the entities with the same shared component separately (or just dealing with them all in a separate manner)?
So say I have 10 entities with SharedComponent{Value = 1} and 10 with SharedComponent{Value=2}
I want to handle those separately. But I also want to grab their unique Translation component.
Preferably like to do this in a job compatible manner. I apologise if this is simple but I can't seem to find the information I need to do it.
I think there's an attribute tag, RequireSharedcomponent(typeof(type)) or something similar to do it, but unfortunately I don't remember the specific name (that you put on jobs)
Thanks for the tip I will look into. Do you know if that will do the per unique variant iteration?
It's just a filter, so it will iterate each entity, not each of the sharedcomponents
I think maybe IJobChunk is what I want and is is correct that I can assume if one entity in a chunk has a certain version of the shared component then all others in the same chunk will as well?
I remember there was some talk about a method to specifically update an entire chunk, but don't remember any specifics. I do know that if you changed it the way you would a normal component, you'd only affect that entity.
Is there a way to check the amount of active entities?
im spawning a bunch of entities every so often, and would want to make sure i dont go over a certain amount
Hmm, you can get an estimate of the amount of entities in an entity query, I think
Obviously, your code would be really brittle if you just checked for total entities that exist, so you'd want to filter it somehow.
Yea, i have the specific entities that i want to check for, just didnt know how to see how many active, short of doing something like a count++ in a foreach which seemed like a terrible way to do it
Well, a normal entity iteration is how you do most stuff in ECS, so if you run the check on demand or infrequently (once per second?) you should have no issues. The specific implementation matters, of course.
Quick google search points to entity queries. They can also be prepared ahead of time.
https://forum.unity.com/threads/get-entity-count-of-a-foreach-before-going-through-the-foreach.674866/#post-4517983
//In a component system
EntityQuery query = GetEntityQuery(
ComponentType.ReadOnly<CropTileQuerry>()
);
int count = query.CalculateLength();
Thanks a bunch!
is this normal?
if (Native_blocks2.IsCreated) Native_blocks2.Dispose();
InvalidOperationException: The NativeArray has been deallocated, it is not allowed to access it
Shouldn't it be something like this?
if (Native_blocks2.IsCreated && !Native_blocks2.IsDisposed)
Native_blocks2.Dispose();
Actually, it might be that Native_blocks2 is null when you do that check, have you tried looking at it with the debugger or logged it?
i dont think can be null if its IsCreated, but you definitely have to make sure its not already disposed to dispose it
another question
can i somehow make nested nativelist?
1D with 2D indexing calculations won't do
because: 1. it's for submesh triangles, so the size will differ, 2. creating two NativeLists, one for indexing where a submesh starts and second to hold tris won't do, since my code analyzes the chunk per XYZ, not pet blocktype
(voxels)
trying everything :v
Spent this morning experimenting with ECS for the first time and really enjoyed it.
Made a simple find and move to target system, and was able to have thousands of entitys and hundreds of FPS, which was insane.
My question is, can this be utilized with other unity behavior?
I'd like to make AI thats more fully featured (i.e. animations, different attacks, states) is ECS a viable way to do this? And if so, are there any good resources for it?
I hope so Slim. I'm working on an asset that would do that
it's still weeks away from release
Very cool! i'll keep my eyes peeled for it. Gonna be experimenting with colliders and a hybrid approach until then
@sonic oyster you can't do nested nativelist or nativearray because the dispose sentinel inside is a class. You can copy the structures and strip out all the dispose sentinel code, but then you will lose that safety mechanism. There are a few alternatives floating around. In the physics package for example they have to deal with similar issues as you for storing geometry so thats a good place to start looking through the code. They have a 'NativeBlob', and there is also 'UnsafeList' in collections package.
@onyx swan, for the moment a lot of features are not ECS ready, so for now you'll probably have to go hybrid, but we're steadily getting there!
Though, if you're making something 2D, you can use Tiny Mode/Project Tiny to get a proper ECS editor and more stuff that works. It locks you to pure ECS, though it's up to you whether that's a pro or con. Tiny mode recently switched from TypeScript to C#, so it's pretty early, but I suggest you give it a ride if you liked the ECS method.
So a couple of questions, for player controllers, should i bridge the gap via hybrid or should i check for inputs in the update part of a system maybe? Also, is it possible or effective to add more than one component data of the same type to an entity? Specifically, i have a mesh i want to combine, but i want it to keep the original component meshes primitive colliders in the form of ecs compatible aabb boxes of my own implementation. Could this be effectively done by adding multiple aabb components?
Due to how ECS works, I don't think you can have multiple components of the same type
EDIT: Something like this is how I'd do input (can handle singleplayer or local multiplayer, could be jobified for a server-authorative multiplayer game):
class PlayerInputSystem {
void OnUpdate(){
entities.forEach<PlayerTagComponent, MoveForwardComponent>(
//get the correct input and set speed in MoveForwardComponent
);
//etc.
}
}
@tawdry tree using job system for a PlayerInputSystem is completely overkill
leave the job system for when you are doing stuff on tons of entities at once. Player input is likely only one
unless you want player system to overlap with more stuff of course
Oh yeah, I'm just too used to thinking ECS-> jobs, but in this case you usually have a max of, what, four players, so not running the code in a job makes more sense. Well, I'd still make methods for them, but that's because I like my update methods to be fairly small and just call stuff with good names
Revised previous comments to better reflect that
i wonder whats the exact overhead of a job
at what point does it become worth it to put something in a job
Well, non-job code runs synchronously on the main thread, meaning it's basically incompatible with any other non-job code
So any time making, scheduling, and syncing the job takes less work than the code itself you want jobs
How would one make it so that a [RuntimeInitialiseOnLoad] is called before a systems OnCreate method? Trying to setup my static classes. The setup does require the entity manager if that makes it impossible (creating a static ArchetypeManager class to store all the archetypes I use)
Can you explain the order of actions here?
Like:
On startup: X first Then Y and Z And on update: Use (a) from Y to do W
In short, what needs to happen in what order (particularly on startup/initialization)
On Startup: The ArchetypeManager needs to register the dictionary of Archetypes
Next: The OnCreate for the system needs to run (an entity is created using an archetype)
OnUpdate: Use the created entity to do things.
I may have created a bit of a bad system here truth be told. Just struggling to do it in an ECS manner.
Hmm, doesn't sound quite like the ECS way. The dictionary sounds a lot like a singleton to me, where you don't want it to exists until you need it to exist, and basically cache the results. So you could use that pattern.
ECS also has a singleton helper thingy, which you can read a bit about here:
https://gametorrahod.com/ecs-singleton-data/
Singleton pattern:
public class ClassWithSingleton{
public static SingletonType Singleton{
get{
if(_singleton == null)
_singleton = GenerateSingletonMethod();
return _singleton;
}
}
private static SingeletonType _singleton;
}
For AI i was thinking of using ECS and burst for the simple find and move towards player (still need to work on collisons), is there a way I could use the ECS pattern to instance more in depth AI components (i.e. other monobehaviours and effects) once they got within a certain range of the player?
Yeah thats pretty much what i did.( @tawdry tree ) the passing through the inputs from the onupdate as floats. I also rigged up a raycasting solution so i can target my entitys by mouse click, and not with unity physics, its my own physics.
@onyx swan You'd do well to set up a partitioning system.
What do you mean by partitioning?
Well, think of in a post office, how you split the post into boxes based on intended location, like pigeon holes, except, you do it to the 3d space. The simplest form is to create some kind of array with an entry for each box in your space. You can, if your space is large, or complex, look into nativemultihashmap as this provides a useful way to partition the space and is kind of made for the job.
You'd then know each "box" contains objects subject to similar stimuli, similar distances. Depending on your scale, you might do a fairly fine scale and have say gun ranges able to reach up to two boxes, then search the local adjacent boxes... easily done. Or, as i am doing, use it to partition the space quite wide, and then use a second narrower phase inside each box.
Mine is for the broad phase detection of my collision system.
The nativemultihashmap is a very quick accessing option tho, it wont feel like you are plodding through some slow mess of iterations like your average multidimensional array.
Check out the Boids simulation in the ecs samples on github
Gotcha, i had something like that in mind. Basically separating which areas react to different behavior. The only real AI i've done in the past was in UE 4, so im still kind of thinking of it like that
Thanks for your help!
No worries!
How do I make my entity have the "WorldToLocal" component?
add that component to it manually?
So it will update it automagically then^^ I noticed I probably needed the other way around, and that is added by the Convert : )
I had to manually add that to something some time ago, can't remember why
objects started rendering after I added it
ah, now I remember, it was that Tertle's proc gen mesh demo for ECS
I just upgraded it to latest ECS and needed to add that for it to work
i'm trying to raycast with new ecs physics
public class RaycastSystem : ComponentSystem
{
PhysicsWorld physicsWorld;
EntityManager entityManager;
RaycastInput rayCastInput;
RaycastHit raycastHit;
protected override void OnCreateManager()
{
raycastHit = new RaycastHit();
entityManager = World.Active.EntityManager;
physicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>().PhysicsWorld;
}
protected override void OnUpdate()
{
Entities.ForEach((Entity entity, ref Translation trs, ref Rotation rot, ref MainCameraComponent mcC) =>
{
Ray ray = Camera.main.ScreenPointToRay(new Vector3(0.5f, 0.5f, 0));
rayCastInput = new RaycastInput
{
Start = ray.origin,
End = ray.origin + ray.direction * 100,
Filter = mcC.Value
};
bool hasHit = physicsWorld.CastRay(rayCastInput, out raycastHit);
});
}
}```
but getting The NativeArray has been deallocated error
what am i doing wrong?
error at this line bool hasHit = physicsWorld.CastRay(rayCastInput, out raycastHit);
it might be the system dependencies ordering? in a jobcomponentsystem you use the final handle for the physics worlds as a primary dependency for any job you want to query off of the physics, i see they just call complete on the componentsystem version in the physics samples https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/4e5f45339d81699464ff2d6fbd195ae184d45a7c/UnityPhysicsExamples/Assets/Demos/6. Use Cases/RaycastCar/Scripts/VehicleMechanics.cs
at the top of OnUpdate() there are some lines you may need to copy for your system
Thank you very much. I got it working now
Is there a way to dynamically set components.
So for example I have an array of IComponentData, because I don't know the exact type those won't work with SetComponentData
The only viable solution I've found requires implementing a second interface on all compone ts to do the call. This obviously isn't ideal so I was curious if there was a proper way to approach this?
I accomplished that in a not so elegant way.
I use a switch(enum) and then cast to the correct component to add the correct component.
I am also interested in a better way to do it. I plan on changing my implementation when I migrate over to 2019.3 which has Polymorphic Serialization
Oh yeah I considered that but definitely not something I want to do. It would also break my inspector setup.
That might be good though I really wish there was a better built in way.
I just did Custom Property Drawer which helped create the proper component. It was pretty simple as most of my components only needed a float value or int value
I think I remember seeing Tiny already has a special inspector for IComponentData
May be worth looking into
Could lead to ideas
I think for now my solution will be to have an interface:
public interface IComponentDataAssignable : IComponentData
{
void AssignToEntity(EntityManager em, Entity entity);
}
which I will implement for anything i want to save as:
public void AssignToEntity(EntityManager em, Entity entity)
{
em.SetComponentData(entity, this);
}
Not ideal but works without too much hassle. No idea if this is going to cause some unseen problems.
Noob question: for what purposes we have [WriteOnly]. I understand that [ReadOnly] just saying "Make a copy" and jobs can read same data. But what we achieve when mark struct fields as [WriteOnly]?
In some cases write-only will let you optimize, particularly when doing collections in parallel.
If, for example, you have some kinda list, and you want to be 100% sure you can add to it, but don't care for the order, then you could have an implementation with eventual consistency - if at any point in time you asked what element [x] was, or how many entries it had, it would not know, and could not know, but once everything was done you could check it.
To be fair, I am not 100% sure on this, since it's a while since i read this (was regarding concurrent collections in C#) but I'm sure knowing you will only write lets you optimize something.
I have just created a new project, imported all the DOTS packages, including the preview ones. I have set up a simple scene, with a plane and a cube, converted to entities and using the new Unity Physics system. But I am getting around 80 fps. The same setup with regular gameobjects and the normal unity physics, gives about 500 fps... Any ideas?
@lapis yoke DOTS Physics is currently tied to the framerate
so running at 500fps would require 500 physics simulations
where stock physics runs still only 50 Hz regardless how fast you render
unless you've changed the defaults
and yes, it's a known issue
it'll get fixed eventually
Aha, thanks. I thought it was something wrong with the burst compiler or a project setting that was wrong. Then I can start playing with it π
well, 80fps isn't great figure still
but... you should rather measure these costs in milliseconds
500fps tells practically nothing
well, it tells you aren't really doing any real work yet
if you can render actual game at 500fps, you got some really beefy gpu or super simplified scene
Yeah, I know. I'm just used to the physics examples running at several hundred fps, and this very simple test was under 100.
But I have not had time to play with it for several months, so a lot has changed with all the packages.
A quick profiling shows that the StepPhysicsWorld is taking ~6 ms, with just the simple cube and plane. I don't know if that's expected and just the Physics waiting for frame sync?
But i'll try throwing a few hundred physics entities after it tomorrow and see what that does to the physics steps. Hopefully it will be faster than the collision detection I wrote myself with Entities/Jobs.
is there a way in ECS to have one function which chooses whether other functions get run in group or not?
I want to run additional processing if the framerate drops below a certain number, so if DeltaTime is large enough I want to run an additional correction function
put that system in place always and have the deltatime check in it?
if it doesn't need to do anything, you just have early out
@lyric gust
I've no idea if @lyric gust has a similar problem to me but e.g. the second frame in editor always takes 0.333ms so it would be ideal to run a system n additional times if e.g. something should have happened every 0.02ms. One approach I've tried is having a for loop in the update and then use another system to set the iterations (based on the delta time)
Hey, does anybody used already EntityManager.MoveEntitiesFrom?
I want to move all entities from the current world into another but unity is freezing or going into an endless loop on that line.
I guess it is because the code runs into this line
throw new ArgumentException("MoveEntitiesFrom is not supported with managed arrays");
Okay guys, another questions. I creating an nativeArray with Allocator.Persistent. But anyway unity is complaining about memory leak detection because it was not disposed. This should not be raised for the persistant allocator, right?
Is Unity doing something magically when I loaded and unloaded scenes in the background? But this should not affect my native stuff.
@crystal zephyr you sure it's coming from your own code?
in past that warning has surfaced x times from Unity's own systems
Yes, I set the leak detection to full stack trace and it was showing me my line where I create a new native array with Allocator.Persistant. But it might be a bug in the leak detection to not ignoring persistant allocators?
I've seen people complaining about that too in past (that they get that error with .Persistent
but can't remember where people ended with those
@crystal zephyr afaik Unity would have you explicitly dispose of the native array, even if persistent
@amber flicker What do you mean? Sure I have to dispose it somewhen but I wanted to keep it for now. Are the persistent array supposed to get disposed before a scene changes or Resource.UnloadUnusedAssets are called or something like this?
so are you getting that when you unload a scene? I think I misunderstood
Unloading a scene is just what I am doing as well. I will check if I would get the message also without it. But this should be unrelated.
also to ask the obvious question - you're aware that once you get that warning the only way to reset it is to restart the editor?
Yes π
@dull copper yeah.. I could always rewrite it to use a while loop for really simple cases, but in more complex cases I need to have different components with a different mix of systems on them. I need to run the "calculate percent done" system then the "calculate position based on percent done" system. Different components would have a different system for calculating percent done. I want to be able to run whichever systems N number of times, where N is calculated based on the value of DeltaTime.
when you need to adjust timing like that, its best to disable auto update for those systems, and tick them yourself inside of a monobehaviour or componentsystem (which owns the other systems mentioned). in those areas you would do a simple update loop timing with target timing code there. (frame count, or dt based simulation update like physics)
@lyric gust
the systems updating, when disabled from stock update timing, can be ticked at any point how ever you would like
100 updates per frame even.
the systems when created manage the dependency generation from their queries, so you are safe to update them
A component system which owns other systems.. that sounds interesting
haven't had a case where I need to update outside of the stock update loop, but it should work just fine
usually I just rework my logic and data
I mean if you need n number of frames, why not just throw a counter onto the component?
Thanks June.. I'm not sure how to actually build such a system, but I'll dig through the documentation with that in mind now
n entities * 4 bytes per counter (1 if its < 255) is only 4mb per million entities
quite literally nothing
yeah.. I could see that
each system could have it's own threashold and dividing factor, most of them would be above the threashold most frames and thus would do nothing
btw, you can just store the elapsed delta time in a singleton component or the like
an just do nothing if its not the time in the system
stuff like
[AlwaysUpdateSystem]
class TimingSystem : ComponentSystem
{
ChildSystem childSystem;
protected override void OnCreateManager()
{
childSystem = World.GetOrCreateSystem<ChildSystem>();
}
protected override void OnUpdate()
{
childSystem.Update();
}
}
[DisableAutoCreation]
class ChildSystem : ComponentSystem
{
EntityQuery NewRequests;
protected override void OnCreateManager()
{
NewRequests = GetEntityQuery(
ComponentType.ReadOnly<AssetRequest>(),
ComponentType.ReadOnly<LocalAsset>(),
ComponentType.Exclude<RequestInProgress>()
);
}
protected override void OnUpdate()
{
Entities.With(NewRequests).ForEach((Entity e, ref AssetRequest req, ref LocalAsset asset) =>
{
Debug.Log("[AssetRequest] " + asset.FileName);
PostUpdateCommands.AddComponent(e, new RequestInProgress { ID = e.GetHashCode() });
});
}
}
key points, [AlwaysUpdateSystem] [DisableAutoCreation]
void Update(){
DeltaComp DeltaTime = GetSingleton<LogicTime>()
if(DeltaTime.elapsed < 0.033){ return}
else{ // do stuff}
}
and childSystem = World.GetOrCreateSystem<ChildSystem>();
childSystem.Update();
any anyway. Manual system loop is something i recomend in general
yeah if you want full control go for it
of course ive used ECS more in C++ than unity, so its the default way. but i think having somewhere in your code where you just have the systems one after another is super good to have
auto created loop is fine for me for now
disabling the bootstrap is pretty easy if you want to just take full control of your system update order
Thanks a bunch @low tangle
with the stipulation that you loose all the unity systems being auto created
yeah no problem
that snippit would compile if you edit my query to your own types, just left it in there because I was working on a asset system and copy pasted it
ran it and it works just fine
one of the coolest parts of ECS is just how incredibly simple is to do this kind of "execute once a second" or "work at 30 fps" systems
just do it at the system level, grouped if you want
interesting
ECS based coroutines, anyone?
eh.. the burst compiler probably wouldn't handle yield return
unless... someone made that happen
tbh, I have no idea what they are hacking with that π
as far as I'm concerned, I'd want to burn coroutines and never see then again π
they are overused for what they do
they're used often because they are useful often
I guess my frustration with them comes from seeing people abusing them for things they shouldn't
hmm.. you must want to burn lambda expressions to the ground too then
and down with linq.. no more fluid architecture...
ohh.. injection has gotta go too
hell.. delegates in general are often abused
if you mean the injection Unity's ECS had, then yet, it was awesome they got rid of that
kill them
tbh, I've not seen delegates getting abused much
no? you haven't seen people add WAY to many events? an event for everything under the sun
public void event Action OnEventThrown()
just to be clear, I'm mainly now talking about game code and what I've come across, and no I've not really seen people use events much
but don't get me started on dozens of singleton managers
I have seen it a lot in game code
anyway, this is pretty #497872469911404564 already π
yeah
Linq is kind of a huge joke
the equivalent on C++ (coming C++20, Ranges) is almost zero-overhead
a Reverse will just flip the iterators, instead of copying the entire array in reverse like Linq does
hmm.. yeah. Several functions for generators... like Reset were never implemented in .net
You could do a more efficient reverse if you could reset
@dull copper I'm trying to find any kind of operable code in this better coroutines package.. I can't find any
Hi, quite new to unity.
I have a prefab which has a collider and a script attached to it. The update function just detects the touch. I have multiple objects of the same prefab on the screen. When the user click obj1 and obj2, I want to create a line between obj1 and obj2.
What is the good model to track this kind of sequence?
it's not meant to be working sample
even after hackweek is done, it's going to be just something people quickly hacked together rather than polished feat π
Cool, how do you know this @dull copper ?
@vagrant surge key point here coming C++20 - they are learning and improving! thats a good thing. its not that linq is fast, its that its been nice and functional style! if its still ergonomic and its faster thats a great thing :)
@lyric gust because Unity's github is now filled with projects and branches that have hackweek, hw19 etc in the name π
ohh.. the prefix!
@visual orbit This isn't the right channel for prefabs and gameobjects. You should probably ask questions about that in #π»βcode-beginner.
That said, I would point you towards the Line Renderer component, which sounds like it would do what you want it to. https://docs.unity3d.com/Manual/class-LineRenderer.html
Hello, coroutine abuser here
Is this pattern-abusers anonymous now?
@tawdry tree Thanks for the pointer. I am aware of line renderer. My question was more around object model and hence I tried this channel. Nonetheless, thanks for the link
ECS (channel name) is a different way to do things from the normal unity way (for the moment, at least), and involves, among other things explicitly downloading a package which is currently in preview. So if you aren't sure if you're using ECS, then you aren't, though if you hadn't heard about it I can see where the confusion came from.
If you're talking about object model as in the logic behind it, then the easiest would be to keep track of the last two objects clicked, no? Perhaps with a selection-box or something like that and a way to deselect.
@tawdry tree You are correct. My confusion was about the object hierarchy. I think I was trying to figure out how the statemanager would be incorporated into the system. But I think I found the answer. Again, thanks!!
High five @odd bay
We can use [InternalBufferCapacity(int)] to set default capacity for all buffers of that type, but what should i do if i want change capacity at runtime?
I see some functions that probably do what i need, but i don't know what they exactly doing. Can someone explain me that?
public void Reserve(int length);
public void ResizeUninitialized(int length);
I guess Reserve(int length) allocate a heap memory block with "length" size.
A bit confused of how I should go about dealing with referenced entities data. My basic system want to copy the position and rotation of another entity. How would I get the referenced entities position and rotation since it doesn't come with the natural iteration?
ComponentDataFromEntity
It's simple to create a component data for a system to crunch on via a monobehaviour, but how can the monobehaviour get the resulting data back?
Keep a refrence to the entity manager and query the data
I have feeling that a do some things wrong. I update float and i need to do some computations when it comes to 0.5f and 1.0f. So for optimize i use IJobForEach to update float, cause i need to do it every frame, and i use IJobParallelFor to make computations. So to pass entities which i need to compute i use NativeQueue.Concurrent and then iterate over it in IJobParallelFor. To access the data in IJobParallelFor i use ComponentDataFromEntity/BufferFromEntity.
I see 2 problems here:
- To access NativeQueue in IJobParallelFor i need to force JobHandle.Complete() right after scheduling IJobForEach
- Approach with using CDFE/BFE looks too ugly
Am i use good approach?
I understand that this is very noob question, but with new DOTS documentation i can't find any information.
from 2019.3.0a7 release notes:
* Graphics: Ability to specify custom Mesh vertex data formats, and set vertex buffer data from NativeArrays. See VertexAttributeFormat, VertexAttributeDescriptor, Mesh.SetVertexBufferParams, Mesh.SetVertexBufferData.
* Graphics: Ability to specify Mesh submesh information directly, and set index buffer data from NativeArrays. See SubMeshDescriptor, Mesh.SetIndexBufferParams, Mesh.SetIndexBufferData.```
That sounds like it's at least partially aimed at helping with the issues you get from trying to use meshes in DOTS
DOTS or wanting to use burst with jobs for this purpose in general
should make proc gen stuff a lot easier to optimize now
neat π
ah nice, next dots physics package apparently got terrain collision
@frosty siren IParallelForFilter is an option for that kind of situation
Those 2019.3a7 patch notes are tempting me to jump to the alpha instead of 2019.2b7. Does anyone have experience with it as far as stability / package compatibility, or is still "wait on it"?
that mesh stuff sounds great π
Hmm quick question, since I finally got around to playing with Unity Physics, how do i get to the collision layers again? I remember seeing a + sign π€
whoops nvm, hadn't realised they were assets π
@untold night it is the usual alpha experience, been on it since first public alpha. Things mostly work, but need to be prepared to use staging packages
At a7, it could as well be b1 IMO
cool, I've generally held off on the alphas until later, but "later" tends to vary per release
For HDRP I stick with github master
But that requires often to revert some commits
Like right now master from 3-4 commits away from head works as is on a7 but there are 2 commits for api changes after that which hasnt landed on alphas yet
@untold night IMO biggest issue on 2019.3 is the new theme atm rather than some random bugs (every unity release has bugs anyway)
for example, package manager icons on 2019.3 on the left, and old setup on the right
you can immediately tell how easy it'll be to spot the ones with updates
I noticed.
I hope their UX team reconsiders, or at least adds more solid color
they've also made text smaller in all places but that doesn't mean you fit more
you just get more white space
and they lack all sensible UI scaling options, they actually have UI scaling but it's fixed step like 100, 125, etc
and 25% step it huge
they go all the way to 300%
but don't have say, 105 or 110 which I'd want to use
honestly, just let us set our own fonts already
or use our own stylesheet
then we should be able to replace the stylesheets
I peeked into this
and ui elements debugger shows the file even
it's just embedded in the unity's editor resources
should just have custom theme option so people could put anything there
as the system clearly allows it
@untold night as for the font, I think Preferences->General has editor font selection
but it's only listing 3 options
ah
Verdana (default), Roboto (UE4 uses this on UI) and Segoe UI
the issue with that is the same tho, Verdana is widest font, therefore biggest
and if you pick anything else, you'd want that 105-110 scaling which is not an option π
I'd prefer this one
but everything is like microscopic
I guess it's good for those people with 27"+ 1080p monitors π
I can still use this with my glasses on, but not without and I don't have that bad near sight
but I can guarantee that this will cause more eye strain
anyway, got bit side tracked from the channel topic again
it's just, Unity's UX team triggers me always with their decisions π
it's like one step forward and two back
to get back on track
anyone else noticed Unity leaked latest DOTS packages on the hackweek repo? π
like, the wip ones for Entities, Unity Physics etc
this is where I saw the terrain collider
but apparently, they realized that now as the repo is actually now gone π (probably moved to private)
ah, they hid all the other hackweek repos, they probably didn't mean them to show up in the first place
I did manage to clone it before it was gone tho :p
was mainly interested on the DOTS gamejams they made, they had two projects there, other was some voxel game for full ECS and other I think was some 2D Tiny game using DOTS mode
There's was a dots networking game they were working on too
I only saw the tweets about it tho during hackweek
@fathom trout , thank u very much for answer. IJobParallelForFilter is for filter some collection and return NativeList<int> of indexes that matches for your check. In code down bellow i have CompAJob that prepare Queue of entities that matches the check and then pass it to OverHundredJob. To access data in OverHundredJob i use ComponentDataFromEntity. Is it ok to do it like this?
struct CompA : IComponentData { public int value; }
struct CompB : IComponentData { public int value; }
struct CompAJob : IJobForEachWithEntity<CompA> {
public NativeQueue<Entity>.Concurrent overHundred;
public void Execute(Entity entity, int index, ref CompA compA) {
compA.value++;
if(compA.value > 100)
overHundred.Enqueue(entity);
}
}
struct OverHundredJob : IJobParallelFor {
[ReadOnly] public NativeArray<Entity> overHundred;
public ComponentDataFromEntity<CompB> compB_CDFE;
public void Execute(int index) {
compB_CDFE[overHundred[index]] = new CompB { value = ... };
}
}
yes, imo perfectly fine. The main reason it wouldn't be is that it when you access data this way (i.e. by entity), you lose linear memory access within a job (i.e. you start cache missing). Sometimes that's just what's required. Other times you may be able to change the data layout to be more optimal but that can be very tricky.
@amber flicker , in my game i have to update CompA every frame, but CompB should be updated just when CompA comes to 100, so to optimize race conditions i prepare entities for per entity access and schedule job for CompB only when i need, avoiding readwrite access to CompB every frame. I think that manage of race conditions more important then linear memory access in that case, when i have other systems that can access to CompB
CompA & CompB are not on the same entity, correct?
@dull copper is .3 fully using ui elements everywhere? kinda looks like it
really wish they would push it out quicker
hmm @frosty siren ok.. so.. it sounds a bit confused... the readwrite access & race conditions is what ECS should be taking care of for you - e.g. through use of the JobHandle you return in OnUpdate so I'm not sure I follow your reasoning. Also for the entities that contain both CompA & B, ideally you'd be doing that without a CDFE but that's only if you're goal is max perf
@amber flicker ok, here the case: If i will make readwrite access to CompA & CompB every frame in job A, and the second job B would make readwrite access to CompB, then they will never be executed in parallel.
But if i will split first job A to AA & AB, and schedule the AB only when i really need to access compB, then in 99% of frames AA & B jobs can be executed in parallel. Am i misunderstood something?
@low tangle I think the earlier ones used it for a while too
but I haven't checked on those
So I'm trying to use the Multiplayer netCode to have multiple worlds, but currently it only registers Systems that are manually marked with Client/ServerSimulationGroup attribute into the worlds. In their sample from what I understand they don't have anything form the scene from the start except the system that conencts the client and server, and doesn't seem to use the Transform system at all, and uses their own rendering. I know I need the TransformSystems in worlds to get physics going, but are the other systems not required to have in Simulation worlds? Is there anywhere I can lookup what these systems do? (image of Astroids demo of default world.
@mystic mountain the MP stuff isn't really ready to be used... at all
it's very basic atm
also depending on what you mean by multiple worlds, it already has support for that? i.e. several client worlds in the same instance for debugging, etc.
@trail burrow Yeah, sure. But I feel like it's better to puzzle it togeather and update frequently than to try go hybrid which has its own cluster of problem and no focus. Looking at their network guide, as my project wont dev out until 20+, it's better to deepdive into this. So yeah, they have multiple worlds, but they don't add default systems to all worlds for some reason, only Begin/EndSimulationEntityCommandBuffer. So I kind of guess if I just add all systems that are in the default world to all simulation worlds it should work fine?
@mystic mountain So i just looked through their networking code a while back
From my understanding they created their own world and constructed the systems specifically for client -> ClientWorld and the same for the ServerWorld
Yeah, there is one thing I don't really understand though. They create e.g. a ServerWorld, create a SimulationSystemGroup in that world and adds systems created in that world with the tag. Finally they Sort the update list and add it to the update list of a TickSystemGroup that is created in the default world. Do you have to run your seperate worlds systems through the default world or why would they do this?
Let me install 2019.1.x and take another look at it
So I'm not exactly sure why the TickSimulationSystemGroup would need to update specifically in the Default World, but it there aren't any systems tht are registered to the default world for those groups
Check the clientServerBootstrap https://github.com/Unity-Technologies/multiplayer/blob/master/sampleproject/Assets/NetCode/ClientServerWorld.cs
So at 345 you see they add the "serverSimulationSystemGroup" to the "TickServerSimulationSystem" of the default world.
Hmm interesting
I'll need to play around with it a bit more on the weekends, but it looks like the usage of the Default world is to construct and register systems, if you comment out 345, the server world's systems aren't created π€
this is if you're running on specifically a server via the playmode tools
Hmm, yeah. So how how would you add a system otherwise to the playerLoop that is created from another world?
Systems are specific to the world they're made in
Well for most intensive purposes, what I'm doing is in my tests are:
var prevWorld = World.Active;
World.Active = new World("CustomWorld");
World.Active.CreateSystem(...); // This may not take into account SystemGroups (haven't checked yet)
And if you're following 'true' ECS, they shouldn't care about anything except stuff(ie. entities) in their world
Hmm.. ok. Well then I'm at a loss. The only thing I see is.
serverSimulationSystemGroup = serverWorld.GetOrCreateSystem<ServerSimulationSystemGroup>();```
So why isn't this creating the systems by itself to the player loop then hmm...
Single responsibility principle?
Get-or-create(specific thing) should only ensure that specific thing exists, but not even its dependencies
There's the only place where it's created. So you say if we change that to a "create". It should pop up in the player loop.
Hmm. Didn't work for me. Maybe I understood it wrong.
Create (system group)
Create (system1)
create(system2)
etc?
I don't know how it works under the hood, and haven't worked much with worlds and system groups, though.
@mystic mountain if you do something like this and wanna register it to the server world you certainly could, but I'm on the same boat as @tawdry tree, I haven't played too much with the worlds/systemgroups API too much.
serverSimulationSystemGroup.AddSystemToUpdateList(serverWorld.CreateSystem(typeof(FakeSystem)));
Is it ok to allocate containers inside jobs and then use them outside?
I would also like to say that, the systems in the samples are automatically created via the default world, and in my FakeSystem i disabled AutoCreation @mystic mountain So it's likely that they're simply transferring the systems from one world to another world too
The correct way would be to allocate first, or do a calc for size in job and allocate after, I believe. Depending on needs.
@frosty siren you could do it via unsafe code and storing a pointer...but allocating first is usually the right idea π€
@tawdry tree , @coarse turtle thank u
Find out how much you need, then allocate. Which might mean you want to run a job for that first, but yeah, no allocation in jobs.
Yeah, u understand me right)
So much noob questions i ask today, i'm sorry.
I'm in case when i have IF at start of my OnUpdate, inside of which i schedule a job, and at the end of OnUpdate i schedule a job too but without IF. It's look like
protected override JobHandle OnUpdate(JobHandle inputDeps) {
JobHandle resultJobHandle = ???;
if(...) {
var jobHandle_A = new SomeJob_A{...}.schedule(inputDeps);
resultJobHandle = JobHandle.CombineDependencies(resultJobHandle, jobHandle_A);
}
var jobHandle_B = new SomeJob_B{...}.schedule(inputDeps);
resultJobHandle = JobHandle.CombineDependencies(resultJobHandle, jobHandle_B);
return resultJobHandle;
}
```So i stack at how i should initialize resultHandle
```csharp
var resultHandle = inputDeps;
```or
```csharp
var resultHandle = new JobHandle();
@frosty siren you chain all of them with input deps
You should return whatever handle best represents the system, which usually means chaining
inputDeps = new Job2().Schedule(inputDeps);
inputDeps = new Job3().Schedule(inputDeps);
return inputDeps;```
if you dont know what you are doing
that is the safe way
Usually as in, "unless you somehow have a big branching tree", but if you have you should be asking yourself why.
But yes, +1 to fholm's more straightforward answer of making a direct chain
Ok, i think i got it, thank u all
@coarse turtle What you mentioned was an add to the "serverSimulationSystemGroup" which is added to tickServerSimulationSystemGroup, or did you comment that line out and still made it work?
I did not comment that line out
I'm trying to optimize my system work and i can't figure out how i can dispose containers without forcing JobHandle.Complete() (except NativeArray).
As i can understand the only way to prepare array in parallel jobs is to use NativeQueue or NativeMultiHashMap, cause only those containers have .ToConcurrent(). Also after filling NativeQueue i need to transform it to NativeArray to be able to access it in parallel. And in the end i need to somewhere dispose NativeQueue. All of this looks dirty.
I also understand that i can dispose my queues at the start of OnUpdate, but in my case it's impossible.
So what the most clear and best way to schedule disposing of your native containers?
oh, found this reply from Joe from two months ago: the burst compiler will support cross platform floating point determinism end 2019 / early 2020.
I didn't realize they set it that far back
it was initially estimated to arrive last winter and then spring 2019
4. Is the new DOTS Unity Physics deterministic?
4. It deterministic but not yet cross platform deterministic since burst does not support cross platform float determinism yet.
I'd take that reply with a grain of salt
how I'd read that is that DOTS physics is deterministic by design but they can't yet guarantee it with Burst
interesting π€
also crossplatform can mean many things
if they can guarantee Burst is deterministic with the same build regardless of the cpu achitecture, that would be great already but I somehow don't think that's the case
i have this system thats creating entities to render stuff with, right now im just storing the result of
PostUpdateCommands.CreateEntity
but this seems to have some problems when i try to actually use that to get, say a RenderMesh so that i can update it
from what i understand, PostUpdateCommands returns an Entity with an Index that is negative of the actual value, say -1, then when the command buffer is actually evaluated at the end of the frame, the new entity is actually assigned positive 1
so to fix this do i just need to negate the Index that i get from PostUpdateCommands.CreateEntity ?
i don't access the new entity until the next frame so im not worried about creating and using it via PostUpdateCommands in the same frame
i tried just negating the index and that just throws a ArgumentException: The entity does not exist
Hey all,
If i want to run some code before ComponentSystems start, how do I do that?
this makes me sad
Joachim just replied to the DOTS editor thread on the forums: ```Our focus is on making the GameObject -> Entity conversion workflow production ready.
We will do a lot with visualizing converted state, warnings / error overlays in inspector, live conversion, asset database caching, player live connect over the next half year. ```
I mean, it's "nice" that you can convert but it feels so dirty and hacky
I'd rather have full blown DOTS editor that works
I guess the reason for this is that they can't make entities package production ready this year with the full editor, so they need to come up with something else so they can market this at bigger studios etc
Why is this
entityManager = World.Active.EntityManager;
causing an object reference not set to instance of object error?
only broke when i upgraded my project to latest beta
@dull copper seems like such a hack
it really feels like like something they had to make to reach some target
but would have still wished they took different path
conversion workflow felt like nice temp workaround to get things done but I'm not really happy about them putting this much focus into it vs the actual dots editor
originally it felt like it was fast way to try new things but when it goes to polishing it, it's totally different thing
@upper tiger if u talking about running code before specific system, then i think u can use OnCreateManager()
But if u want to run some code before all systems starting then probably you should create World manually
I guess I want to create a reference that multiple systems use, such as the terrain. So at the start I find the terrain, get a reference to it and store that in a static variable that is accessible from all systems
but it has to happen before those systems load otherwise they will try to run code with a null terrain variable
Most people will probably go for a hybrid approach because most people just don't understand ECS yet. That's probably why that's their focus.
@upper tiger in my project i successfully call Start() on Mono and get all required references before systems run
why not to use mono and then just destroy it after start work?
I think I can use
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
say I have 10 systems, which OnCreateManager runs first
Not sure, I'd assume they get run in the same order the system updates do.
maybe, but i still need to control that
You can control that order.
oh I didn't mean hybrid couldn't exist, it has to exist for the time being
but if they would have made DOTS editor extension so that it could coexist with the gameobject scene editor, it would make the transition or using both seamless
now we just keep getting things that exist only on one side and get full editor open only for one side
it's so far from what it could be
if they did that, there wouldn't be need for more advanced tools to show the temp phase
they could just focus on the real editor and moving the two things between in seamless fashion
"We will do a lot with visualizing converted state, warnings / error overlays in inspector" <- stuff like this wouldn't need to happen, we wouldn't need to author entities in gameobject side to immediately convert them over when game starts
we could just author hybrid things on gameobject side and entities on DOTS side from the start
I personally don't even use any of the conversion api
my core game is started from a preload static method
which creates the entities needed to kick off the rest of the systems
hybrid objects are created and managed by systems way later on in the api
how do you preload a static method without a game object?
You can do a Bootstrap class.
for example
yup ^
public static void Initialize()
{
}```
oh right, I do that then augment it with a in scene settings object, holding a bunch of random stuff
but thats only for the editor version
internal class SceneStartupSettings : MonoBehaviour
{
public enum EditorStartupMode
{
None,
Server,
Client,
LocalHost,
AutoJoin
}
public EditorStartupMode EditorMode;
public string AutoJoinIP;
public ushort AutoJoinPort;
public bool NoSteam;
public bool NoDiscord;
public bool ForceVR;
public bool Oculus;
public bool Vsync;
public bool LogExtra;
public bool DisableUI;
public string User;
public string Password;
public string WorldGUID;
public string PlayerGUID;
public string VersionOverride;
}
but personally I'm thinking about moving to two scriptable objects, one for base game, second one for editor only values (overrides for my api, and disabling things)
I already use a settings.ini system I wrote as well. these are mostly for static asset refrences without going to resources.load
back in the init method, I store some globals for faster lookup inside of the MyGame.Systems namespace:
//Grab the auto created world
World world = World.Active;
ECS.EntityManager = world.EntityManager;
ECS.DefaultWorld = world;
ECS.PlatformSwitchingSystem = world.GetOrCreateSystem<PlatformSwitchingSystem>();
//Create singleton data
var ent = ECS.EntityManager.CreateEntity();
ECS.EntityManager.AddComponentData(ent, new RequestSettings { MaxRequestsAlive = 100 });
new Entities package must be close, we've gotten new version each month this year but this one, so it's probably going to release soon
I guess the biggest change will be the option to add/remove components and entities inside ForEach lambda
i used to be able to remember from comments what the new package would have but i cant remember whats what for the next one
well, that was actually from the leaked entities package from one hackweek repo :p
they got dots master there
the physics package change is bigger as they changed the api a lot
I still dont get why they dont keep that repo open for all
too many people complaining that stuff isnt working maybe?
I dunno, SRPs have dev branches on github along with other unity feats
i wish they had a community manager for just dots stuff
or like, roadmap with proper estimates π
squeeze some more info out of em π
like even four quarter estimates
lol almost asking too much
we do know somewhat around that ballpark on when things are going to land
but that info is scattered in random places
yes that squiggle graph π
not a bad idea
also, wasn't the havok physics announcement meant to happen in June? or was it July...?
I think they only said this summer
https://blogs.unity3d.com/2019/03/19/announcing-unity-and-havok-physics-for-dots/ said: The Havok Physics package will be available later this summer.
ah, https://www.havok.com/products/havok-physics/ says: We are working closely with Unity to develop an officially supported Havok Physics integration for Unity. This integration will be made available in June 2019.
oh, I was simply thinking about the announcement itself heh
well, one shouldn't put that specific deadlines that far away in the first place, they never stick π
I can also see many issues in the plan
where was this hackweek repo? π΄
basically they want to keep unified API for both new Unity Physics and Havok integration, but Unity Physics package is still very alpha, so it's API will evolve
and this means that if they publish Havok integration they need to constantly change that too then
it feels like a thing that should have been done only after they figured what all Unity Physics needs
@safe lintel it was on the main Unity github, but it's gone already
they cleaned most of the hackweek stuff from there at once (probably just set them to private)
doh
what about the renderer stuff?
from here
would def like to know how that works
I'm super puzzled about the current Unity's rendering plan
they are about to get HDRP out of the door
but it doesn't utilize any new DOTS perf improvements
and it's very likely that at some point DOTS will have a dedicated renderer that is not HDRP
but developing new HD renderer for years just to have it being replaced after just few years after release sounds super silly as well
@dull copper the render pipeline can have parts done in DOTS
the work on the whole render pipeline stuff isnt the same as DOTS renderer
in fact, most of the hardest work is on the shaders and visual effects
and those are in glsl/whatevre
you'd think, yeah
in hdrp, they heavily utilize compute shaders
but they've actually gone bit back to more traditional shaders on some as just stuffing everything on gpu compute didn't bring the best perf
but for example, current DXR's experimental version is heavily CPU bound
of course that doesn't reflect how the final version will be, we'll see if it's still cpu heavy on next falls HDRP
unity has a very interesting powerup on the DOTs stuff
making it simpler to create highly parallel code is a huge deal
I was wondering, is it possible to Blit without freezing the engine ?
Hi guys. I'm Trying to call Camera..WorldToViewportPoint() from an ECS job but its saying It can only be called from the main thread. Is there any way around this? Google yields no details how to implement it myself and it's natively implemented so no source.
@gusty comet unfortunately this is what's expected with the hybrid workflow (any access to monobehaviours needs to be via main thread). That said, doing it once per frame shouldn't be too bad? Unless you have thousands of cameras π
FYI you can call Camera.WorldToViewportPoint() in the system's OnUpdate and pass it to your job
Hey i was wondering, is the system timing in the entity browser/viewer ui (i forget what its called) taking into account the duration of jobs scheduled or is it purely what happens in the update method.
@amber flicker I can't just call it outside, I am doing it in side a job, for each of potentially thousands of components. That's why I asked for how to do it manually.
@gusty comet so you do have thousands of cameras?
no thousands of units.
oh I see
you pass a different position to the method for each
gotcha
so if I knew how to do it myself, I could do it in the job in my loop
yea.. so I don't know off the top of my head the maths to recreate it (but you could start here https://answers.unity.com/questions/822464/reproduce-worldtoviewportpoint-function.html) - it does strike me as something you might not really want to be doing though? Can't work with things in world space instead?
I am doing this for another dev actually, who insist he must do it this way
I'm gonna talk to him again, I had the same thought
Cool - understand there are reasons to do things a certain way sometimes but I have a feeling that could get a bit expensive quite quick... good luck!
Is it possible to create an archetype from a prefab?
Any of you code/script terrain tools?
omg, to dispose NativeArray after job we should use [DeallocateOnJobCompletion], to dispose NativeList we should use NativList.Dispose(JobHandle). Why so chaotically?
@knotty quail you got questions?
@flat scroll, yeah there is a low poly terrain editor that is depreciated from two years ago, and was hoping someone might be able to fix it and make it compatible with newer version of unity.
I don't think this is the correct place for that, even if any of us were. Maybe try #π»βcode-beginner ?
I tried there, it moves pretty fast and gets buried so no replies other than a self proclaimed 15 year old that tried for 3 minutes, lol.
π
ah, you posted that in #β°οΈβterrain-3d. hadn't read that yet
Yep, wasn't sure programmers paid attention to that either.
mostly me haha
from unity at least
but there are a few programmers that chat there
I am surprised I haven't seen a good solid low poly terrain editor go into the unity store and I have been on and off with unity for years.
Does the new terrain system have the ability to toggle flat shading by chance?
I don't want to use a custom shader as they can be resource intense at that scale and pop like crazy on LOD's at lower settings. π¦
I'll try to answer these back in the terrain channel
Thank you
I have an error:
The previously scheduled job Utils:QueueToArray1 writes to the NativeArray QueueToArray1.queue. You must call JobHandle.Complete() on the job Utils:QueueToArray`1, before you can write to the NativeArray safely.
Little bit confused, cause field "queue" is not a NativeArray, it's NativeQueue.
And also my second job scheduled with JobHandle of an prev job, so it will start write to queue only when prev is completed. I guess there is some attribute for this kind of problems.
Did you properly queue the jobs?
Meaning something like:
var jobHandle1 = job1.Schedule(inputDeps, eventualOtherArgs);
var jobHandle2 = job2.schedule(jobHandle2, eventualOtherArgs2);
yeap. i chained all with inputDeps, so it can't be wrong
Wait, you made ALL of them depend on inputdeps?
yes, like
inputDeps = job1.Schedule(inputDeps, eventualOtherArgs);
inputDeps = job2.schedule(inputDeps, eventualOtherArgs2);
Ah, you just override inputdeps, that works. It sounded like maybe you scheduled both jobs after the original inputdeps, which would be a fairly obvious cause for that issue.
i have no problem with jobs that access to the same native container except this two. But the difference is this jobs both WRITES to container
@mystic mountain only just saw your post
not sure if it's the right way but
you can put a ConvertToEntity behaviour on your prefab together with some script that adds the wanted components on conversion and then
Entity sourceEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(myPrefab, World.Active);
then you can use that as archetype to instantiate your entities
however sourceEntity gets instantiated too i think so far as i know you gotta use destroyentity on it when you're done, not sure if that is the intended way to go about it so anyone feel free to correct if there's a better way
I have a an Entity prefab created with with ConvertGameObjectHierarchy and on the game object to be converted is a monobehavior with IConvertGameObjectToEntity that adds an extra ComponentData to the Entity.
The resulting prefab entity does include the additional component. However when i EntityManager.Instantiate the prefab in a system, it uses the wrong archetype, excluding the extra component. Anyone been through this or found a workaround? I am quite confused.
basically my goal is to use ConvertToEntity but have the resulting Entity include a few extra Components (and not add them manually after instantiate)
Hi everyone, was hoping I could get some input on a somewhat architectural problem where I feel I am digging myself down a hole. Essentially, what I want is to have an entity with a component that contains a complex structure; a collection of bounding box grids (layered according to size, so essentially List<List<AABB>>). However, due to the requirement of primitive and blittable types I haven't really found any good ways to get that into a single component (I have some ideas for bad ways). Anyone have any ideas on how I could do this?
Essentially what I would need would be a way to create a 2D Dynamic Buffer
(Jumping back to monobehavior for this data structure is a valid option and I am currently considering it, just wanted to hear here first)
@gentle osprey
Could you use dynamic buffer components (https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/dynamic_buffers.html )?
I did try using dynamic buffers, however, then I can only get 1 dimension.
I can, but I am already 3D to 1D indexing in there since its a 3D grid, and adding a 4th dimension wasn't really what I was hoping to do.
The thing I am sort of thinking back on is whether or not I actually want this thing as component to begin with, or if it should really be a system almost. I mean, I will never have more than 1 of it, and outside of visualization for debugging I am only using it for queries.
I am new to Unity ECS myself but if you only ever have one of it and it is complicated like you say then making it a system may make sense, but can't comment much beyond that without knowing more.
@gentle osprey have you considered one entity per AABB? Is the idea that a cell in your 3d grid has multiple AABBs?
Can i use ECS productive?
It's for a streaming system (streaming stuff off of disk). Essentially its just a spatial querying structure (like an Octree almost). I will just be using it to check if a player is within one of the cells then use that information to load in the rest of the world. The voxelgrid has several sub grids (for reasons), which is why I would like a 2D approach, so I have a collection of layers of VoxelGrids.
@amber flicker I tried such an approach, the problem is that I need to know what index an AABB is within the grid.
Honestly, I do something similar (though it is 2D) and I use a system to do it
Can you hold your data structure somewhere else, and store an integer index into it inside the component?
@gentle osprey Not sure I can be of much use but I wonder if (re?)looking at the boids or even the physics broadphase might be helpful? e.g. the boids hashes the position
Hi all. It's a weird to ask this here but, i'm not doing any ECS and i'm getting this sometimes
To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp. This will output the callstacks of the leaked allocations```
in a standalone, master server stuff process in cmd (MSF does use multi thread in this, but still, no ECS). Looks harmless, but when i Ctrl+C, it crashes. This is probably unrelated, but i'm just trying to debug. Why i'm getting JobTempAlloc stuff?
Yes i'm using PostProcessing.
And whats worse is, this only happens sometimes... and when this happens, something else that should happen is not happening
Ah, Discord came back up again, cool. Great idea @fallen sleet, I'm going for that one :) (or at least a variation of it), thank you so much for your help people :)
@stoic monolith
I get that problem too. I think it may be a bug (someone correct me if I am wrong)
But you're doing ECS, right?
Oh yeah, I am. But it doesn't always start happening after chanigng any ecs stuff. Do you know if there is any job usage?
I have had a similar problem actually, was wondering if it was a bug. I had a leak, got that message, fixed the leak, but the message doesn't dissapear until I have restarted unity.
None at all except maybe from PostProcessing.
And this is from a standalone build, so maybe i should try restarting PC?
But then again it's set to server build, so it's headless, no graphics. Not sure if it'd stop PostProcessing.
How NativeMultiHashMap.GetKeyArray() works?
it just does
nobody knows?)
the guys that wrote it probally know
kidding, it just returns a native array of the keys? what do you not understand about that
I mean how it's generated.
the array of keys is not stored in the hashmap, isn't it?
I mean hashmap of course contains all keys but with split lists, and i don't know how it's implemented in DOTS (actually i don't know hashmap data structure well), so i worry about perf. But based on your words i think it's just simply connects all keys into array)
Just a question before freezing π Can I use NativeArrays in ISystemStateComponentData ?
I am getting some reasonably intense jagged edges after rotating a quad mesh with the Rotation and Rotation pivot components. Is there something I should be doing to avoid this?
And if I am trying to rotate around the centre of the quad is the pivot even necessary?
Which tutorials to start with ECS do you recommend?
none
they are all outdated
@shy garnet
but if you start with something, look at least the official manual & docs
they are linked in the pinned message in this channel
ok, thank you very much, I knew it was difficult and if I tried to search it by myself I was sure it will be outdated xD
I'm a bit confused about Burst and the whole stack
Unity Technologies says how awesome ECS and Burst are, how they are more performant than the same code written in C++
However, this only applies if all of your code is in ECS, with Job systems and those Jobs compiled with burst.
Otherwise, ECS code compiled with IL2CPP is 2-3 times slower and ECS code compiled with Roslyn is further 2 times slower than the IL2CPP build.
How can this be considered a nice thing? Burst is not supported on all of the platforms (looking at you, nintendo switch) and it is not supported in non-jobified code.
Just imagine: Unity says how good their new DSP Audio System is great and dandy, but all of its speed depends on burst.
What's the deal with that?
@fringe sinew the idea is that you will always use Burst
and currently, DOTS is quite barebones, so it's not really good to compare it to existing things directly
Unity hasn't said this is thing you should jump into today
in fact they've said it will takes years for this to be a thing you should really use
But I'm still quite confused. Burst seems such an afterthought, easily breakable in the process. It all seems like IL2CPP all over again which can't compile half of the time on consoles
I don't understand this at all tho: Otherwise, ECS code compiled with IL2CPP is 2-3 times slower and ECS code compiled with Roslyn is further 2 times slower than the IL2CPP build.
"ECS code compiled with IL2CPP is 2-3 times slower ", slower than what?
" and ECS code compiled with Roslyn is further 2 times slower than the IL2CPP build.", wasn't this what you compared the first one against?
I totally missed the point here
According to their own blog post and Aras' blog about a C# raytracer, Aras' profilings show that a NET Core version of the code runs 2-3 times slower than the C++ code, IL2CPP code in unity runs comparatively to the NET Core version and the unity Mono compiled code runs 2 times slower than IL2CPP and NET Core code
Burst is one of the core things on this whole concept, it's what enables a lot of things, it's not just the perf either
burst gives them full control over the compiler, they can do determinism, handle precisions etc
uh, so you compare c# to c++ now
but we don't script in c++ with Unity in the first place
Not me, Unity themselves, in a blogpost about performance
it's only meant to give people some idea where these are at
the results you get vary a lot too depending what you actually do there
When I (and they) talk about C++ and NET, they meant about the code outside the unity, to test later how it compares to Mono and IL2CPP builds in Unity
2-3x slower doesn't mean anything in DOTS
it's like totally irrelevant info
you can get 50-400x speedups with ecs + jobs + burst
nobody cares if you get 2x slower code if you only use it for C# ECS vs c++ code comparison
I think you miss the point of the blog post I'm talking about.
as that's not the intended use case
I know the blog post, I've read it
but you really need Burst for this all to work well, and doing perf comparisons without it is just silly
I understand that we'll need it, but, as I stated before, I'm just confused about such a decision behind burst
For example, it's JIT only, compiled at the start or the first schedule. How can that be a good thing?
have you read this? https://blogs.unity3d.com/2019/02/26/on-dots-c-c/
Of course, it's to these blog posts that I'm referring
You completely miss my initial question here.
I am confused behind the decision of Burst.
but that's explained on those blog posts?
there are some Unite talks too that explain more about the reasoning behind it I suppose
C# is for speed at development phase
IL2CPP is to make the active code you got from C# more performant
DOTS is a way to sort data to have an improve of performance over other orientations
All of them are improvements, and all of them will run independently.
*IL2CPP isn't about perf at all
Isn't IL2CPP more about platforms?
oops I missed that then xD
I thought it will be improved to have better perform through getting the benefits of a CPP compiler
I mean yeah about platforms is a need, but about this topic about performance it's involved too
there were 2 big reasons for IL2CPP originally: to get AOT builds for IOS as apple didn't allow JIT anymore and other was to be able to run emscripten (to convert c++ to js) so they get webgl builds (after chrome banned Unity's webplayer plugin)
and after that, it was used on other newer platforms that didn't have support for Mono version they had
nowadays Unity has many platform targets that only support IL2CPP as scripting backend
First of all, it is JIT only. Why is that? That can't be a good thing a lot of the times because of code modification. Why isn't it AOT?
Second of all, it compiles directly into native code. Alright, what if I try to run my old game somewhere with a new architecture (a new SSE iteration perhaps)? How will that do? Mono will surely compile fine, IL2CPP and UE4 games will also be probably fine, but what about Burst's JIT?
what is jit only?
If I am not mistaken, Burst code is compiled at runtime on the target machine.
When working on your projects in the editor (play mode), burst works in a Just-In-Time (JIT) fashion.
However when you build your project into a Standalone Player, burst will instead compile all the supported code Ahead-Of-Time (AOT).
they had some chart about JIT / AOT between all unity things somewhere but not sure where it was
but there is this at least: https://docs.unity3d.com/Packages/com.unity.burst@1.0/manual/index.html#burst-aot-requirements
In short: JIT in editor for speed, AOT on build for perf
Is what I'm taking from those quotes
today, Burst also builds for example SSE2 and SSE4 both for windows builds and it picks up the one that your computer supports when you run it
I guess it's same with linux and macos
TIL about that IL2CPP thanks xD
and as for new CPU's, you don't have to do anything
we already have extensions like AVX, AVX2, AVX512 that are not on all cpu's. of course you'd need dedicated support to enable these but older extensions still work on these cpu's. Practically every PC that can run Unity, supports SSE2, Steam's hw survey says 100%. For SSE4 the figure is ~96% (due to old athlons, phenoms and pentiums lacking support for it). But if new cpu comes along it will definitely support both of these.
I've been asking for AVX support on Burst for quite a while but it didn't really make much sense in past when Burst didn't build for multiple extensions yet
@fringe sinew ive made an open source unity-style ECS
ive also made a boid flocking system
its 10 times slower than unity boids sample
and thats running on a custom engine where i use instanced rendering to render the entire scene in 1 drawcall
the burst thing is really felt
it does generate faster code than C++ in nearly all cases. In fact, if it doesnt, its considered a bug