#archived-dots
1 messages Β· Page 231 of 1
If the float values do not change, that means that the UnsafeLists are aliasing unintentionally due to the new array's default pointers.
And if you want to just skip all these confusing type and memory issues, just malloc your own 2d array
Had to disable the rest of the function to test that since there's a few bits that rely on it being a list, but doesn't matter since it still seemed to be reproducable with the follow up disabled - using NativeArray with UninitializedMemory, the values in the existing array don't change - NativeArray with ClearMemory and the first two floats are becoming 0f instead of whatever garbage was there before
My theory was that my UnsafeLists were getting disposed somehow, so the temp allocator was returning the same memory to put the new NativeList/NativeArray in, but could you explain more what you mean about the default pointers aliasing if this lines up with what you'd expect?
the values in the existing array don't change
As in it's still causes the read again to become garbage?
So I'm Destroying Enemy entities when they die, but then I have some of leftover references to that that entity in a buffer of targetdata.
Anyone know a clean/nice way of removing these items from the buffer? if not I feel like i'd be iterating over every buffer of this datatype to find the ones I have to remove
With UninitializedMemory - no corruption, values stay the same between A & B
(although I'm not doing anything with the array after yet, just throwing out of the function)
Unity ECS / DOTS does not search for references of entities that were previously destroyed by design. One of the core design philosophies is "no callbacks". So yes, you either have to make a system that continuously scans for destroyed entities and removes elements if the entity it references is destroyed or some other method.
No corruption, right. As expected. Yea, the UnsafeList pointers are aliasing with each other unintentionally.
k. I think ill just add the extra overhead when I destroy the entities, instead of a system that polls for it
You have to think about what is going on when you create these containers. They're just pointers to buffers. If you nest containers within a container, a NativeList<UnsafeList> becomes a pointer to a buffer filled with pointers
Pointers do not ensure that the memory chunk they are pointing to is "unique". Well C# pointers at least. So NativeX has a massive number of code to make sure it is.
To prevent "aliasing", or when two or more pointers point to the same chunk, or same part of a chunk, or memory.
When you create a NativeList<float>, float's a value type so it gets allocated a memory chunk that can be read and write to directly. No worries about aliasing. However, when you create a NativeList<UnsafeList>, that UnsafeList is another pointer. The first pointer to the "chunk" of memory is not aliased, checked by the creation of the NativeList, but that second set of pointers, the UnsafeLists, are not checked.
And when an UnsafeList is created, even if it's not new UnsafeList, it's a struct type so it needs to be initialized to default values.
That means a lot of null, 0, or whatever default needs to be written there
So when you create a NativeList<UnsafeList> without UninitializedMemory, it overwrites anything previously there. And doesnt notify any other pointer currently pointing to that chunk of memory because how could it know. It doesnt check.
And if you want to use NativeList, use [SkipLocalsInit] as a tag on the struct of the method. It's the same as UninitializedMemory but for all variable inside the function for Burst: https://docs.unity3d.com/Packages/com.unity.burst@1.6/manual/docs/OptimizationGuidelines.html#skiplocalsinit-attribute.
Of course, that doesnt "fix" the problem of aliasing UnsafeLists. If you were to create and then allocate the UnsafeLists in the NativeLists, then there's a possibility it may re-alias and you get the corruption again... probably not though.
Slightly confused still sorry, hope you don't mind if I get you to clarify where my thought process is going wrong here
it's a bit of a rabbit hole, dont fault ya for not understanding what's going on in there
I create a NativeList with a capacity of say 10 using the temp allocator - the list asks the temp allocator for enough memory to store an array of 10 pointers to the UnsafeLists - but these lists don't actually get created yet. (they should just be unitialized pointers / pointers to garbage?) The temp allocator shouldn't allocate memory it's already given out to something else, so there shouldn't be any possibility for corruption here unless I've already told the temp allocator somewhere that memory is safe to give back out?
where is my understanding going wrong there? π
(thanks btw)
What's the best way to remove an item from a Dynamic Buffer? I only see Clear() or RemoveAt(). I'd like to use RemoveAt but on a command buffer....
You are correct in that creating a list of 10 UnsafeLists creates 10 pointers to "uninitialized" UnsafeLists. But remember, UnsafeList isnt just a malloc buffer, it has a lot of other "status" variables like length, another pointer to it's buffer (which is the malloc buffer), and more. I think it's a size 16 struct.
Now if UnsafeList was a class, your assumption would be correct. The NativeList would be filled with null pointers that wont conflict with any other current memory allocations and you wouldn't have a problem. But UnsafeList is a struct. That means it's a value type that must, by default, first clear out a space in the memory for it to use. Even if it's not initialized to any value.
The UnsafeLists' buffer pointer will be null, it's size would be 0, and so on. But that still requires space in the memory to store that data.
Following with you there, thanks - but why is that data ending up where my other data is? π
Now NativeList checks if it's pointer and buffer does not conflict with other data in the stack (Allocators is just one giant unmanaged memory chunk). It does not check if the UnsafeLists' pointers do not conflict with another data's pointers. Now this is where my knowledge gets a little fuzzy.
Give me a sec to look at the source code
What is the allocator of the original contour list?
TempJob - allocated from before the job is fired off & passed into the job on construction
TempJob and Persistent use the same memory chunk. Temp uses a different chunk. Temp is extremely compacted which may mean aliased buffers but TempJob and Temp should not be close to each other.
but the lists within it are Temp
Ah, there ya go.
(which are the ones getting overriden)
This is not documented anywhere by Unity but tests by another programmer characterizing the Allocation memory buffers shows that Temp is extremely volatile and packed together. A lot speed and you dont need to dispose of arrays allocated in Temp because it is very easily overwritten
Let me see if I can find the article
JacksonDunstan.com covers game programming
JacksonDunstan.com covers game programming
Now this is what I think is happening, I have no proof because this is all engine code.
When you create a native container with same stride / alignment and size (like contour and contour2D), the Temp memory buffer thinks "oh, look at these already pre-aligned and allocated memory the same size and stride as the new one the programmer wants" and overwrites it with default junk data
Yea im pretty sure their extern malloc also has some additional logic to handle the different allocation strategies (I want to believe that it's a simple bump allocator - but no proof from my end π€·)
This "eager" buffer allocator allows for "internal" array allocation that do not need to be disposed of within the job since it just "reuses" same stride arrays from previous jobs assuming it is no longer needed
The UnsafeLists allocated in Temp outside the job are simply being reused without your permission and without notifying the original arrays, resulting in the pointers now pointing to junk.
Simply change the UnsafeLists of the external Contours to be TempJob and it should work without UninitalizedMemory
See, I'm agreed with you up to there - I can't see why the lists would be getting reused if I haven't disposed of them yet
It's a "feature" of Allocator.Temp arrays. They do not need to be disposed.
They're invalidated automatically by the engine based on who knows what parameters, never documented and it's in C++ binary, so it may be doing so too eagerly
Since they're only valid for within a frame, you can technically not dispose them, but they shouldn't get reused within a frame? π€ This is all happening during one frame
Yep
Thats how temp allocated nativeX work in jobs. They're being created before the first job is run based on the number of threads available then reused by all jobs within a single frame
Theoretically, using UninitializedMemory, you might be able to pass information between two jobs within a single thread but the order and whatever else Unity is doing to it behind the scenes may invalidate it or throw an error.
how do you guys normally remove items from a dynamic buffer?
Ah right, your question. Depends on if you want to maintain the order of the buffer.
don't care about order right now
But if Temp stuff allocated within a frame could just be randomly sharing the same memory as something else allocated with temp... surely the temp allocator would be entirely useless? π
DynamicBuffer.RemoveAt/RemoveAtSwapback?
not seeing how it being initalized or not would make a difference here either, that would just change when it gets corrupted from when I declare it to when I start writing into it? π€
If you dont care about order, swap last index with the removed index then reduce the size of the buffer by 1. Extremely fast and no need for reorganization. I believe it's already implemented by unity with.... let me find it. Yea, remove at swapback
Who really know's what's going in Temp. from Jackson Dunstan: "There may be one fixed-sized block per thread, per job, or for all jobs but we donβt really know at this point. Even overflow allocations are allowed within the job."
so this can't be done with boost?
Boost?
Temp works, most of the time. But multiple temp allocations crossing Job and Main-Thread boundaries is very buggy, as you see there.
I have an ECB but I don't see a way of using it to do the action
I shouldnt. RemoveAtSwapBack simply swaps the values of 2 index's and then reduces the Size parameter of the DynamicBuffer by 1. Now if you want to compress the DynamicBuffer, that would be a structural change.
Give me a sec, I gotta check the source
The only operation I can see you use in your case, if you have an ECB is SetBuffer
that might be it
Yea, you need write access but DynamicBuffer (not the elements in it) has burstable RemoveAtSwapBack()
/// <summary>
/// Removes the element at the specified index and swaps the last element into its place. This is more efficient
/// than moving all elements following the removed element, but does change the order of elements in the buffer.
/// </summary>
/// <param name="index">The index of the element to remove.</param>
public void RemoveAtSwapBack(int index)
{
CheckWriteAccess();
CheckBounds(index);
ref var l = ref m_Buffer->Length;
l -= 1;
int newLength = l;
if (index != newLength)
{
byte* basePtr = BufferHeader.GetElementPointer(m_Buffer);
UnsafeUtility.WriteArrayElement(basePtr, index, UnsafeUtility.ReadArrayElement<T>(basePtr, newLength));
}
}```
Nothing there requires invalidating the buffer array provided by DynamicBuffer. So it's burstable. Now Parallel maybe not, depending on how you're structuring the parallel access
If you're doing the removal per entity and each entity does not access the buffer of another entity (aka not using GetBufferFromEntity), you can use RemoveAtSwapBack in parallel with burst.
hey, when y'all have a chance I have a weird beginner question:
so in OOP, let's say i'd make a script with a public void TakeDamage(float f) function, which would subtract from the object's hit points and perform some other simple tasks/functions like running a private void Die() method if the object was reduced to zero hit points.
as far as I can tell, it's redundant to do something like slap this function on a component, because components are only meant to contain data. how would this be accomplished in DOTS?
Entities
.ForEach((ref DynamicBuffer<Element> buffer) =>
{
buffer.RemoveAtSwapBack(14);
}).ScheduleParallel();```
it's redundant to do something like slap this function on a component, because components are only meant to contain data
You dont want to slap functions on components. Components should be data only. You can not call functions on components since all the ways to access components return temp values only.
Multiple ways to check for a Die. You can have whatever job add a tag component to mark entities to die (if the health component <= 0), you can stash entities into a temporary buffer and have a job destroy any entities in said temp buffer depending on the health. It's all dependent on what data you read and how you want to execute logic on said data.
Ok thanks, I must be fetching it in a bad way. lol
how would this be accomplished in DOTS?
Now in DOTS, you would have another entity attach a component onto its target like a "flag" stating that it has taken damage and how much. Then in a system scanning for these "flags", it then picks it up, combines the flag's damage with the target's hit points, and then remove the flag.
That is if you can not directly apply the damage to the target's hit point
i think i understand, this is more what i was looking for. so in other words, attach a component to the entity on "damage taken", then have a system dedicated to recognizing these components (and any values within them), and then running logic based on them?
because the point of this question isn't necessarily to deal damage and have an object die, it's to perform other logic on damage taken (say, spawning particles, factoring resistances, the like)
100%. That's DOTS. It doesnt need to be application or removal of components (since that is fairly expensive and locks up the main thread). You can instead have boolean toggles or bitwise flags in a persistent component.
Thank you!!! I think I worked out what the problem is - the temp lists are created inside of one job and put into the other TempJob list that's shared between two jobs, then consumed in the second job - the temp allocation from the first job is then getting released since that job is done, and then it rewritten in the next job when it needs to allocate things
interesting, that's a lot more intuitive than I initially thought.
in regards to this part though:
You can instead have boolean toggles or bitwise flags in a persistent component.
how exactly would this work? wouldn't I need to pass in a value for the amount of damage taken?
which matches up with the documentation:
Each frame, the main thread creates a Temp allocator which is deallocated in its entirety at the end of the frame. Each job also creates one Temp allocator per thread, and these are deallocated in their entireties at the end of the job. Because a Temp allocator gets discarded as a whole, you actually don't need to manually deallocate your Temp allocations (in fact, doing so is a no-op).
Ah. You did the forbidden thing. Temp allocations crossing Job - Main - Job thresholds. Bad bad. Use TempJob if you need that.
Ah, no. It'll cause your unity to crash without an error message.
In an entity, you can have a "permanent" component called "Attacked". It can have a bitwise flag integer that signifies which "type" of damage the following float value corresponds to.
So you have a system scanning entities with the two components Attacked and HitPoints. Maybe even Armor.
If Attacked.Damage <= 0, early return, skip that entity since no damage has been done since the last time it was checked.
If Attacked.Damage > 0, check Attacked.Type for the type of damage then multiply Damage with Armor, if it has any.
Then apply Damage to Hitpoint component and reset Damage = 0. All on the same Entity.
You can then parallel and, if you're feeling brave), loop vectorize it for lightning speed performance over 2 million entities.
probably best to allocate ahead of time with the size you need. Allocate something that's too small - you'll resize & do a memcpy (where the new size is old Capacity + 1).
starting to make more sense right now. there's some bits that I don't entirely understand yet (like loop vectorizing and bitwise flags) but i'm definitely getting it. thank you, this helped a lot!
this is one of those fun cases where there's a very awkwardly unknown upper bound π¦
dumb solution is two just merge my two jobs into one very long job
Dont worry about vectorization or bitwise operation. That's more complex stuff that really over-optimizes programs.
i see
since I can only create temp memory within the job, and I can't pass that out of the job (wait, why can I resize a tempjob list within the job then...? π€)
You can maybe make a third (well new first) job that computes the required size of the internal UnsafeLists and then pass that to a deferred list constructor
As long as you never need to read the list in the main thread, you can pass along deferred arrays throughout your job chain.
hmm, I'll think about it, thanks π
Of course, this wouldnt work with Entities. You'll need to use IJobParallelForDeferred and such
luckily no entities here π
I have avoided TempAllocators so far, but most of my collections are very large so the cost to allocate even in a job can be problematic for performance π
wait, why can I resize a tempjob list within the job
Race conditions. Even singlethreaded Job may interfere with Mainthread actions in the TempJob sphere. Which is why Job - Main boundary is very strict in what may pass between the two.
I think memory chunks resulting from malloc can pass between the boundary but I know performance is going to be destroyed using that. Otherwise, I dont believe there is any other way to dynamically allocate memory size and pass from a job back to the main thread to be read. You need to know the size of the arrays or memory before the job is even scheduled.
Why not just have a non-temp collection they both use to shuttle data between, making one job a dependency of the other?
if the issue is it changes size, just have an array[1] that stores the current index size that frame and pass that in to those jobs as well.
i.e. something like that
But now you need to know the "sum" of the sizes of all the internal UnsafeLists and you might as well use a NativeMultiHashMap instead.
basically I've got one job that produces a jagged array (nativelist of unsafelists of vector3s), and another job that consumes them, where the jagged-ness is of unknown and almost unbounded size π¬
and this job is spread over multiple threads and you need to avoid inter-thread locking?
there's multiple instances of it running over multiple threads but there shouldn't be any data shared between threads (other than explictly from job A into job B where b is scheduled after a)
(no data is shared between the instances, I'm just running it on a bunch of different data at once)
you say they are unbounded in size, but in practice how big can they get?
I think 4194240 float3's in total, spread across the axis is any way
and u are generating this how often?
most cases it's gonna be nowhere near that big, just the theoretical max is huge
might happen up to hundreds of time a frame when it does happen, but that frame wouldn't happen often
π
if this sounds cursed... it is
I think i can get away with job combining the producing & consuming jobs though
Does burstable main thread need ecs 0.17 and ISystemBase?
understood, I am trying to understand how expensive your memory allocations will be overtime if u keep allocating and disposing, even if in a job this can be expensive. If it happens often and at sizes anywhere near that, I would be concerned. In such cases I would likely just create a pool of paired permanent nativearrays, one of sufficient size to contain my objects and the other of size 1 to contain the current index count. Then just hand them out to jobs as needed.
Yes
Hey, how do you guys decide when to put two pieces of data in one IComponentData, and when to put each in their own IComponentData? Feels arbitrary right now, except that the default delegate for Entities.ForEach limits you to nine parameters
You rarely ever bump up against the ForEach limit. If you need that many parameters, consider splitting up the job
As for how to organize the data, it really depends on what systems need the info. Aim for the smallest number of components but also the minimum amount of "wasted" data. Data in a component that is not used in the system is "wasted" space.
i agree with you when you said that patching DOTS into an alreasy existing game leads to more suffering, but if DOTS was intended to deal with large number of GameObjects, it's not a bad idea to implement it to a simple game since it gives you better performance by default . let's say a game that uses oop and gameobjects is running fine, maybe 125fps (I don't know, I am just throwing numbers), but with dots it would run even better, maybe 200fps+ (again just throwing numbers) but maybe it took more time to create the game, in my opinion it's worth it don't you think? again I don't know anything about dots so I could be completely wrong.
Reality is most games are gpu bound but if you're cpu bound then it can def help.
What's the best way to learn the current DOTS syntax? Every time I come back to look at DOTS again the syntax changes and I find I'm doing everything the 'old way' and most tutorials and reference material (including officially released code) is outdated...
Imo the samples are still a good reference. Syntax hasn't really changed in the past 6months - year. If & when they release what they've been working on behind closed doors, things will probably change again though so it might be worth waiting if you find the current stuff to changeable.
I just remember looking through the movement component in the sample project and it was like...basically written as a Monobehavior and Dots was basically a wrapper for it
Like it wasn't actually 'coded in DOTs'
Are all the dots sample projects compatible with 2020.3.20f1? Looks like they were made in 2020.1.9f1
DOTS is not a magical bullet that gives free FPS. It helps a lot for certain games sure but it's a very niche genre.
Take chess, there are at most 33 gameobjects in a very basic chess, 1 for the board, 16 for the black player, 16 for the white. Converting that to DOTS is not going to give you more performance, in fact probably less
What would help would be maybe a visual where 5,000 games of chess were happening at the same time
Or a city traffic simulator like Cities Skyline where there are a lot of identical cars on city roads
data oriented programming performance benefits can be felt in most game genres, where scaling entity counts higher is useful. For example I am working on a large world survival game and its beneficial to be able to increase the number of systems/entities updating in the world at any given time, even tho the majority of those entities wont ever be see on screen by the player at the same time. It is also useful for any game where u want to save cpu cycles and/or power on mobile.
You can also still obtain a lot of these benefits without using DOTs entities, simply by following good DOP practices and using jobs where it makes sense. Doesn't have to be all or nothing to get benefits.
DOTS has other benefits. It's expandability is theoretically much better than OOP. Because the "Systems" are smaller than Object behaviors and are designed to be used on entirely different kinds of objects or even for completely different purposes. It's a pretty big project to try and re-organize your OOP setup.
That's what I thought of them π , I mean you can't call it free fps since you're changing the way you write code and organize things
Less performance? Are you sure? How and why? Up untill now i've never heard of disadvantages of using dots...
Thanks
Does anybody has problems with Unity 2020.3.20LTS and ECS. I updated ECS to 0.17 and com.unity.platforms was updated as dependency. After that i have errors
You might need to downgrade the platforms package
ObjectPool was introduced in 2021.1
but this package upgraded with im changed ecs from 0.16 to 0.17. And ecs with 2021.1 not officially supported. Im trying to use HybridRenderV2 with android URP and Unity 2020.3
Yea I'm just saying that ObjectPool was introduced in the engine in 2021.1 and you're on 2020.3. I updated to 2021.1, but I don't use Hybrid Renderer π€
Is there no GetSingleton method on the EntityManager anymore? I'm sure their used to be π
No, but you can call GetSingleton on an EntityQuery created from an EntityManager. Or if you are inside a SystemBase, you can call GetSingleton without setting up any queries.
GetSingleton on a SystemBase does create an EntityQuery, it's just inside that method instead of having to write it out yourself
But isn't it caching the entity query in that case? In other words, its not creating the EntityQuery inside the GetSingleton method call, but simply using the one it sets up internally. I always assumed that it was equivalent to manually setting up the EntityQuery in OnCreate and calling GetSingleton on it in OnUpdate.
Yea that's pretty much it, since if it's created, it'll just search through its internal UnsafeList<EntityQuery> and find the query with the correct ComponentType
I'm using it in a monobehavior, but I guess that should still work, thanks
Anyone know why I get "The entity does not exist" error when checking GetComponentDataFromEntity inside a foreach lambda that has the entity as an argument?
Like if the entity doesn't exist, how did I get inside this lambda and inside checks for certain tags on that entity
If you're working on the entity in the argument, why don't you just pass the component data as an argument??
I confused myself as i wrote that lol. It's checking tags on that entity which are valid, then it does the GetComponentDataFromEntity on the reference of a different data
I'm trying to check if the reference is null, but it passes that
if (targetData.Target == Entity.Null) return;
var dirToTarget = (positions[targetData.Target].Value - translation.Value);
positions is my GetComponentDataFromEntity
is there a safe way to check if an entity exists? clearly null isn't the way..
Well, the intended way is to just query for entities with the given tag, and operate on them if they exist in the query; no null reference check needed. I'd rethink whether you really need entity references in this case. If you do, I'd implement a system that cleans up entity references before entity destruction, so I'd know all entity references are up to date and valid.
Well I have one entity that follows another entity so i have it keep a reference to the one it follows
Hey everyone! I'm using HDRP with the hybrid renderer and can't seem to get my entities to render. Even though I followed all of the documentation properly, I never got the confirming console output when trying to upgrade to the hybrid renderer v2, so I'm thinking that's my main issue. My color space is set to linear, the script define symbol is there, and srp batching is enabled in the HDRP asset. Here's the code I'm using to spawn an entity (just in case that's actually the issue): https://pastebin.com/Sh5BrbYV
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Quick scan looks like you donβt have all the components needed to render. Iβd suggest comparing to a mesh thatβs been converted for comparison. In general this is why Unity try to push us towards conversion. I think there may be a helper method in one of the last updates but definitely check if eg a gameobject in a subscene renders
Why don't you just parent the entity then? Everything could be automatically handled by the transform system group
@left oak Kinda new to this lol. How would I do that?
np, take a look at this to start: https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/transform_system.html
ah it's a special thing just for transforms?
Look at Section 5
You get a lot of utility from parenting, like included entity references
you also get this child's position in parent space
Sounds like a nice piece i've been missing out on lol. Trying to figure out the syntax now. There's a lot of text on that page π
Yeah, but the diagrams help
It's easier to use with conversion, but can certainly be setup programmatically
So, I realize this question is way too broad and I'm kind of expecting crickets, but is there a "beginners guide to building your first DOTS project as a standalone that you can distribute to friends" out there anywhere that anyone knows of? π
right now it builds and I just see a grey screen when the splash screen ends
I don't know of one, but I would suggest ignoring everything geared towards optimization and focus on learning how to use ECS as a framework. Forget about burst and trying to make things multi-threaded. Forget about using the hybrid renderer or hybrid physics. You can make any class into a component by just adding IComponentData to it's implementation list. You will run into complexity with the way Unity has built their hybrid stuff, and I personally found I needed to write my own stuff to make the entity-gameobject hybrid shamelessly work the way I wanted it to work. If you do all this, then you can focus on just learning and following the principals of ECS. You won't benefit from the optimizations, but you will flatten the learning curve, you will still benefit from the stability benefits of sequential execution, system decoupling, and you will set yourself up for straight forward refactoring and optimization later.
oh, sorry, I'm talking specifically about building. I'm pretty darn good with ECS / have a relatively complex little sim that works when I enter play mode
I just want to build the thing so that I can show it off
oh, I don't know, I never had any issues with building
maybe that's because I didn't use unity's more experimental parts
so, Im wondering if its related to the fact that I have "convert and inject gameobject" attached to the main camera
I use the CopyTransformToGameObject component so that I can control the camera position from ECS
maybe it doesn't like that
Are you using the scriptable build pipeline?
its an HDRP project, I can't remember if that's mutually exclusive
no build errors. got 2 warnings - unable to find player assembly - UnityEngine.TestRunner.dll and UnityEngine.PerformanceTesting.dll -, but I feel like that shouldnt matter
yeah, just grey screen once the unity splash screen ends
o, yeah not sure - maybe it's a hybrid renderer issue? π€
could try Companion gameobject
I currently use that to control a camera
ugh. okay nevermind. I really appreciate both of you helping but I'm just an idiot and committed the error I thought I wasn't stupid enough to make
The scene that as added to the build was not the one I was using to control the game
sorry, this wasnt DOTS related at all and I'm that guy tonight.
I might be understanding this wrong, but shouldn't these 3 objects be converted to entities and destroyed since I have the ConvertToEntity script on them?
cant tell what the problem is from that shot, can you screencap them in the inspector before entering playmode_
Here ya go. It's just three copies of a prefab with a meshrenderer, meshfilter, and a ConvertToEntity script.
Quick question... when i use burst compatible structs as components for my entities. Are those allowed to inherit interfaces other than IComponentData ?
Like public struct Movement : IComponentData, IDisposable, IMyOwnInterface ?
Yes but if you use your interface in burst it must be used as a generic implementation of your interface
i have this system. i want it to be burst compatible. It has few protected static methods in base system. Should i mark methods with [BurstCompile] attribute?
im look in DOTS compiler how its look like so attribute set to system. Is it enough ?
also should i move GetComponentData form singleton Entity into lambda and get data through GetComponentDataFromEntity
If you call a static function from inside a bursted function, it will be bursted
No need to decorate the static functions
how do we run an entities foreach loop with dynamic "with" clause
foreach (ComponentType t in types)
{
Entities
.WithAll<t>
.ForEach((Entity entity, Translation translation, Rotation rotation) =>
{
}).ScheduleParallel();
}
Might be better to use an IJobChunk/IJobEntityBatch job struct and pass in a query versus trying to use a ForEach statement
Cause it looks like you'll probably just want to construct the query using an Any clause
Is it expected, that the Parent component on an instantiated prefab points to itself?
yes - it's a flat list of the hierarchy is the idea
Any particular reasons why EndFrameParentSystem might be using a looot of time compared to all other systems
Additional question - when trying to take advantage of hybrid renderer ( for example thousands of bullets ) is there anything special that needs to be done to take advantage of batching? Does enabling GPU instancing in the URP Lit marerial affect this at all?
According to this thread, there is no need to enable GPU Instancing on materials when using hybrid renderer v2: https://forum.unity.com/threads/confused-about-performance-of-srp-batching-vs-gpu-instancing.949185/. It also sounds like you should disable Dynamic Batching in the pipeline asset so that it doesn't interfere with the newer stuff in hybrid renderer, although I might have misunderstood that part.
Thanks i'll have a look. I did notice this thread from today in the DOTS Graphics forum ( https://forum.unity.com/threads/will-using-hr2-in-non-dots-project-help-with-rendering-performance.1175114/ ) but it's just a bit of a black box with information scattered around it's hard to know what's what exactly.
welcome to DOTS lmao
can entities v0.20 come out already lmao
Really interested in this question if anybody has any insight.. problem seems to occur on and off in different scenarios so it's kinda hard to discern why exactly the EndFrameParentSystem sometimes consumes a lot of time per frame
have you looked at the profiler?
it would be the same because i'd have to type out each componenttypehandle anyway
honestly might have to do some codegen or something
but you can pass in an array of ComponentTypes to an EntityQueryDesc?
plus you can also combine EntityQueryDesc together π€
Well I'm not really sure what you're trying to achieve
does someone have an up to date example on how to handle trigger events?
physics samples inside of https://github.com/Unity-Technologies/EntityComponentSystemSamples has one for triggers
there's also an example here which feeds from the physics samples baron linked to:
https://dots-tutorial.moetsi.com/unity-dots-physics/use-dots-physics-for-collisions
anyone else noticed Companion GameObjects don't get destroyed, at least in the editor when quitting play mode?
GhostStatSystem is making my game almost unplayable
what is it?
its unity. i restarted unity and now its gone. wtf guys.
Is there an idiomatic way to get player inputs from the player input component into an ECS system? I'm not converting an existing game. (I mean, I am, but what code existed is incredibly simple, and I'm redoing it from scratch.)
thats how I use it
also dots hybrid rendering, prepare to say goodbye to the v1 of the hybridrenderer https://github.com/Unity-Technologies/Graphics/pull/5842
That's a lot of preprocessor instructions. I'll look into it, though. Seems like a good place to start. Thank you kindly.
thought similarly originally, though after using it to me it seems fine and the least of my worries as far as any dots <-> unityengine based interaction
Oh, is all that just for keeping things from breaking with multiple developers using source control?
it's more of a state of unity since there are multiple input systems
and this example specifically uses the new input system
Not just that. It looks like v2 is also going away and the third iteration (basically v3 but not called that) is taking its place. They also mention DOTS 1.0!
wow it was there in the first sentence and i missed the 1.0
That... Doesn't really explain anything. If that were a problem I would have had to do this when I've used the new input system before.
Mb didn't read your message properly, to answer your question - yes
it's there to avoid breaking the system in case someone doesn't have the new input system enabled in their project
probably gonna sound like a broken record but wish the other dots repos were open. would feel a little bit better about the whole lack of communication
Ah, alright. Thanks for clarifying.
Yeah I agree. I can kinda understand them keeping it private if they are making large breaking changes and don't want people to start using it yet. But why couldn't they just tell us that? And what is stopping them from discussing these changes on the forums?
I can guess that the answer is something related to unity being a publicly traded company...
Anyways, I'm just excited to see that DOTS 1.0 is still actively being worked on. Fingers crossed for a break in the radio silence by the end of the year.
i dont think its anything to do with them being publicly traded tbh, imo the whole roadmap productboard kind of disproves that(along with the safe harbour statement), i think its just par for the course with how unity operates, sometimes hot and sometimes cold as far as communication goes.
Hmm I dunno. Perhaps it has nothing to do with being publicly traded, but it really does feel like the unity folks were told not to discuss future DOTS changes anymore. There used to be very frequent posts by unity staff saying that various changes would land in the next version of entities in a month, or them participating in discussions of improvements and changes to the workflows. I find it hard to believe that they all just stopped being as active in the forums at the same time.
Agreed
def agree that theres some general gag order as far as general communication, i just feel its more of a general strategy rather than in reaction to being publicly traded. feels reminiscent of how terrain was just ignored for the longest time, or the ire around state of unhappiness regarding render pipelines until they made a big post about it.
itβs one thing to not talk about DOTS.
itβs another thing to not talk about why no one can talk about DOTS.
would be just fine if someone said whatβs going on (SEC/expectations/research/β¦)
people are more understanding than they think
Rule number one of Dots Club - you do not talk about Dots Club
Hello
I need to have some meshes from a scene as DontDestroyOnLoad
Before, I could easily achieve making them persistent with DontDestroyOnLoad codes
Now, I have converted those meshes to Entities, as they're under Subscenes
Is there any way to make those meshes or entities, persistent?
Take a look at SystemStateComponents: https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/system_state_components.html
They're persistent component types that ensure that entities are not destroyed unless the SystemStateComponent is also removed
interestingly, a PR in september targeted DOTS 0.5. Moving fast hah. Also, DOTS compatible picking in scene view seems to be coming to SRP
nice find with the picking, can only hope we will be able to edit entity data in the inspector soon enough to go along with that picking
I think it was planned initially, but then someone from the team got a bit defensive when someone mentioned it. Might be they'll just say to use live conversion, which is annoying and doesn't even work with NetCode for example
as far as we know, dots have more people working on it than ever, but terrain for the longest time did not have a full team behind it.
Thrilled to announce we have formed a C#/.NET Tech Group within Unity, bringing Scripting (C# compilation, .NET Runtime integration...), Burst & VM/IL2CPP teams all together to further standardize, modernize, and innovate with .NET technologies within the Unity platform! β₯οΈ
Imho, radio silence is definitely related to being publicly traded
yeah in that editor thread they mentioned it would only be readonly, but really hoping they are changed their minds on that. I mean picking entities is handy but picking and editing is like what I come to expect, not just reading that data.
probably too many siloed teams all moving at once which is why they're silent. π€·
Can you change the behavior of a system based on the existence of a component in an entity?
And by that I mean the system always applies with the presence of specific components, like normal, but the way it processes changes depending on the existence or non-existence of an extra component.
Hi all, just joined the discord. Brand new to DOTS and ECS. Hope to see you all around o/
@mystic quartz, the simplest way to do that is to have different Entities.ForEach() for the various possible combinations of components by using either the WithAll(), WithAny(), and WithNone() modifiers or by including different sets of captured variables in the ForEach lambda. This involves writing a lot of jobs with subtle differences in execution, but you gain the confidence that only the valid sets of ForEach run on any given frame. You could also simply do a HasComponent(Entity) check and then branch from there within a job, but I very much recommend the former over the latter
Yep, that's what I ended up doing. Seems to work.
the other way is to use IJobChunk/IJobEntityBatch and use chunkwise logic
It seems that you used to get access to a physics frame's triggerEvents in StepPhysicsWorld.Simulation.TriggerEvents (unless I'm mistaken), but it doesn't seem to be present. Has it been moved/api changed?
Makin' a camera controller. I'm giving it a reference to an Entity for it to track, but I need to access the Translation component of that Entity in the ForEach. Tried a thing I found online that uses GetComponentDataFromEntity and WithReadOnly, but that just throws a load of InvalidOperationExceptions at me whenever I try to index the variable, which I think might come down to the possibility of reading from and writing to the same Translation.
Anyone know the pattern for what I'm trying to do?
paste how you're using it. also if you are using ForEach you can use GetComponent/SetComponent which compiles to cdfe
public class CameraDollySystem : SystemBase {
protected override void OnUpdate() {
float deltaTime = Time.DeltaTime;
var translationComponentData = GetComponentDataFromEntity<Translation>();
Entities.WithReadOnly(translationComponentData).ForEach((ref Translation translation, in CameraDolly dolly) => {
var targetPosition = translationComponentData[dolly.target].Value;
translation.Value = AMath.Approach(translation.Value, targetPosition, deltaTime, dolly.smoothingRate);
}).Schedule();
}
}```
Found it. I needed to explicitly cast StepPhysicsWorld.Simulation to Unity.Physics.Simulation
@mystic quartz yeah you cant use cdfe for the same component in the foreach, so instead of readonly can set that entity's translation via cdfe. Also for reference the Get/SetComponent equivalent https://docs.unity3d.com/Packages/com.unity.entities@0.17/api/Unity.Entities.SystemBase.SetComponent.html / https://docs.unity3d.com/Packages/com.unity.entities@0.17/api/Unity.Entities.SystemBase.GetComponent.html
SWEET! I thought I had that code, but I must have lost it in a backup restore
Weirdest thing I did ctrl+h for exist like twice and nothing showed up...
you da man baron von rick codin
so instead of readonly can set that entity's translation via cdfe
Dunno what you mean by that.
So I recently created a new HDRP project to test if the hybrid renderer v2 works on it, and it turns out it works perfectly. However, on my current HDRP project that I've been working on for months now, I can't get the hybrid renderer v2 to activate at all. Both projects follow the documentation exactly (hybrid renderer v2 enabled in script defines, color space is set to linear, srp batching enabled in the hdrp asset), but only the new test project is getting the confirming console output and is able to render an entity. The hdrp and hybrid renderer package versions are the same on both projects as well. Does anyone have any pointers as to what could potentially be causing this issue?
Under Buildconfiguration, what are the components: Unity.Build.DOTSRUNTIME and do I need them to see entities in standalone?
2020.3 correct?
Yep, 2020.3
@mystic quartz
Entities.ForEach((Entity entity, in CameraDolly dolly) => {
var targetPosition = GetComponent<Translation>(dolly.target).Value;
var translation = GetComponent<Translation>(entity)
SetComponent(entity, AMath.Approach(translation.Value, targetPosition, deltaTime, dolly.smoothingRate));
}).Schedule();
//or
Entities.WithNativeDisableParallelForRestriction(translationComponentData).ForEach((Entity entity, in CameraDolly dolly)=>{
var translation = translationComponentData[entity];
// etc
})
@pallid moat you got the ENABLE_HYBRID_RENDERER_V2 define in player settings?
Yep. I have it enabled in both projects, but I only get the confirming console output in the new test project I created.
Having a NetCode issue with child entities and interpolated-only ghosts. Posted here with a minimal example if someone is willing to take a look: https://forum.unity.com/threads/snapshot-not-sending-child-rotation-for-interpolated-entity.1183633/
I have a server-controlled ghost, which rotates a ghost child entity. The data updates in the server world, but does not transfer to the client world ghost child entity. The strange thing is that the translation data of the ghost root entity does transfer. This problem appeared when I converted a hierarchical ghost from an owner predicted ghost to a purely interpolated ghost. Provided some GIF visualizations in the thread
Solved: overrides["Unity.Transforms.Rotation"].attribute.SendDataForChildEntity = true; See thread for more info on solution
Is there a DisablePhysics ComponentTag or something similiar for dots physics? I remember seeing this somewhere, but can't find it π€
Ah found it PhysicsExclude It's not mentioned in the documentation
Does .NET Standard 2.0 vs Framework 4.x matter in terms of DOTS packages?
Trying to work out if this is an ECS/DOTS issue or InputSystem issue. My horizonal and vertical actions are updated fine, but my button actions (jump and orient) are always false. Am I missing something?
InputSystem.Update();
float horizontal = playerActions.Horizontal.ReadValue<float>();
float vertical = playerActions.Vertical.ReadValue<float>();
bool jump = playerActions.Jump.triggered;
bool orient = playerActions.Orient.triggered;
Debug.Log($"Jump: {jump}, Orient: {orient}");
Is this the correct way to handle InputSystem stuff in Systems?
Hi, does anyone know how to do raycasts inside a jobs struct?
I don't think triggered works properly from what I can remember
I have a basic dots input system working here if it helps https://github.com/Calabitale/Flow-field-dots-nav-/blob/main/Flow Field Nav System/Scripts/PlayerInputSystem.cs
I have tried moving my code into a monobehvaiour to test and the triggered value isn't even working there.
yeah that's what I mean I just used readvalue<float>() and that seems to work
Ah cool thanks. Weird that non-preview package just isn't functioning according to the docs π€
Cool I'm just gonna use this for now:
bool jump = playerActions.Jump.ReadValue<float>() != 0 ? true : false;
Thanks for your help
have you compared all of the dots packages to ensure the same versions between your test project and your working project?
what allocator do i need for MeshCollider.Create() for the vertices and triangles NativeArrays?
when running a job is there a way to avoid using the main thread and only schedule it on the other cores ?
of course that's the whole point use either schedule() or scheduleparallel()
i see thanks , any ideas about how to use compute buffers with DOTS ?
nope, I think compute buffers are a whole different area than DOTS
This doesnt seem to need the ? true : false
It does if you want a bool π
Although I think worth saying that it's difficult to avoid having the main thread do work to schedule the job. So although your job can run on another thread, especially for smaller jobs, the time taken to schedule it can be much longer than the duration of the job itself.
E.g. for <100 entities (esp entities with components used in other jobs), Run() is often less total main thread cost than just the scheduling and dependency management in a Sched/SchedParallel (ignoring the time to execute / do the work).
What do you think playerActions.Jump.ReadValue<float>() != 0 returns?
Sorry, I misread your post, I thought you said it doesn't need the whole != 0 ? true : false.
You're right. I forgot c# syntax allows the conditional on it's own on the right side.
bool jump = playerActions.Jump.ReadValue<float>() != 0. Is fine on its own.
Or rather @stiff skiff said
I did not know that 
That's cool. Feels a bit fussy to bring it up but definitely more readable. Especially as you can have a true condition return false like that. i.e. bool isUp = !isDown ? false : true; π
It is a nice syntax. VB sadly has to use an if that makes it all messy.
where can i find the dots repositories on github ?
think they're still pinned?
i mean we can download those in the package manager
and open the Library code
but i can't find it on github
not sure why you'd expect to? Unity don't want pr's
pr?
pull requests, fixes, generally anyone contributing code outside of Unity
ok thanks , ill just copy it from the Library folder then
There is a needle mirror if you want it on github for looking at he code away from your project
btw if you only need access to the internal methods you can use the 'AssemblyInfo.cs' combined with assembly reference trick to make it accessible to your classes.
etc.
The whole list is here: https://github.com/orgs/needle-mirror/repositories
neat just* wanted to lookup something without cloning it for reference
apparently the hybrid one writes to a compute buffer from a burst job if i understood it correctly
Just want to check you're aware you can generate project files for packages too? Can help follow code. e.g.
Have you configured unity to generate the package projects for you? ne you ca jump ot the methods in Visual Studio
Ha just beat me to it!
yea im aware of this , my laptop is a bit slow and the project is already pretty big so wanted to avoid downloading this
thanks
How do I make this .scheduleParallel :https://pastebin.com/0LVReG0X
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
So does anyone have any pointers on reducing the load in EndFrameParentSystem.. it's showing up in Profiler as job called RenderGraph:ParallelRenderer (Burst):
Or even some way to trace why it's consuming so much time
i think make your ecb AsParallelWriter()
_endSimEntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter()
Oh is that next line tied to the line above?
uhh.. yeah?
I changed the whole script to accommodate EntityCommandBuffer.ParallelWriter stuff. I've done this in SystemBases so I know the code works. I never did a parallelWriter in a JobComponentSystem. All the code works except that line .schedule parallel still.... https://crystalfighter.com/code/22JobScheduleparallelNotworking.png
I'm not familiar of coding when one line of code flags an error if the one after it isn't there outside not doing method returns... This dots stuff is curious.
what error do you get? tbh i've done very little jobs mostly Systems
The error is in this picture: https://crystalfighter.com/code/22JobScheduleparallelNotworking.png
Its the same error I got before refactoring my code to accept parallel writing...
Ok, so what I get is you just didn't understand my question.
That answers my curiosity of why a line of code would show an error if a line of code after it was not there.
That's good to know. We just back to the original problem now.
Well the error is showing that the first argument of the ScheduleParallel for the job expects an EntityQuery
So it might be worth doing a quick search for other examples of where ScheduleParallel has been used on a job and how a query is typically passed in
Here's an example from the Animation package:
Do you know if schedule parallel is even allowable in jobs?
Cuz I do parallel in some systemsbase scripts successfully now
Normally I end with: }).WithoutBurst().ScheduleParallel(this.Dependency);
You do not even need an EntityQuery my man.
It's obviously slightly different with a job, like in the above example..
So when you run the job you're passing in a query which represents the entities to run through the job
I'm just helping you out... There is nothing that needs to be passed to .ScheduleParallel that involves an EntityQuery...
Its fun when two people with imperfect information come together to help each other.
I find this beautiful, not frustrating
It's literally telling you it wants a query..
Frustrating is when you have no idea how to start going over a brick wall hurdle.
look at the example i posted above
Where do you get the dependency from the above example?
I'm missing that part as well.
how du mean
The line: .ScheduleParallel(m_ComputeSkinMatrixQuery,1,Dependency)
ahh i see
The Dependency variable is not declared in the visible code.
Dependency is passed in to every SystemBase, it's already there
in my system base, it is declared by setting it Dependency = Entities .Foreach
Oh!
wow!
ty
so i think in your case you're passing in Jobhandle inputDeps, that's i think the old way of doing it with JobComponents or something
using SystemBase is just magnitudes simpler than all that
ok so I did have it then
mine is inputDeps
cool cool
I'm using this code because it works for collisions... Normally yah I use Systembase for everything
Here's basically how you can chain together two jobs in a SystemBase, really simple:
protected override void OnUpdate()
{
Dependency = new ComputeSkinMatrixJob
{
}.ScheduleParallel(myQuery1, 1, Dependency);
Dependency = new CopySparseBlendShapeWeightJob
{
}.ScheduleParallel(myQuery2, 1, Dependency);
}
And here's another way using CombineDependencies:
protected override void OnUpdate()
{
var job1 = new ComputeSkinMatrixJob
{
}.ScheduleParallel(myQuery1, 1, Dependency);
Dependency = JobHandle.CombineDependencies(job1, Dependency);
var job2 = new CopySparseBlendShapeWeightJob
{
}.ScheduleParallel(myQuery2, 1, Dependency);
}
As you suggested, I added the EntityQuery, but ScheduleParallel is explaining it cannot take 4 arguments: https://crystalfighter.com/code/23JobScheduleparallelNotworking.png The Visual Studio alt+enter potential fix did not work.
Ah it's a CollisionJob i didn't notice that.. let me have a quick look through the physics samples
is CollisionJob a custom job you've created?
Dude, you da bull, check it out now my funk soul bovine, if you find me and starfighter doing well, ask for the manilla payoff, I'm stupid generous, and also a bit stupid π
Here, I'll give the full code
It was working code for non parallel That I expanded
Enjoy...
It requires a custom component named EntityData... and that's just stuff custom to my game.
Remove all that and you can still be reading in collisions.
I ended up hitting same error as I did in my systembases
It would destroy an entity, while another systembase tried to post process the scheduler
Without parallel, one may destroy while other being used
You know what tho...
I'm probably going about this wrong.
Maybe I should flag it to be destroyed and use my destroyer process... That probably should work.
Unless stuff is being read/wrote same time multithread problems
Okay i think basically the ICollisionEventJob interface does not accomodate ScheduleParallel
We good to go. Hey let me post one of my cool looking DOTS ECS videos, these things are funny
If I have future issues, I either need to do collision elsewhere or see how to do stuff before or after my parallel stuff... I get conflicts cuz my parallel isn't finding destroyed entities in my iCollisionEventJob
Yeah it's kinda the joy of dots/ecs is you get the benefit of being mega explicit over exactly what happens and when, but then you have to spend that extra time designing the systems and jobs to flow as linearly as possible etc
Starfighter General: A soul gamer indie in the age of boring corporate spew.
This action MMORPG will have live game masters. Those who role play well whether good guy bounty hunter, bad guy pirate, emporer or whatever will attract the eye of a live Game Master for live sessions. Nothing held back, nothing off table, change the universe you pl...
No lie, Cow, I enjoy having a challenge. At least it aint mind twisty like circutboard chip coding where memory is the limit and not the processing... It flips the optimization habit processes in my brain and fries me. Unity DOTS is like mind expanding beauty.
Hehe looks nice. Reminds me of an oldschool space game that i can't put my finger on. Are you using hybrid renderer or gameobjects?
Is there a cross platform deterministic physics engine in DOTS?
Fixed-point/integer based
Is there a way to query two related entities at the same time?
I've got a player, and a gun. The gun is necessarily related to the player (Transform, velocity, friendly-fire checking,) but also requires its own composition (Rate of fire, projectiles, hitscan, bullet prefab, effects, transform offset, burst, ect)
The system needs to know about the player in order to correctly use the gun, and the gun must be an entity so it can be composed.
Anyone ever dealt with entities spawning at 0,0,0? despite setting transform location at the start
like it's only happening for 1 frame, but it's messing some things up for me :\
Are you spawning the entity and setting the transform from two different places in the code?
Yikes. Might have something to do with parallel processing, but I'm still new to this, so I wouldn't know for sure.
it's even happening when i parent them. I can set a LocalToParent value, and in a different system it'll come back at 0,0,0 for 1 frame
I tried setting localtoworld instead of just translation or localToParent to see, but it didn't help
Ok so for at least one of my cases, this has something to do with the position in my prefab. despite me setting it right after I make it.
Am I creating it wrong? this is what I'm doing
Entities.ForEach((int entityInQueryIndex, in Spawner spawner, in Translation translation) =>
{
var spawnedEntity = ecb.Instantiate(entityInQueryIndex, spawner.EntityPrefab);
ecb.SetComponent(entityInQueryIndex, spawnedEntity, translation);
}
my guess is that it's spawning in time to be rendered, but not in time to be processed by the transform system group
the effect of that being the case is a single frame of entities being rendered at world origin
This should help https://forum.unity.com/threads/how-to-update-localtoworld-translation.1150868/#post-7385411
@tribal pollen Basically it has to do with what @left oak said. The rendering system is using the localToWorld component. that component is updated by the transform systems in the simulation group. If you spawn you entity at the end of the simulation group it will not have an updated localToWorld value it will be (0,0,0) or whatever value the default is for your prefab. After the simulation group comes the presentation group that display your entity on screen. since the localToWorld is not updated it will show up at world origin. So you can either spawn your entity at the begin simulation group command buffer (delaying the instantiation by 1 frame) which will give time for the transforms group to update the position of your entity or you can compute and set yourself the local to world. Option 1 is the simplest one but be aware that the simulation will also have the localToWorld at (0,0,0) until the transform group is run. So if the physics system uses the localToWorld and run before the transform group it will also "see" the entity at (0,0,0).
yup exactly what @uncut rover said. Some people set the LTW manually for the first frame but I wouldn't really recommend it. One additional thing - instead of delaying instantiation to the first frame, another approach is to ensure your spawning system updates before the Transform System.
@left oak @uncut rover @amber flicker Thanks, for all your help. I didn't get to do much with it this morning before work but I did quickly test and changing it to the StartInitialization buffer seems to have fixed the issue for my normal spawned entities.
However, it seems like the issue is still there for my Child entities, LocalToParent is starting at 0,0,0 (Note I'm not spawning parent and child at the same time, parent already exists when I spawn a child). I believe this 0,0,0 is the same location as the parent, not the world 0,0,0
I'm pretty sure i tested with both setting LTP value on creation and also just setting transform.
Is there a similar order oddity happening within the System's Hierarchical Transforms?
I have not yet tried to spawn an entity and parent it to an existing one. All I know from the conversion system is that the is a Parent component on the child and there is a Child buffer on the parent. These are used by the transform system to compute localToParent matrix. I would start by checking if the parent component and child buffer are properly populated after instantiation. If they are not the transform system will most likely not work as expected.
Hi, Im on Unity 2021.2.0b16.3733, URP 12.1.0, Hybrid renderer 0.11.0-preview.44
And on android platform.
On attempting to build the project, I get the following error:
Shader error in Universal Render Pipeline/Unlit: The DOTS_INSTANCING_ON keyword requires shader model 4.5 or greater ("#pragma target 4.5" or greater), at /NewUnity Projects/Android 2021.2ecs/Library/PackageCache/com.unity.render-pipelines.core@12.1.0/ShaderLibrary/UnityInstancing.hlsl(50)
Use of UNITY 2021 and DOTS packages is discouraged (https://forum.unity.com/threads/notice-on-dots-compatibility-with-unity-2021-1.1091800/) that being said, some managed to make it at least partly work : https://forum.unity.com/threads/dots-and-2021-2-known-issues.1183456/#post-7579792
Hi!
With the release of Unity 2021.1, DOTS is at a crossroads in terms of compatibility with the currently available Unity versions.
While certain...
Surprisingly, on unity 2020 Dots hasnt been working for me, to say the rendering part at least.
Spent 3 days working thru many unity versions and I came to this-
Unity 2019.4, Entities do get rendered (HybridRendererV1 only is supported), but they dont support Skybox/Ambient/Environment lighting.
Unity 2021.1, and even Unity 2020,
The entities never get rendered, no matter how much time is spent on "Importing EntityScene" (on the bottom of unity program where it shows loading).
On the scene view, on clicking the Subscene object, its forever stuck on Importing...
I spent 6 hours yesterday on trying out diff things like new subscenes and hitting saves and whatnot, but it didnt ever show up.
But, Unity 2021.2.0b16, a beta version of unity, seems to show the entities properly (as of now too), and it supports Skybox/Ambient/Environment lighting (probably cuz of HybridRendererV2)
And to see it now stuck on the build error, makes it more... Ugh
Oh and, on the Unity 2020, Entities do show up on PC build platform (Idk if I had URP set up in the graphics, but it did show)
Switching to Android build, and making a few changes as setting the URP to work, and it didnt show up afterwards
:/
I wish I could downgrade the URP version of possible? Tho I'm not finding an option how to with my searches
I can tell you I've experienced issue with subscenes and unity 2020 when have Entities + UITK+ new input system. that resembles your "infinite" import issue. I tested the latest 2021.1 version but have a bunch of errors.
Can you share you build configuration for this project ? maybe it will give more hints on the issue.
Edit the Packages/manifest.json if you want to downgrade URP. I think if you're on 2021.2 URP should be v 12.x.0, 2020 should be on v 10.x.0.
10.x for 2020 I think
o right, 2021.1 should be 11.x.0, thnx π
@remote crater didnt follow the entire convo but afaik trigger/collision stuff doesnt support parallel yet. i think its on the physics guys todo in the future(not sure when though)
@uncut rover @coarse turtle
Pinging as if to reply to the conversation
Sooo there was a "temporary solution" posted on the forum by somebody where I had to edit the UniversalTargets.cs of the URP package, and now it builds with no issue.
And now, to my another surprise (whew its been many surprises lately), the mobile screen is flickering like crazy, as if brightness is going rapid up-down, you know (Checked the player settings and its alright it seems)
Welp, I'm going to instal unity 2020.3.6f1 with URP 10.5.0, which seemed to be stable for Somebody on the forum. Nevertheless I want to give it a try and see how it goes
Posts a dead emote
Hello everybody, I want to use GetComponentDataFromEntity to modify the translation of an entity but for some reason it takes no effect. What can I do to address this?
public class UnitMoveToTargetSystem : SystemBase
{
protected override void OnUpdate()
{
var allTranslations = GetComponentDataFromEntity<Translation>(false);
Entities.ForEach((Entity unitEntity, int entityInQueryIndex,
in HasTarget hasTarget) =>
// ref Translation translation,
{
var translation = allTranslations[unitEntity];
translation.Value.x += 0.1f * deltaTime;
}).Schedule();
}
}
you have to then assign translation back to allTranslations, yeah?
Wow that was easy, thanks I was really banging my head against a wall ^^
np, just keep in mind these are all copied by value, not reference
LocalToParent keeps starting with a value of 0 >_<
I'm stuck again. When I run this system I get an error. Any ideas what be going wrong here?
public class FindTargetSystem : SystemBase
{
protected override void OnUpdate()
{
var targetsQuery = GetEntityQuery(typeof(Target));
var allTargets = targetsQuery.ToEntityArray(Allocator.TempJob);
var allTranslations = GetComponentDataFromEntity<Translation>(true);
Entities.WithReadOnly(allTranslations).WithNone<HasTarget>().WithAll<Unit>().ForEach(
(Entity entity, int entityInQueryIndex) =>
{
float3 unitPosition = allTranslations[entity].Value;
for (int i = 0; i < allTargets.Length; i++)
{
var targetEntity = allTargets[i];
}
}).Schedule();
allTargets.Dispose();
}
}```
|| InvalidOperationException: The previously scheduled job FindTargetSystem:OnUpdate_LambdaJob0 writes to the Unity.Collections.NativeArray`1[Unity.Entities.Entity] OnUpdate_LambdaJob0.JobData.allTargets. You must call JobHandle.Complete() on the job FindTargetSystem:OnUpdate_LambdaJob0, before you can deallocate the Unity.Collections.NativeArray`1[Unity.Entities.Entity] safely. Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <ca496b8c93454b2f9b9924292c19379f>:0) Unity.Collections.LowLevel.Unsafe.DisposeSentinel.Dispose (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& safety, Unity.Collections.LowLevel.Unsafe.DisposeSentinel& sentinel) (at <ca496b8c93454b2f9b9924292c19379f>:0) Unity.Collections.NativeArray`1[T].Dispose () (at <ca496b8c93454b2f9b9924292c19379f>:0) Code.Systems.FindTargetSystem.OnUpdate () (at Assets/Code/Systems/FindTargetSystem.cs:70) Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/SystemBase.cs:412) Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/ComponentSystemGroup.cs:472) UnityEngine.Debug:LogException(Exception)...||
|| Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/Stubs/Unity/Debug.cs:19) Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/ComponentSystemGroup.cs:477) Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/ComponentSystemGroup.cs:417) Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/ComponentSystem.cs:114) Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/ScriptBehaviourUpdateOrder.cs:333)||
You have a race condition. You are disposing your native array on the main thread after scheduling the job, but possibly before the job runs.
You want to use WithDisposeOnCompletion(allTargets) on your forearch call.
@muted star instead of calling allTargets.Dispose();
try adding
.WithDisposeOnCompletion(allTargets)
Thank you that was the problem. This error message really confused me π
Also, it looks like you could add the entity translation as an argument to your ForEach() call since you don't need the random access of GetComponentDataFromEntity().
Ah okay, I was about to ask if this was the entire system or not. Looks good to me
Looks like an error with your UnitMoveToTargetSystem. Based on the error, I would guess that you don't have WithReadOnly(allTranslations)
Ah my bad yes just realized that
No worries. I normally can't decipher these errors in my own project so I'm glad I could help haha.
Does anyone have a hack to show BlobAssets in entity's inspector?
I don't know why DynamicBuffer doesn't scale. I've lots of complex systems but those that are just for clearing a DynamicBuffer take the longest. I've checked dependencies now and gone back to Run() for these systems, no real reason to be found.
one of these clearing systems takes half the time of the whole frametime. completely absurd π¦
Maybe as an alternative have a bool flag inside the IBufferElement's to mark as active or updated, and basically try just never clearing?
makes no difference when it's inside the buffer, the mere existence of the ForEach with the DynamicBuffer slows it down. (the buffers aren't used, so size is 0) - What I really need to do is not iterate over every buffer so I'd need to build some IComp flag. Really annoying ...
and again, not sure what's going on that takes so much cpu time. the buffer is 0. meh, it's always what happens when I use DynamicBuffer. The NativeMultiHashmaps scale much better. And to think DynamicBuffers are NativeArrays really
was stupid to use them to begin with, per-frame data shouldn't exist on entities
I got rid of most of those cases but some trigger buffers are left over
just out of curiosity if you don't mind me asking - how else would you use a buffer other than a for each and why are the size 0?
ah i think i see what you mean, so you're using the existence of the buffer as part of the query in a way for the for each
so you've found even if the buffer size is zero it slows the ForEach job down?
that's what happens
that's interesting π€
i have a stress test running, 250k entities with such a DynamicBuffer and the Entities.ForEach takes around 10ms
I can ScheduleParallel it, to bring it down to 1.26ms but that's still too much for what's happening.
have you tested with just a tag instead of buffer to see what the difference is?
cos obviously the 1.2ms would depend on what else the job is doing
Just using an Entities.ForEach with a tag that is on the same entity takes 0.75ms of iteration time
that's interesting to know..
so does the IBufferElementData contain a bunch of different members
like even if it's empty, is it say just a struct with one bool or is it a bunch of different data
the buffer has a struct with 2 Entity structs, 3 ints and 1 ushort.
another system uses a more complex buffer and the timings are rather equal. so size doesn't matter too much it seems
i'd guess the job has to allocate and deallocate memory for that maybe that's the issue.. if there's say a job running a query of 250k entities and each entity could have any number of buffer elements, maybe the allocation is the overhead
I don't know, from my experience now I'd say don't ever use DynamicBuffer when a) it's on a lot of entities and b) when it's fast changing data, like for only 1 frame
the buffers should be allocated by then
did you set the InternalBufferCapacity
I guess the buffers are all over in memory so that's why iteration is so slow
yeah just thinking about heap/stack business maybe slowing it down, cache misses galore etc
hm, where would I set the InternalBufferCapacity? It's not a parameter in AddBuffer
you add it to the bufferelement
// InternalBufferCapacity specifies how many elements a buffer can have before
// the buffer storage is moved outside the chunk.
[InternalBufferCapacity(8)]
public struct MyBufferElement : IBufferElementData
{
}
try setting it to 0 to force buffers to always be out of chunk
ah, thanks, ok I'll try that
by default it's occupying chunk space
do you know what's the default value for InternalBufferCapacity?
ok that brought it down significantly, not as much as where I'd want it to be but from 10ms to 2.5ms
I think my archetype got way too big. Last I checked I could only bring 11 entities into the chunk
default seems to be 128 / elementsize (basically 128 bytes rounded up depending on your struct size)
but that's per entity so it adds up
also yea only 11 entities sounds like a pretty big archetype
cool, saved a bunch of milliseconds, big thanks Scorr!
yeah, I need to split it up somehow. Not sure how though, lol. All the data is required. Still, I must be able to bring it down and split it into 2 other references. Hard to say how much I'll gain though
maybe I'll rather wait for the new entities version, at some point it should be possible to set the chunk size yourself
ah, i see with the capacity change to the buffers I can already fit 15 instead of 11 in a chunk
Have you considered splitting off some of you data onto different archetypes or entities assuming you're not using all of it in each job or system
yeah, I wanted to finish the system before I make optimisations. now's a good time π
When I do this: using Unity.Collections ; I have access to NativeArray, but not NativeList, why? Unity 2020.LTS and latest Rider
No. Is there someway I can download this without using Package Manager (like, direct from Github?)
... Why?
Because I don't want to download it through Package Manager. The last few times I've given Package Manager access to the internet, it's downloaded multiple versions of just about everything ever seen, and took up many, many gigs.
Well, if you don't have the package, you can't use the classes. Unity doesn't host it elsewhere, but needle hosts mirrors of everything. I'm sure you can find it
Found that. THANK YOU!!!
Why the attitude?
Having downloaded it, how do I install it?
For anyone else, looking for a NativeList, recommend you try JacksonDunstan's version. Can experiment without Burst ruining your iteration times: https://github.com/jacksondunstan/NativeCollections
Put the package in your Packages folder
how would I make an authoring component for a singleton entity? For example for a ScriptableObject or a prefab, so that it only adds a singleton once.
Make your singleton prefab and create a bootstrapper object that checks for the existence your the singletons on start and instantiates them if they're not there.
Is that what you're asking?
Oh sorry, didn't realize I was in DOTS.
@velvet panther the package manager will just keep a cache of all packages you've downloaded in your appdata (local or localroaming) folder. it doesnt download things you havent personally needed. you can just delete that folder, but it will always 'fill up' again as you download packages.
yeah it's a bit irritating i think people have been asking for years for a way to change the default package cache, pretty sure it also caches paid assets which in some cases are huge
you can change the directory of where it gets downloaded if anything and put it on an different drive
is it possible to do that now?
Been that way for a few years
how is this wizardry achieved?
tbh it's not something i've looked at for a few years, other than to notice i have a pretty big chunk of space being eaten up by the package cache
there's an environment variable you can set IIRC
https://docs.unity3d.com/2019.3/Documentation/Manual/upm-cache.html See Customizing shared location
UPM_CACHE_ROOT I think edit: was too slow hah
ah yeah, i guess this would cover assets also then
I've been tracking this probelm for a couple of weeks, on and off again. It's got nothing to do with what i use, or have ever used. I run very lean. CInemachine, TextMeshPro and thats about it. Yet it downloads multiple versions of every package of Unity, every time it's given access to the internet. Worst was about 10+gigs, hence I noticed it.
Each time I bring it up, someone is dsimissive about it, in some way or another, as though it can't happen, or I've done something. I haven't. It's just happening, so I've cut off Unity from having any access to the internet
Which of the MANY folders in there?
I'd seen mentions of this problem for a couple of years, first time I've experienced it, that I know of. It might have been going on for a long time and I simply hadn't previously noticed it. eg. I've never used HDRP, but there were half a dozen versions in there, for no good reason.
I recently started using Burst... the verified version for 2020,LTS... the next day... 1.6 and a bunch of earlier ones were in there, taking up a couple of gig. This is what first drew my attention to this behaviour.
yeah mines about 8gb at the moment and has a couple at least of versions of most of the packages
just deleted mine to see what exactly happens on a new project
i think the behaviour of assets has changed but it used to be assets would also mirror onto the c drive and it was almost impossible to prevent
having lots of large assets was a problem
collab, nunit, rider, visualstudio, vscode, test-framework, textmeshpro, timeline are the default for the package cache, theres also a larger npm cache that instantly went to 1.7gb that I assume is copied from the unity editor folder? package folder is only like 50megs though
@velvet panther I mean there should be the expectation that in a complex program like unity there will be a fluctuating amount of data with regard to custom projects. cutting unity off from the internet seems excessive to me but idk. you could setup a scheduled task to delete that folder. and if its really doing stuff that seems out of the ordinary and is a repeating factor, you could easily report it as a bug
Mine blew out to over 14gig the day I was paying attention to it. I was able to strip it back to under 2gig a couple of times, before it would balloon back out to 10-ish gig.
Every X
every XR thing ... for example, small, but all there... added, over and over. Your excuse making is weird. NO APP should be downloading such things without express permission.
As for bug reporting. I've been using Unity for long enough to know how fruitless that experience is.
My general thoughts on the package manager are that it's better than the hub, but not any other part of Unity. And that's right at the bottom of the barrel. Worse than SRP.
speaking of DOTS, when can we use Span<T>?
If I add an IComponentData not used anywhere in program except to be assigned to Entities, will they even be added? I'm trying to just tag something... for some reason the entity doesn't have the iComponentData attached.
Can technically use it whenever, but IIRC Span doesn't natively exist in Unity's mono environment, you need to import the DLL into Unity
A builtin unsafe alternative is using stackalloc
or just stick with NativeArrays with Temp allocation
maybe unity does need a timed decay setting in which to purge that folder, but if you dont want to report something that is causing you that much frustration well I guess whatever then
Check the very top in the Entities inspector, there's a header called Tags
It was not a tag tho. It showed up, but I couldn't find it since I had so many datacomponents. Thanks It does show even if not used.
Now it does as of 2021.2 π₯³ - not that 2021 is recommended with dots of course.
My next question and I'm done asking for a while... If you Entity e = EntityManager.Instaniate(pooledEntity); You can then add and remove components. But if you do this with an EntityCommandBuffer Instantiate (pooledEntity) then EntityCommandBuffer RemoveComponent (pooledEntity)... What happens is the pooledEntity gets modified. How can I instantiate a pooledEntity in EntityCommandBuffer then modify the cloned instantiated entity without messing up the original pooledEntity?
based on what you've typed, you're doing removeComponent on the pooledEntity.. so you'd want to do:
var newEntity = ecb.Instantiate(pooledEntity);
ecb.RemoveComponent<MyComponent>(newEntity);
You can do that1?1
I thought the entity wasn't made until ECB instantiated after process
It makes a reference straight then and there? wow! I would have never guessed that!
yeah i'm not sure exactly how that works, i assume it returns a dummy reference and allows you to use that in additional commands
cheers, am using Stackalloc very heavily, and looking forward to cleaning up around Span sommetime in the future.
int**[] for now... π
That's really cool MidnightCow... The Unity Devs reallythought it out
Makes you wonder if they know about phantom references why we can't link Gameobjects as entities in scene
Should be trivial... Maybe they didn't care.
i think that's just more to do with using reference types and managed objects which is kinda anti-data-oriented
basically anything that is a class and not a struct or anything that is stored in managed memory is going to drag down your ecs systems performance so it kinda defeats the purpose
if i understand your meaning
Oh yea cool, I remember reading that
good to know too cause I just updated to 2021.2 lol
Hey everyone, how can I get the entities from a chunk (not the components)?
Something like this would be nice var entities = chunks[0].GetEntities()
I'm asking because I'm currently trying to optimize a job, so far it's gone horribly wrong. Maybe my approach is just wrong.
The current job is receiving NativeArrays instead of batches since I don't know how to get the entities from a batch
I think you want to look at IJobChunk/IJobEntityBatch instead as they natively allow you to do chunk iteration.
To get the Entities of the chunk it'd would look like so
struct SomeJob : IJobEntityBatch {
public EntityTypeHandle EntityType;
public void Execute(ArchetypeChunk chunk, int batchIndex) {
var entities = chunk.GetNativeArray(EntityType);
for (int i = 0; i < chunk.Count; i++) {
Entity e = entities[i];
// Do something with e
}
}
}
// In SystemBase
new SomeJob { EntityType = this.GetEntityTypeHandle() }.Schedule(someEntityQueryToIterateThrough, Dependency);
https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/ecs_ijobentitybatch.html
Can I fill in a BlobArray by passing existing BlobAssetReferences instead of actual values?
or rather, is this legal: BlobArray<BlobAssetReference<SomeRegularStruct>>?\
You MidCow, that code did not work, I get: ArgumentException: All entities created using EntityCommandBuffer.CreateEntity must be realized via playback(). One of the entities is still deferred (Index: -1).
Let me show my code, I think its similar to what you gave.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Above is declared entity e, and the array is my object pool buffer of one entity each.
In entities 17 it is not, it will be in the next versions. The issue is that a validation method in hte entities pacckage does not allow for generic type.it can be fixed if you make a local copy of the entitites package https://forum.unity.com/threads/blobarray-with-valuetype-generic-parameters-fails.1045639/
I already commented that validation out. So there's no errors. I meant more like, is that a bad idea to store a reference inside a blob
As long a you release it properly I don't see an issue, but I'm no expert ;).
what do you mean release?
Blob asset are unmanaged memory allocation so they need to be disposed/released when no longer needed. if you dispose of the 'high' level blob it will not automatically dispose of the blob inside it, so you should probably do somthing not to leak memory.
are you sure about that? I thought they become part of the subscene and get disposed along with it
hmmm... I don't know if subscene do something 'magical', I'm not using them rigth now (issue with UITK+entites+Input system, long story...) but blob are not restricted to subscene so I don't see why subscene in particular would make the blob behave differently. Maybe the blobassetstore does the job. To be honest I make a blobasset reference on start up of my game and never destroy it so either I'm leaking memory or something magical happen on game shutdown. Either way, I will probably need to test it further at some point (once I figure out how to profile such cases) but I would not bet on thing happening automatically.
hmm i think i'd need to see more of the context.. it could be that RemoveComponent doesn't work but definitely AddComponent works fine the way i showed..
There should be no folders in there other than previously manually installed packages.
I know. I know... I've heard this everywhere I've mentioned this issue. And I'm by no means the only person having this problem. On my workstation, this hasn't happened.
No, the one in the user root library.
Then that's not where you install packages manually into a project.
You can also just add packages from any location from disk https://docs.unity3d.com/Manual/upm-ui-local.html
I'm not currently discussing that, I'm replying to the bloat!
That didn't work. I tried that means from disk.
My reply was directly discussing that
My mistake, I thought you were making the same claim that everyone makes about the packages folder in the library, that it shouldn't have all that extra stuff in it.
I've cleansed the manifest, etc. It still happens. Deleted all but one install of Unity (only using 2020.LTS on this) and it's still happening if I turn off Little Snitch for a sec.
I just have a symlink for my packages directory. I just stick the entire Unity cache on a large drive
hey vertx while youre here, I think the dots wiki in the pinned messages should be removed, its kinda old and no one updates it and some of the info is a little bit "eh" and I dont have the desire to go sort it out(as a previous contributor)
Sure, is there anything that should replace it? Or are we all just waiting for Unity to come out of hiding before recommending ECS π
when Unity Unity's..
Not sure theres any replacement but tbh the regular forums are better(though not really organizedπ)
Amatuer cow, I'm on 28 min now in one of my projects I am working on
key is to work on more than one project at once
Then when one is loading, you're coding in another
Why does this line alone trigger the error then? e=ecb.Instantiate(firstEntity[index]); I can't set addComponent to e if I can't get e like you say. That was really sus code anyway. I never expected to work...
Full error: https://pastebin.com/Y0w10apH
So my original question stands: How do you use an EntityCommandBuffer to instantiate an entity from an entity then add or remove components without affecting the original entity?
this is why i'm saying more context would be useful.. like is 'e' the actual Entity passed in to your ForEach for example.. the way i suggested was basically this which works for me at least with AddComponent:
Bear in mind also if it's a parallel job you should use a parallel ecb and pass entityInQueryIndex into the job
Entity e;// Just declared.
I can post full code after a nap, adrenal fatigue got me. brb in a few min/hrs.
For when you're back - i just tested, added TestComponent to my prefab entity and then removed it from Instantiated clone with the ECB as follows so it definitely works..
This line works: ecb.Instantiate(firstEntity[index]); This line does not: Entity e=ecb.Instantiate(firstEntity[index]);
wow
it was the var
somehow the var is generic enough to break typecasting or something
var e=ecb.Instantiate(firstEntity[index]); works
Thanks Cow, you da man... cow... maybe minotaurish thinger
ahh glad to hear you got that working
Thank you very much once again!
I actually smashed through two brick walls today.
One the reason entities were not rendering on my standalone had something to do with an HDRP configuration file. I'll figure the details later.
The reason I could not delete stuff before was because when I instantiated from an entity(pseudo object pooler), it was removing disabled and such from live components, rendering them able to be destroyed.
So now stuff is pretty good. I hope to finally get a standalone working and see how much I can render for real!
Also my players will like an update to benchmark their rigs.
Very cool, very cool, very cool, praise God. Ok, nap time for real. Remember, anyone who helps me, If I make bank, you make bank, but you gotta remind me. I get help from TONS of cool people. That's one thing that has made the Internet great as long as I've been on since 1994, the silicon valley tech worker desire to help others.
Thanks, I got it to work performantly with IJobEntityBatchWithIndex
jobcomponentsystem will be deprecated. systembase is the new standard
how is systembase slower if it gets more fps?
according to your picture
It had lower average fps but maybe that was because of a mistake on my part, I may have had a memory leak I didn't notice
also does anyone's VS debugger get stuck in "Application.EnterPlayMode"
it's been 5 minutes
half the time my debugger gets stuck and crashes
No but you may try to enable fast enter playmode
i have that enabled already
what's the difference between GetEntityQuery and EntityManager.CreateEntityQuery
GetEntityQuery is a convienience method of SystemBase
makes sense, they're functionally the same though
pretty much
nice
GetEntityQuery also allows the SystemBase to track the EntityQuery as a dependency, if you use EntityManager.CreateEntityQuery it bypasses the system dependency tracking. (If you're not careful in tracking dependencies you might incur an issue where a job attempts to access data that requires a prior job to finish.)
GetEntityQuery also attempts to cache the query
Anybody ever had the issue where suddenly most of the systems have just vanished
i removed a plugin folder and replaced it with newer version and now when i run most of the dots systems are just gone, including my own systems
This is all i'm left with..
No errors or anything, all entities/physics/etc packages still installed etc as before
are the PackageCaches all in place?
yeah they seem to be, in Library/PackageCache
i wonder if i delete them all they'll automatically replace
they should, yea
deleting whole library folder, see what happens
How do people generally handle most of unity's UI related things in dots? for example, GUI hub, displaying text/damage numbers in game or opening temporary skills/option panels?
Do you display them with normal unity components with monobehaviours, then use events to update them?
I could see that working for the UI hub, curious if there's a more pure ECS way.
Also, really curious how we'd spawn damage numbers to display...
Sorry if this is vague or basic π
Yea that's one way, I think the lack of a decent UI solution makes it fuzzy to figure out a better way. You can try hybrid components and have entities manage gameObjects, but it feels a bit clunky
For 2D I just ended up writing out mesh data to display text and have a render pass draw it out in URP.
Shameless plug: https://forum.unity.com/threads/in-development-nimgui-a-1-draw-call-immediate-mode-gui-for-unity.1171601/
But I'm building this out so you can use immediate mode API to draw out UI via SystemBase or MonoBehaviour which is pretty much what I'm describing with building out the meshes and having a renderpass draw out the UI.
all good need something like that to be standards.
Is there a nice list of hybrid components somewhere?
if I simplified things to attempting to spawn damage numbers (3d world), what's the best way?
Hybrid components can pretty much be any MonoBehaviour. As long as during conversion you call conversionSystem.AddHybridComponent(component) https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/hybrid_component.html
So you convert your entities as usual and unity internally tracks and create a hidden gameobject
I don't know how well it works with Unity's UI, mainly because I imagine you have to convert everything (including the canvas)
Yeah the requirement of a canvas is why I couldn't just spawn some of the things I tried.
I say start simple, figure out a way to get data from entities (maybe via events or write data to static container and at the end of the frame read the data from a monobehavior and display it)
you might need to double buffer if you're doing a lot of stuff in parallel and writing to a static container so that you don't mess with read/write access (so after jobs are completed, copy it over to a new buffer to avoid race conditions).
If i wanted to create UI items during gameplay, how would I attach them to a canvas?
I feel like I could get a static GUI to work in a couple of ways like you just said, but the playtime display changes are a bit more confusing
Well I'm more describing writing data that needs to be displayed to a static container (not a static GUI)
so it'd look sometihng like this
well anything that's existing when you start the scene
so the stuff that doesn't exist statically, and might only be displayed for a few seconds at a time. Those spawned UI pieces are still pretty unclear to me right now
an image or prefab would be fine, but text and numbers that could change. idk
// In a SystemBase
NativeArray<int> data = SomeStaticClass.NativeArray1; // Or use SharedStatic
NativeArray<int> data2 = SomeStaticClass.NativeArray2; // Our double buffer
Deps = Entities.ForEach((...) => {
data[x] = some_data;
}).Schedule(Deps);
Deps = Job.WithCode(() => {
for (...) {
// Copy the data to double buffer, so we have a safe readonly data
// for our gameObjects
data2[i] = data[i];
}
}).Schedule(Deps);
// In a monobehavior attached to a gameobject
void Update() {
for (int i = 0; i < SomeStaticClass.NativeArray2.Length; i++) {
// Your text mesh is cached and already created or pooled
// and managed by a MonoBehavior
someTextMesh.text = $"Data: {SomeStaticClass.NativeArray2[i]}";
}
}
kk then I guess that textmesh would be part of a prefab with that mono attached, and then you spawn it, having it's mono fetch the data
Yea something like that
kk, my thought's weren't far off the mark, I just didn't think to attach a mono to a textmesh prefab lol
thanks man.
The Entities.ForEach statement contains dynamic code that cannot be statically analyzed. what the hell does that mean, lol
Hmm no didn't work, my systems have all still vanished :/
What in the f* could cause this.
at this point you probably need to debug the place where the systems are auto-registered
Even the unity package systems are missing
animation, physics, whatever else
last thing i want to do is have to setup another project and copy all of my assets etc over
how do you guys reset / reload a scene
SceneManagement.LoadScene doesnt seem to reset the World
i finally got 100k entities rendered using texture based bone animations
no LOD or culling though
shits pretty nice
did you use an asset for that or write your own shaders etc?
i used shader graph
used a custom function node and basically injected all the instancing code into it
i wish there was an asset
look at the Austin Untiy ECS demo
has everything you need
@devout prairie
That's interesting thanks, i've been tempted to look into this
Have you looked at implementing AI in some way?
what kind of AI
I wonder what different approaches there could be to automating 100k characters
you basically need to be really good at parallelizing your code
and optimizing it for BURST
well they have to be moved around right.. just wondering how that could be approached
i use A*
true yeah
Nav mesh would work too
do you have physics bodies for collision or raycasting for ground or anything like that?
is your ground flat?
if you want them to stay grounded you can sample a heightmap or something
and set it to that height
yeah i was thinking heightmap is an option
my ground is flat, yeah
i haven't gotten that far yet unfortunately
wish i could be more helpful
just thinking out loud tbh i'm using Rival at the moment and it scales really well to thousands of ai with collisions etc
but not 100k hehhe
no it's cool as i say just thinking out loud
yeah i think Rival raycasts each character controller against the ground
i'm using the SimpleAnimation system which is good for animating skinned characters but tempted by the idea of doing the shader based texture skinning/animation
it's unfortunately not the most efficient way, but it's very good for a generic controller
i saw that
I talked to other ppl here who said that they're(Unity) basically going to develop a tool for ECS that does all of it for you anyway
so all the legwork you do now might not be very efficient use of time
i tend to agree
yeah it's a really good robust controller with lots of great features, maybe not applicable to 100k characters but it does work well for very reasonable numbers
the shader based stuff I would say is easier and more efficient to do imo
than using the DOTS animation package
which relies on the DOTS Node package too
with barely any documentation. very steep learning curve
not as efficient as shader based gpu skinning either
yeah the dots animation package is i think a really nice starting point for what it is, but for skinning for sure there are more hyper-efficient ways
i think currently the simpleanimation system is building/updating the graph each frame etc
significantly faster than skinnedmeshrenderer though
yeah i forgot the reason why
i think they were loading the skinning info into a compute buffer and calculating the transforms in a compute shader
tbh i think the overhead of Animator has a lot to do with it
not really sure
the disadvantage of baking bone transformations into a texture is
so i think possibly the skinning and deform stuff was fast, but damn the animator is just a pain to use and slow
that there are no blend trees for lerping different animations
was limited to circa 1-200 characters depending on complexity
also the Austin demo limited it to 2 bones per vertex instead of the typical 4
yeah so is there no way to lerp with that system
not possible to sample the textures themselves to lerp or something
if you find a way to do 100k ragdolls with skinned meshes let me know π
lol
i've built a ragdoll system that works with physics joints and basically overwrites the AnimatedLocalToRoot components on the skinned characters
it's faster than traditional unity ragdolls but i think could be faster still
well it uses a ragdoll built with unity.physics joints
then the systems that transfer data are parallel and bursted
how many ragdolls can you get going before a slowdown?
i think i had issues where it slowed down between 250-500
hi, is subScene.sceneGUID static, and if so is there a way to access it in the editor somewhere, without having to do it through scripts?
Had fun rendering 100,000 slimes at a time :)
Lets say I want to use DOTS just for the bullets in my game and have everyrhing else be normal. Is that possible and not a total clusterduck to achieve ?
A post with content for the first time in months? https://forum.unity.com/threads/very-poor-performance-on-mobille-when-having-a-lot-of-system.1184056/#post-7590175
To be fair, that sounds to me like an incredible performance optimization to an already incredible system..
runs away
You can use ISystemBase now if you want to see what it's like. It is an improvement but also a massive headache to avoid everything managed. I'm sure they'll make it easier. I'm more interested to hear of the optimisations to the type handle stuff.
you guys have any sample code of getting the distance between 2 objects written inside normal Jobs?
or wait does the math library have that? (checking)
well you can do like:
math.distancesq(pos1,pos2) or math.lengthsq(pos1-pos2)
is branching code totally not supported in Entities.ForEach?
what u mean?
I'm trying to do sort of a "add or update" on a NativeMultiHashMap, using TryAdd. I'm getting an error The Entities.ForEach statement contains dynamic code that cannot be statically analyzed
there's an "IsUnsupportedBranch" check in CecilHelpers, which I think triggers that. But I don't understand those analyzers
"no date yet..."
ruh roh
I remember they promised Unity 2021 DOTS support by like December
It's practically Nov and no update
whaaat, where?
somewhere in the forums ...
It was more in line with " incompatibility above 2020.3 at least until end of the year"
We have no estimate whatsoever, so could be Q2 2022, or worse
we just don't know
yeah that was it ... if Joachim comes out this morning and says "no date yet" then that means they're no where close to next release
i would guess late Q1 or Q2 like you said
I wonder if they have a dependency on changes needed to Unity Editor, so they can't even say if next version of Entities will be released to the public.
Any reason why dots animation and physics may play slowly or at a different rate, independent of framerate?
Having yet another weird issue.
Framerate larger than x*fixed rate, where x is max steps per frame. perhaps?
does Entities.ForEach exclude Prefabs by default?
yea
even in entityqueries they're not included by default
unless you enable the option to query them in the EntityQueryDesc
Hey @digital kestrel, with your animation system, are you able to read the animated bone positions on the CPU? For example, let's say I wanted a character to be holding an item in their hand, but the character's arm and hand are being animated using your texture-based animation shader. Is there a way to do this?
I guess one option is to have the shader moving all the mesh vertices, and separately some CPU code that also reads the animation textures and writes to bone positions.
I'm currently using the animation package, but it seems a bit overkill. I don't need blending or multiple bone weights per vertex.
not really
if you knew the final position, you'd just pass that to the GPU instead of handling the skinning in a shader
you would have to recalculate it on the CPU which would defeat the purpose
the advantage might be that you can skip the calculation for everything else (other body parts)
which could save you some time
well gpu would be moving all the vertices for you. cpu would just be moving the bones
all the bone positions are baked into the texture
so the CPU doesn't do any bone transform calculations after the initial pass
it just sends the animationa's normalized time value and uses that to sample the texture which has the bone positions
Yeah, I understand that part. I meant cpu could sample the baked texture and move some bone entities around. This allows for things like item attachments.
yeah
you could bake all of the transforms for the hand
and store that on the CPU and just apply it exactly how you would on the gpu
like you said
no need to store it in a texture, just store it as a separate float4x4
yeah good point about not needing a texture on cpu side
it would be a lot more efficient since you're only calculating one bone per mesh instead of all N bones, and applying world transforms would be trivial
especially if you vectorize it correctly
yeah seems it could work well
if you need blend trees, i wouldnt use texture based animation
I guess another considering is to do all the animation on the cpu side with the baked bone positions. I think I would need a separate mesh/entity for each bone. However, I like the idea of my characters being a single mesh, even if I don't need multiple bone weights. Makes it easier to apply material properties to the entire character.
I haven't looked at how blending is typically implemented, but couldn't it theoretically be done in the shader?
But yeah, at that point, I would just use the animation package.
Thanks for the insight @digital kestrel! Not sure if I'm ready to switch to baked animations yet but good to know what is possible.
good luck, let me know how it goes!
i might release it on the asset store for like $10 lol
How am I supposed to pass BlobAssetReference to a IJobEntityBatch? I'm trying through a public field on the job and doing ref var array = ref TheReference.Value.SomeArray and debugger shows random numbers instead of what I expect π€¨
ref blobAsset or a copy?
just pass in BlobAssetReference
var myAsset = MyBlobAsssetReference;
job.withcode(() => { ref var array = ref myAsset.Value.SomeArray; }).Schedule()
should work from memory
(been a while since I've used a blobassetreference that isn't attached to an entity, i have my own custom memory system that i use instead for memory not on entities)
interesting. thanks I'll try that tomorrow
Holy shit, Unity is alive.
No info but the CTO is once again on the forums. Entities 0.20 ETA has moved from "Heat Death of the Universe" to "Sometime next year".
Misgivings over timescales aside, i think it's insanely cool that the co-founder is still balls-deep in the technology. A great many software companies have long since sold off and being run by money managers. I really genuinely believe what Unity is doing with dots/ecs will be massively transformative, but i do think it will take some time to achieve.
It can be frustrating i think but it's really cool to be in for the ride, and given access to the tech while it evolves. It feels less like a marketing exercise and more like a genuine contribution to realtime/game-engine technology.
He started Unity at 19 lol
I didn't even realise he was the Co-founder 
yeah, its awesome hes super hands on with dots. I dont think I wouldve been an early adopter if we didnt have someone at his level of clout in unity being this enthusiastic about it
how do we know 0.20 got moved from "Heat Death of the Universe" to "Sometime next year" ?
we dont really π₯²
anyone know:
If I use ConvertToEntity scripts on an object with lightprobes component attached, will the lightprobes still work correctly?
Personally, I think it's because the gag-order on all employees talking about Entities (the main DOTS package) seems to be lifted. The CTO is out there once again answering questions and describing intended DOTS usages so the next package seems to largely re-solidified around a timeline. That means release sometime... soon-ish.
I have android app and in scene there are a lot of simple box colliders may be about 200k. Im using only one raycast and thats all. No collisions events or any rigidbody objects. So i have this profiler screen. Any tips or suggestion what should i check or what going on ?
does Hybrid renderer v1 work with per-entity material properties in 2020.3.20f1? I try the override property declaration/hybrid per instance and it does not seem to work
Whatβs keeping you on v1? Built-in!
nope, webGL
v2 doesn't work for webGL but v1 does π¦
The mad thing is I have another project where the per-entity props worked fine and I can't seem to figure out why it doesnt in this one
i have problem with v2 on android and unity 2020.3.20f1
Slightly surprised v1 worked without just a new material
https://elliotb256.itch.io/ecscombat this one is using v1
same material on all ships, and a '_TeamColor' material property
ahh, my mistake - I'm using one of the pre-defined render properties, not my own in that project: https://github.com/ElliotB256/ECSCombat/blob/master/Assets/Battle/Misc/SetTeamColorsSystem.cs - maybe that is the issue
The user manual states that V1 supports custom material props but that doesn't appear to be the case, unless I'm doing something daft https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.11/manual/hybrid-renderer-v1.html
Just a quick update on this, in case anybody has a similar issue.. the problem was in the ProjectSettings->Time settings..
I think the default is something like this:
Whereas i had cloned the Unity Physics Samples project, deleted all assets and scripts, and imported my own assets and scripts into this. It took me some time to realise the the Physics Samples project uses these settings, which essentially seemed to slow everything down:
Physics samples also has some code that sets:
Application.targetFrameRate = 60
I'm not exactly sure of what the implications are of all this, how these settings interact, but that's where the issue was.
still seeking an answer on this:
you can use ConvertAndInject and keep your gameobject rendering in monobehaviour world. But i don't know will light probes work with DOTS rendering, i think not
ill just duplicate the object and remove the renderer, that way the probes stay on a non-ECS version, im assuming they will still project the emission onto an ECS renderer, just wondered if converting the probes to ECS too would work
they should, probes get a companion gameobject on conversion @gusty comet tbh Im not too familiar with companion gameobjects and subscenes
I view anything outside of just plain vanilla rendering kind of experimental when it comes to dots graphics, light baking is kinda glitchy, the actual results with stuff like spotlights only show as point lights, occlusion is buggy etc
speaking of Companions, I recommend adding DOTS_HYBRID_COMPONENTS_DEBUG define to see companion objects in scene hierarchy when needed
When writing a sequencing system, and wanting to ensure that it's possibly suited to Burst/Jobs if needed for performance, should it be that all the system exist in one class, and use structs for any separations of data/state and methods? And are static arrays OK?
yeah im planning to only use ECS for the actual renderers, i've already got duplicate items as children to take care of colliders etc, so I may as well put the probes on them, that way it wont need to create companion gameobject for the probes themselves.
IIRC this helped me prevent an error spam where Unity complains you didnt disposed a collection in time, i.e. having an Allocator.TempJob and a framerate high enough to exceed the 4 frames limitation
Uhmmm
Yeah it actually says something about that in the comment next to that line of code
good news finally π
I new it wasn't dead
....(I didn't)
dots was never dead
They had to smooze the board before they could say anything to the peons >.>
Does Hybrid Renderer V2 need Vulkan API for android?
It would be nice if they actually proved a timeline however
Because
Can be anywhere between next week to Q2 next year and beyond
timelines are bad because predicting how long this stuff takes is nigh on impossible
isn't there a saying with programming, that however long you think its going to take its going to be at least twice as long
is querying for reference types as fast as for the data structs ?
lets say a Player monobehaviour and a PlayerData struct
you cannot use reference types with dots. there are some .....workarounds but you really shouldn't
Yeah you can i saw that in the FPSSample i wondered what was the drawback
[DisableAutoCreation]
public abstract class BaseComponentSystem<T1> : BaseComponentSystem
where T1 : MonoBehaviour
{
ComponentGroup Group;
protected ComponentType[] ExtraComponentRequirements;
string name;
public BaseComponentSystem(GameWorld world) : base(world) {}
protected override void OnCreateManager()
{
base.OnCreateManager();
name = GetType().Name;
var list = new List<ComponentType>(6);
if(ExtraComponentRequirements != null)
list.AddRange(ExtraComponentRequirements);
list.AddRange(new ComponentType[] { typeof(T1) } );
list.Add(ComponentType.Subtractive<DespawningEntity>());
Group = GetComponentGroup(list.ToArray());
}
protected override void OnUpdate()
{
Profiler.BeginSample(name);
var entityArray = Group.GetEntityArray();
var dataArray = Group.GetComponentArray<T1>();
for (var i = 0; i < entityArray.Length; i++)
{
Update(entityArray[i], dataArray[i]);
}
Profiler.EndSample();
}
protected abstract void Update(Entity entity,T1 data);
}
i am looking for a solution to have an event when a player is instantiated without the start() callback so i turned to ecs
it looks like you can query monobehaviours
i am not quite sure what that code does. nevertheless, it is vastly outdated
is this the only thing why you turned to ecs?
no ofc not but i'm trying to keep it at bay until its done
also what exactly do you want? you want to instatiate a player and NOT call start?
Itβs much slower to iterate. Thereβs no underlying linear memory layout with managed stuff (for a start)
its a wrapper for systems to no do the for loop and only output the entity and behaviour in a custom Update
basically yes i want to stay away from the unity callbacks i can do this once built but in the editor if on play mode i can't really iterate for players in the scene
why do you not want to use the callbacks??
Much slower than OOP ?
if you want to use monobehaviours anyway, using dots to query for them is just a stupid idea
I'm making a multiplayer game with my own networking and unity callbacks gets in the way
you are still using monobehaviours though
No. But if performance is your concern, youβll have to run some tests with the type of data you have and the kind of transformations you want to do.
Alright thanks for the info
i don't think you have an idea what dots is for. if you don't want the callbacks, just use your own methods
How do I use RequireForUpdate correctly? If I use it like this the system seems to stop running for some batches which match the query.
{
endSimulationEcbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
unitsWithoutTargetQuery = GetEntityQuery(new EntityQueryDesc
{
All = new[]
{
ComponentType.ReadOnly<MoveOrder>(),
ComponentType.ReadOnly<Unit>(),
ComponentType.ReadWrite<Translation>()
},
None = new[]
{
ComponentType.ReadOnly<HasTarget>()
}
});
RequireForUpdate(unitsWithoutTargetQuery);
}```
Looks okay at first read. You're saying you still have units without target that dont get processed ?
Never saw = new[], always saw = new ComponentType[] can you really be non-strict here ? π€
yes.
Oh good π
I don't see anything wrong in FlightFight code π€·ββοΈ
Something else might interfere
Yes, but it works fine without the RequireForUpdate call so it's no big deal
If you really wanted to interrupt the system another way would be to calculate count on the entity query and early exit in update
Is there an equivalent to MonoBehaviour.OnRenderObject() but for DOTS/ECS?
none out of the box, I imagine the equivalent would be writing a frustum cull test and determining if the entity's bound is within view
are the terms "DOTS" and "ECS" interchangeable? i've been calling everything ECS
Dots is data oriented technology stack, Unity's new approach to game development based on data oriented design. Ecs is entity component system, a piece of the dots "stack", Unity's way of connecting game design to systems and data.
So no. One is a component of the other, one is made of many components
Pretty much. Jobs and Burst are part of the technology stack upon which ECS is apparently being built. But everyone thinks of DOTS as ECS, and ECS as DOTS, and considers Jobs and Burst to be just helpers, and separate things. Which they are. You can use Jobs and Burst without having anything to do with ECS.
the "TS" in DOTS stands for "technology stack" but it was a contrived name, to give them some sense of accomplishment when they realised that ECS was years away from being ready. Hence the switch in naming, from talking about ECS and performance by default to "DOTS", so they can claim some parts of it are done. (Jobs and Burst are fully operational).
The name DOTS existed since they announced ECS, Jobs and Burst. They still talk about performance by default, they were separate and similar concepts introduced at the same time.
If you're talking about its elements, say them by name, if you're talking about them under an umbrella say DOTS.
People will know what you're talking about if you mix them up, but don't go talking about Jobs as if it's ECS for example.
ok thanks
These "facts" don't matter, as DOTS has become synonymous with ECS, in the minds of most, and the manner in which most discuss them. Few talk about Jobs at all, even less about Burst.
Look around the boards, the forums, in here... Stackoverflow, Reddit, conversatiosn in the real world. Anywhere you like. Many even write "DOTS/ECS" or "ECS/DOTS" when discussing them, just a way to be sure they've covered all bases.
People constantly do mix them up and don't want to bother being specific, what's your point?
Why you feel the need to scare quotes facts as if what I'm saying isn't true is beyond me
why you want to be scared by quotes?
It's a real term, feel free to google it
I know exactly what it is. I don't think you do.
I'll let you be unbearable by yourself then π
In this case, when using quotes around "facts", I'm drawing attention, in this construct. The use of the "scare" quotes is to draw attention to those things (the "facts") as separate from the subjective manner in which the terms have become commonly known. What you've presented as historical factuality no longer matters in the majority of conversations about ECS, because most consider it to be DOTS, and vice-versa. I'm, believe it or not, siding with you, on the original naming, meanings and terminology, whilst pointing out that that original definition is now a bit quaint.
One thing's for certain, it probably wasn't a good idea to let Unity's __A__cronym __R__esearch __S__pecialists & __E__nthusiasts also do the new logo.
Does anyone have an idea why is this exception thrown when I run this code?
var ecb = endSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter();
Entities.ForEach((
Entity unitEntity,
int entityInQueryIndex,
ref Unit unit) =>
{
var destroyedTargets = GetBuffer<DestroyedTargetsBufferElement>(unitEntity);
if (destroyedTargets.Length >= 20)
{
var maxLevel = unit.unitExperienceBlobAssetReference.Value.maxVeterancyLevel;
if (unit.veterancyLevel != maxLevel)
{
ecb.SetComponent(
entityInQueryIndex,
unitEntity,
new Unit
{
moveSpeed = unit.moveSpeed,
veterancyLevel = 3
}
);
}
}
}).ScheduleParallel();
endSimulationEcbSystem.AddJobHandleForProducer(Dependency);
}```
Unity.Entities.JobChunkExtensions.FinalizeScheduleChecked (System.Boolean isParallel, System.Int32 unfilteredChunkCount, Unity.Jobs.JobHandle prefilterHandle, Unity.Collections.NativeArray`1[T] prefilterData, System.Void* deferredCountData, System.Boolean useFiltering, Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& scheduleParams, System.Boolean& executed, Unity.Jobs.JobHandle& result) (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/IJobChunk.cs:270)
Unity.Entities.JobChunkExtensions.ScheduleInternal[T] (T& jobData, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode, System.Boolean isParallel) (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/IJobChunk.cs:246)
Unity.Entities.JobChunkExtensions.ScheduleParallel[T] (T jobData, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependsOn) (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/IJobChunk.cs:150)
Code.Systems.UnitExperienceSystem.OnUpdate () (at Assets/Code/Systems/UnitExperienceSystem.cs:38)...```
Never mind I think I found the problem...
the variable destroyedTargets needs to be read only so I need to figure out how to do that now
Nice that works π
Here's another weird one, if I access the maxVeterancyLevel from my blobAssetReference it works fine but as soon as I use the ECB ParallelWriter.SetComponent I get a null reference error.
protected override void OnUpdate()
{
var ecb = endSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter();
Entities.ForEach((
Entity unitEntity,
int entityInQueryIndex,
ref Unit unit) =>
{
var destroyedTargets = GetBufferFromEntity<DestroyedTargetsBufferElement>(true)[unitEntity];
var maxLevel = unit.unitExperienceBlobAssetReference.Value.maxVeterancyLevel;
ecb.SetComponent( // If I comment out this method call everything is fine
entityInQueryIndex,
unitEntity,
new Unit
{
moveSpeed = unit.moveSpeed,
veterancyLevel = 3
}
);```
Exception with burst compilation disabled:
InvalidOperationException: The BlobAssetReference is null.
Unity.Entities.BlobAssetReferenceData.ValidateNotNull () (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/Blobs.cs:279)
Unity.Entities.BlobAssetReference`1[T].get_Value () (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/Blobs.cs:365)
Code.Systems.UnitExperienceSystem+<>c__DisplayClass_OnUpdate_LambdaJob0.IterateEntities (Unity.Entities.ArchetypeChunk& chunk, Code.Systems.UnitExperienceSystem+<>c__DisplayClass_OnUpdate_LambdaJob0+LambdaParameterValueProviders+Runtimes& runtimes) (at <f74c023565104fd3b6e455b2c48d320a>:0)
Code.Systems.UnitExperienceSystem+<>c__DisplayClass_OnUpdate_LambdaJob0.Execute (Unity.Entities.ArchetypeChunk chunk, System.Int32 chunkIndex, System.Int32 firstEntityIndex) (at <f74c023565104fd3b6e455b2c48d320a>:0)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].ExecuteInternal (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/IJobChunk.cs:386)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].Execute (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/IJobChunk.cs:353)```
well, it looks like you're recreating the Unit component data, but not assigning the blob asset reference to this new component data, so it's null
Ah, yes that's it. Thanks for the help! I'll take a break
np, when it comes to ECS, code-by-error feels like the default process, haha
Is GetBufferFromEntity inefficient like GetComponentDataFromEntity?
Another question: Is it generally a better idea to store the BlobAssetReference on a singleton entity instead of a lot of entities?
So a person who is literally asking for the correct nomenclature should ignore the answers that include the correct nomenclature and explanation, and instead rely on your advice, which is to not worry about the correct nomenclature? You're hilarious lol
@muted star BufferFromEntity & ComponentDataFromEntity do have a price compared to captured variables, but if you're referencing data that doesn't belong to the Entities.ForEach, there aren't many ways around it. You could certainly put your BlobAssetReference on a singleton, and if there's only one Blob you're referencing throughout the entire Entities.ForEach, there's no reason not to, I feel.
did you miss all the caveats? "subjectively", "most", "majority" etc?
is there a way to use Blobs without ECS?
"No", in the sense that they belong to the Unity.Entities namespace. However, you could probably use them without much reliance on Entities