Also reading through the code line by line, seems like unity does not actually reduce the memory taken by physics world unless a hard reset (disposal and then restarting the physics systems) is done. Physics allocates the maximum amount of bodies across all frames and uses it. Fine except in cases where there's a sudden spike in bodies and then reduces back to normal. Physics will continue to operate with the spike quantity as its capacity.
#archived-dots
1 messages ยท Page 6 of 1
#1 change I would make 100% if I was CTO at unity: remove batchIndex from IJobEntityBatch Execute() parameter list. Make one with BatchIndex if people will be using it. Dont include it by default in IJEB because it fucks with intellisense since the var that needs to be used starts with batchIn... I want to be able to type: ba and instantly get the variable I want first and by default.
#1 change I would make 100% if I was CTO at unity: remove batchIndex from IJobEntityBatch Execute() parameter list. Make one with BatchIndex if people will be using it.
what benefit does this provide?
just your intellisense?
my ide learned that it was the wrong one ^_^"
Yes.
It cant be that hard. We have a separate IJEB with entity index. Just make a third with batch index as a parameter as well. Come on unity.
i doubt it'd be hard but it's kind of annoying
even having withindex is annoying
but that is done for performance reasons
Yea. I get why WithIndex is it's own job but come on unity, save us poor programmers with very dumb intelligence intellisense.
wdym? How is it breaking intellisense?
just naming pattern?
tbh, you can simply use IJobParallelFor
you'll simply have to switch 1 line in which you assign query to scheduling
to assigning chunk list to field of job
oh wait
you'll still have index...
nvm xD
It doesnt break intellisense. It's annoying when i type ba intending for the archetype chunk and end up instead with an int.
I have found 0 actual use for it in my logic so far so it's just a complete annoyance.
command buffer is generally the use case for it
i think i've only ever used it once for something else, something thread safe related
index for native stream maybe
You know what else I would change?
This giant list
It's getting as large as my screen is tall.
Huh, did they change how struct systems work? I cant cache a native array into the property field of the ISystem struct.
And yes, i'm disposing of it in OnDestroy(). I get that error one frame 1.
you can't until 1.0
the dispose sentinel is a managed object
it gets nulled in burst
Oh, oof. Right.
It is just one sized array so nothing major. Shame.
You did note earlier that arrays allocated with the update allocator can be reused across frames. I found no mention of that in the actual AllocateNativeArray method. Is that something the memory handler does?
You did note earlier that arrays allocated with the update allocator can be reused across frames
did i? because it can't really
they last 2 frames
and the memory is then re-used
2 frames because the world alternates update allocators every frame
this means you don't need to sync point end of frame to return the memory
and can still update through to the next time the system updates (in which case it auto completes)
The array itself gets invalidated but the memory slot it formerly occupied can easily be refilled by a new array the same size. I guess that's just regular memory.
is it bad practice to change the mesh frequently on the hybrid renderer?
Bad practice in general. If you need to do frequent mesh changes, do so in a compute shader.
Yeah I was just looking
looks like I can just adjust vert positions in shader
and bake verts to a texture
Hybrid renderer is just a really fancy dynamic indirect draw call system. Doesnt change the rules around rendering.
Yep. That's how terrains work.
A heightmap texture, generate a plane with vertices at every pixel.
So how would I go about generating a texture from a 3d animation I am trying to google around but just keep getting stuff about 2d
2D is discussed because it's easiest for programmers new to procedural graphics to understand. Add a third axis and you leave nice straightforward linear math and enter the world of linear algebra. Matrixes, quaternion rotations, cross products.
However it is fundamentally the same. The math though is exponentially harder.
What data do I need to save to the texture? vert position ofc anything else?
https://catlikecoding.com/unity/tutorials/advanced-rendering/tessellation/
This is basically what 3D procedural mesh generation is like.
It's tessellation shader so it's a decent jumping off point to proper vertex welding and ordering.
There's no index buffer so it's a simplified version.
awesome thank you very much!
That might also help. Typically 3D mesh generation will use a combination of the two.
Perfect
3d math is fun
I am inches away from purging the last remnant from my project. LocalToWorld is too big.
Float3x3 let's go
Yep. But then I'll have to either messing with the very slow 2D Entities sprite renderer or roll my own procedural drawing system
Off roll your own
I suggest making auto atlassing
And simply draw all sprites indtanced
I dont want to do the latter since I've seen how good the hybrid renderer API (dont know about the package) of 2022 is and I want to work with Unity, not against if I had a choice.
Well
In this case
You can use RenderMesh
But it won't use atlassing
My suggestion roll your own
Ehhhhh, I dont want to put up a temp solution if it's gonna be superseded within an update.
The only reason I rolled my own lighting is due to custom needs. My own physics because Unity themselves said they fired everyone working on 2D DOTS. And possibly my own netcode because I want peer to peer, not peer to server.
I know, I made my own 2D lighting. I know how fast it is.
If you just use combination of atlas and instancing
You don't need procedural
Even
Or if you really want
You can make it the way turtle did
By creating mesh every frame
I just, really dont entirely care about the performance cost of sprite rendering right now. I will have to either roll my own or somehow bend a material to my will as my lighting needs hooks into determining what to render so I'm thinking about it.
Just create a quad that matches the sprite dimensions. Not hard.
No
And scale it in shader using a compute buffer.
Why?
Fuck, you're gonna make me roll my own sprite renderer just to prove you wrong
i dont want to though, physics is more interesting
But it's literally what tertle did
Kek
We compared his drawing system and HR
It was similar somewhat
Does the sprite atlas v2 in unity pack concave sprites within / on top each other?
Concave?
Like a U sprite and a N sprite, does the atlas merge the U and N on top of each other? A leg of the N inside the bowl of the U.
Or does it specify rectangular bounding boxes for each sprite?
Ah, yea. Full rect will allow for a sprite renderer to use a single pre-defined constant quad and plaster it on the screen repeatedly.
No need for complex meshes. 6 vertices is all you need and you can make it a const static float2 in the shader.
Either collect all matrices and draw quads instances
Or use matrix to get local to world quad vertices and uv
Combine all in one
And draw in one call
Two ways I know of
Sprites can rotate though, but for a 2D sprite renderer, the GPU upload would be a 3x3. 2x3 used by the L2W and 2 floats on the C2 row for sprite UV on the atlas.
Ehhhhh, feed in a angle I guess. SinCos is fairly cheap.
You just get matrix for each vertice and multiply by ltw or entity
Best part it's super fast math
At least in float4x4 world
No idea if you can vectorize float3x3
That means GPU upload can be 1 float for angle, 2 floats for position, 4 floats for min max UV of the sprite in the full rect sprite atlas. 7 floats though.
Hmmm
3x3, with 2 floats left over for anything else.
That's some custom stuff
GPU will only accept 4x4 matrix
Or maybe vector3
Or mesh
Definitely not, my lighting shader, which is basically a sprite-less sprite renderer I'm talking about, accepts float4s:
And this is constructing a 4x4 L2W from a float3.
Oh, ewwww. Shadergraphs
Or thus
This
I mean
Do you really expect every 2d enthusiast to write their own shaders? xD
Yes.
3x3 only advantage is memory size. Burst will treat a 3x3 as a 4x4 regardless
Yeah
well no, a 3x4
Anyways
as the last row wont need a vp operation.
Your approach means no compatibility with 3d
Yea, I have 0 plans for 3D.
Meanwhile I don't want to miss out on that
How would 3D even interact with 2D?
Well
Ships asteroids and etc are 2d
Starts planets 3d
And they rotate
Without any spritesheet
Thus no need for pre drawn animation
Ability to use shaders for burning effect
Or planets atmosphere
That's my perspective
You can simulate rotation in 2D using a shader though? Just shift the UVs.
I don't have enough strength to implement all of it kek
I want to be close to release in one year
At least playable alpha
I am also not planning on ever releasing this.
I can't afford simply developing stuff with getting nothing out of that
Can't even apply for a job sadkek
Thats why I hobby dev. I'm grinding away at grad school in an completely different field from game dev.
hobby dev is fun. professional dev is not
I am very happy that I'm finally working with internal logic of game
Currently making Dev tools
Which will be used by modders or cheaters kek
Although implementing it is pain kek
Have to work with UI a lot
Maybe look into how unity dots editor tools interact with the editor's UIE.
Dev tools are runtime
it should be directly applicable considering they're working with the sum of all entities in a world and displaying it
As in use their method of interacting with UIElements to help with figuring out a way to interact with runtime UI Elements.
It's the same API.
It's more the Entities to UI hook that I'm interested in. Not the actual construction of the UI itself.
They have to display a lot of data from a lot of entities every frame. And they do so.
You can literally just copy package to local and modify it
Yea, I need to see what they use though. I havent dug into the package yet.
UI is a long way away so it's not a priority.
I constantly get error from internal logic xD
I'll send you stacktrace
Smth related to null archetype
I think it's because I use generics
What, Im not gonna be looking into it now.
I'm already going line by line through the physics package. I cant start on the UI at the same time.
Sprite rendering with custom shaders is simple enough though
Don't think I'm capable of reimplementing everything without burning out
Thats why I'm a hobbyist dev. It doesnt matter if I burn out. I'm here for education. Not for results.
Anybody knows if its possible to sort systems from another assembly. E.g just define that SystemA should be updated after SystemB although those are defined in other assemblies?
Only during runtime I think and through reflection
You have access to system's list
And you can probably edit constraints
Idk how tho
No idea about System's thi
ISystems
easier to just add them to your own system group
and override the sort
rather than use reflection probably
it's actually really hard for us to find dots devs atm, need more mainstream usage!
basically just have to train up everyone from scratch
Meanwhile here no one is even looking for dots. The only ECS application I found is for 2017 version of Unity xD
we're hiring atm! fully remote just unfortunately australian time zone =\
Well a lot of people dont trust experimental packages ๐
good chance not a single applicant i interview on friday will have even heard of dots
Had a lof of interviews where they heard about it but never used it.
Thats what I do. But I have an IK package with an IKGroup and a movement Assembly with a MovementGroup. Now if I want the IKGroup to run after the MovementGroup I have to define this in either of the Assemblies
But the relation is not implicit in either of the packages / assemblies. It might be project specific. So there should be a way to define their order in a third assembly
Otherwise it might get even worse with package manager and package dependencies. Packages would need to have a lot of dependecies on packages they might not even know of just for sorting and on the other hand you might have packages that you just cannot use because they dont fit in the order of your system groups ๐ค
i'm struggling to think of a case where you would need to explicitly assign order in 1 project but not another
where that project wouldn't have a 3rd assembly couldn't simply put ordering on IK/Movement
and achieve the same thing
e.g. you buy/download an animation package and an IK package. The IK system has to run after the animation system. but obviously the IK system does not even know that the animation system even exists
you could implement a custom bootstrap. not great but it would give you the most control
yeah thought about that. will be the last resort I guess as it is a pretty big change. would be better if I could somehow hook into the existing sorting
i know the struggle. we have some systems that we don't wanna run in a certain package configuration. a former dev implemented it by reordering/removing systems with an InitializeOnLoad method. not fast and not very intuitive. we'll probably switch to a custom bootstrap. will be a pain to maintain but we didn't really find any other options
cant you just have a custom system or system group to order them?
it doesn't need to be in either package
thats the only thing I came up with for now. Having an empty system or group and order it before one and after the other
but this does feal like a hacky solution. having and empty system as a splitter hanging around
it should be pretty ease for unity to implement some static method like UpdateAfter(System a, System b)
Otherwise this will get a real mess when working with a lot of external packages using ECS
or did you mean sth different? like a custom group with a custom sort method?
that was my original suggestion
it's not that simple
every single system group would need to look for this
they specifically switched away from explicit ordering a long time ago
From what I have seen there is a single FindConstraints method that looks for all attributes and creates the order.
The only thing this would change would be that this Ordering Attribute or Method would not have to be attached to a specific class definition
sure explicitly ordering all systems would cause other problems
Unity 2023.1.0 Alpha 4 is out
is that supposed to be a version with entities as default workflow? xD
Unity's still using 2022.2A15-Dots in their most recent training samples
noticed that joachim's gpu repo uses some of the new baking api that I assume is 1.0 stuff
As in the interface : Baker? Yea, that's 1.0
It's replacing the GameObjectConversionSystem for a much more succinct name.
And better code gen
Maybe. I havent seen anyone use an ECB in a baker though. It's all been small and for basic conversions: https://github.com/Unity-Technologies/DOTS-training-samples/tree/dots-training-2022-05-na-group1-Buckets!/Ported/BucketBrigade/Assets/Scripts/Authoring
Ugh, im gonna see if I can roll my own local to world. 2D is only 6 floats. 3D is 16. That's 10 floats of wasted bytes per entity
gonna have so many authoring components to convert with this update
oh man, I hope I will be able to avoid codegen fully
You and me both. I got a pile of [GenerateAuthoringComponent] that will probably need complete restructuring.
I always kinda hated that thing so I dont think I ever used it more than once or twice for test components
I do it for simple tag components and singletons. More complex components get their own custom inspector and conversion system
maybe its because I keep renaming things but it broke a few times here and there and I just swore off it. wonder if they do some replacement for it though
was enable disable supposed to make it for 1.0? almost forgot about that ๐
i have c# templates for authoring comps (so just copy/paste). who needs code'gen for something that simple. plus, i like the versatility it gives to customize the editor
the superluminal profiler is really quite something. it's vtune + vs profiler in a package that actually works without weird problems. funny in that sense that it just looks like a remix of both profilers at first glance
and it weaves code lines + assembly together which is probably the coolest thing about it
yep ๐
Tada. Removes 10 unused floats from my entities.
now i just need to get better at reading assembly because most issues i have are related to random memory access
An evergreen skill to have
MemX > VP > VS > SS
i'm looking for r11, yet the whole assembly of the method has no other mention of r11
makes me think i'm just looking at a fragment. :/
the burst inspector needs a simple, open in browser
Wow, math.select drastically changes the burst output. And I dont know if for the better or not.
which type are you using it with?
float2s
math.select(new float2(1), position[i], hasPosition) vs hasPosition ? position[i] : new float2(1)
ah yeah, should be for the better. have you used it instead of branching?
what's the assembly?
i was more thinking about the selector type. you are using bool, right?
yea, bool
kind of surprised to find it different. if you look at the math select code it's literally the same "? :"
I cant really post the assembly. it's such a drastic change it changes full pages worth of assembly
i've never seen new(1) instead of 1.0f ๐
Math.select definitely simplifies the code. If all three checks were inline tertiary ifs, it would create a branch for each one
it's new float2(1). With C#10 optional type parameter if obvious.
Makes refactoring a lot easier as there's less strongly typed new statements floating around
Is this valid?
...Inside system...
protected override void OnCreate()
{
controls.Player.SelectSingle.performed += _ =>
{
Entities.ForEach...
};
}
Maybe???? I dont know how well that'll play with the code generation.
You'll be safer off making a IJobEntityBatch and then adding the scheduling code inside the event rather than a ForEach lambda.
float2 trans = hasPos ? pos[i] : float2.zero;
float2 scale = hasScalar ? scalar[i] : new(1);
float2 sinCos = hasAngle ? angle[i].ToSinCos() : new(0, 1);
// float2 trans = math.select(float2.zero, pos[i], hasPos);
// float2 scale = math.select(float2.zero, scalar[i], hasScalar);
// float2 sinCos = math.select(new(0, 1), angle[i].ToSinCos(), hasAngle);
``` It seems like the tertiary if (not commented) generates a branch for each if statement (since they're constant for the duration of the for loop) whereas math.select requires a check every loop iteration despite the bools being constant.
@gentle harness ill say sort of no because assuming you are using the builtin bootstrap, you want to perform anything involving iterating over entities inside of OnUpdate
hrm, for best efficiency, i might need to gently nudge the compiler to generate a jump table...
@viral sonnet supposedly burst knows how to handle math.select specifically
Yea. But I dont know if it's exactly better in this case.
Actually, that code doesnt even matter. I no longer have optional transform components so all three bools will always be true.
Custom local to world matrix is nearly 1/3 the size of a full one.
Wait. Holy shit: It's fixed. I didnt realize it until now but I think 2021.3.6 fixed the DOTS inspector blue highlighting of selected entities.
I was wondering, why is this inspector workflow so usable and then I realized, the selected entity was actually highlighted.
Huh. Why is mine fixed then?
no idea
In that case. I am never updating my unity editor until 1.0 releases. This makes the 3 new windows actually pretty good.
the selection highlight issue is a com.unity.entities package side issue - the fix was package side. So maybe you need to update your package version? Can confirm, as the dev that fixed it, it was indeed bugged and subsequently fixed. @rustic rain
Nice. Thank you so much. It was so annoying.
Yea, it was updated yesterday. I have no recollection of actually pressing the update button last night.
Check the changelog that comes with package
Oh my god, they also fixed the very annoying source gen hard error. I even put together a script to delete the temp folder and then recompile all scripts.
time to finally move to 2021?!?
Wait what?
com.unity.jobs to version 0.70.0
The ILPP error?
Nah, the source gen error where randomly it would stop code gen'ing entirely if it could not delete and recreate the temp folder (where the generated code output would go for viewing, not actually used in the code).
Aaaaah, yes
You either had to completely restart the editor to clear the folder or make a script to do it.
Also seems like the jobs package just got rolled into collections
com.unity.jobs is a deprecated package. This code for this package has been combined into com.unity.collections-1.4.0, please prefer that package instead.
Thats the 0.70 jobs change.
The com.unity.jobs package has been merged into com.unity.collections to resolve circular dependency issues that can occur when using Unity 2022.2+.
Seems like they're prepping for release soon^tm.
Very exciting
Don't forget to setup build assets ๐
Smth that will never be fixed
It's not fixed? I fixed it locally was easy.
hehe ๐ yeah, i'll move to 2021 when the il2cpp generic bug is fixed
You can compile with il2cpp, if you turn on the smaller builds setting
Could you make a screenshot of build assets with il2cpp settings?
How?
solving random memory access is such a pain. everything that involves source->target is ... ugh. what's the secret behind it to untangle this. a few ptr accesses are like 90% of my performance when calculating a spell.
You gotta rethink the entirely of your data structure. Overhaul it from the ground up.
@rustic rain
Ha. I just clicked randomly until I saw what I wanted.
the relation problem doesn't go away though. even when denormalizing, you exchange read+write for just a read
It's a nice little window and I wanted to reuse it so had to fix!
For example, i had a bunch of light entities that formed a halo around a light source for soft lighting emulation. When I tried to figure out a way to properly transfer the "parent" light's position to the "child" halo lights, i ran into a problem of random access. So instead I completely restructured my light GPU data generation to instead re-compute a halo light position from the original parent light. No child light entities needed.
I meant build assets
my current problem is calculating a spell and about stats from source/target. i could make a data structure that is linear to the problem but maintaining this is not feasible and it gets absurd when AoE spells with several targets are involved. i would have a great data structure that is linear to my problem with lots of other read+writes to maintain it, which would make it overall slower because i can't really cache it. i'm not seeing the solution here.
Can you boil down your spells to a set of universal components? Like how transforms are ultimately a position, rotation, and scale?
Then have the spells only apply modifiers onto those universal components. From there, it's the same as a physics sytem.
Where spells are "forces" and whatever they modify being the "transform"
Can't you just calculate all data per entity and then grab finished result in random access?
one method is rolling a spell result. it's simple and fast, what's not is getting the stats var targetDodgeChance2 = targetStats[(int)StatType.Dodge]; var targetParryChance2 = targetStats[(int)StatType.Parry]; var targetBlockChance2 = targetStats[(int)StatType.Block]; var sourceCrit2 = spellStats[(int)StatType.CriticalStrike]; var hitChance2 = spellStats[(int)StatType.HitChance]; i have even aligned them in memory to get advantage of a cache line but it's still 2 random access. :/
i mean, all things considered. it takes 3.5ms for 250k spells to calculate
i just think, if i could solve this i could apply the solution to more places
This would only happen once in spell creation right?
yes
Which at 250k would mean you're creating 15 million spells a second at 60fps
That seems like enough for most use cases =D
oh no, it's really just the 250k spells per frame
what i meant previously was caching a data structure that is linear for spell calculation on target switches but it's not a solution for AoE spells sadly ๐ฆ only for single target
now i get what you mean... lol, yeah it would really be 15 million spells haha
not concerned about performance that much, i mean, yeah a side effect. more about getting rid of random memory access and i feel like source/target is such a common pattern in game design
My problem is less about random access performance
More about managing references
When target or source destroyed etc
yep, also painful. it's pretty much either check for existence or manage a reference buffer. both are not great solutions imo. a simple HasComponent check is faster, although when there are more references it doesn't scale well
What happens if I create a ecb from BeginSimulationEntityCommandBufferSystem from a system running at LateSimulationSystemGroup?
Does the buffer play back next frame or is it lost?
Next frame
Sweet, thanks
oh they've fixed this anyway
Huh, they did
[ReadOnly] public EntityTypeHandle entityTypeHandle;
public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
{
var entities = batchInChunk.GetNativeArray(entityTypeHandle);
var i = 0;
while (i++ < batchInChunk.Count)
{
var entity = entities[i]; // this is where IndexOutOfRangeException is thrown
}
}
Can anyone enlighten me as to why, or what situation, the IJobEntityBatch would throw index range exception on an array retrieved via EntityTypeHandle?
this is not ๐ฆ
Yeah I realized this after change to for loop. I thought that i++ returns current value, then increments?
it does
var entity = entities[i];
but it's incremented here
the check is fine
but on the next line it's now incremented which is where you are using it
0 < count
entities[1]
1 < count
entities[2]
I have never seen someone use a while loop to iterate through an array. Either For, ForEach, or a linq extension but not a While loop...
I bet!
next up, using goto
Does anyone know of a way to get a singleton during conversion from a separate conversion system?
nvm, figured it out
how would i do this best? i want to debug step a certain assembly line. i just have no idea how to either setup rider to debug an assembly or in VS to find the actual assembly line i'm looking for. scrolled through endless code but never found the right method.
i'm kind of confused what you're trying to look at
are you trying to profile a specific line of assembly? or figure out what generated a specific line of assembly?
or actually hook up a debugger and step through assembly?
rider to the rescue, missed the native debugger and i'm looking at the right memory address now. for some reason VS was being VS and couldn't find it... i'm actually just trying to figure out which values are accessed because i'm too dumb to just figure that out from the assembly alone ๐
What a peculiar debacle. I have a IJobFor that does var unitEntity = command.Instantiate(unitInfo.prefab); that runs on single schedule. It works, entity spawns properly. BUT! There's always a butt. In the job itself, after command.Instantiate(prefab) I set some components and conditionally AddComponent. The entity is instantiated as a Prefab (with the prefab) tag instead of an instance. This only happens to entities that have that condition met. And when I comment out that condition all together, it instantitates as an instance normally! WTF? Any thoughts?
If you need to see code, I'll post it.
the add is also with the ecb, yes?
Yup.
no idea really, that should work fine. post a code snippet of this
https://pastebin.com/EqMe40KZ Issue happens because of line 55
Pastebin
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.
Any thoughts/ideas?
That was my thought exactly. Think I found a bug?
Maybe it doesn't instantiate at all, I can't see it in DOTS Hierarchy, but unit actually does appear in game and scene view lol. So I have to assume it's the prefab because its the only one in the hierarchy.
ah doesn't that just mean it's the existing prefab?
that you instantiated from
Yeah, but how else can I explain the phenomenon?
When it "instantiates" it get's placed on float3.zero position instead of non-zero where it should be (the actual instance I mean)
best explanation is probably something else destroyed it ^_^'
unitInfo.prefab
needs to exist in your hierarchy
hmm...I'll look into that. If any other ideas pop up, shoot them over.
you're saying you only have 1 prefab in your hierarchy
It does
I have 1 prefab of that unit yes, but I have other prefabs for all other units.
this does not occur on start, this occurs because of user input way later then the start, so unit.prefab has to exist by then 100%, but I will run the check just to be sure.
any idea what rax is? the struct? it's aligned so well so it's unlikely they are my parameters
but it's also unlikely that the struct is moved to a bunch of registers. ๐ค
{
public SpellOwner spellOwner;
public float* snapshotSpellStats;
public float* spellStatsPtr;
public TargetInfo targetInfo;
public byte sourceTeamId;
public AttackResult forceSpellResultHit;
public void* spellBlob;
public bool fromMainEffect;
}```
any idea what it could be in that context?
So before the job runs, there is a destroy all units job (because this is a load request and needs to destroy previous units then write new ones from save file. I thought you were on to something and completely skipped the destruction job and went straight to writing new units. And they all appear and it's the same thing, that second unit that appears (because 1st wasn't deleted), it shows up in game view but not in hierarchy. And at this point there is no other place in the project that deletes units.
gotta step away, just tag me when if you have something else to suggest. Otherwise no worries.
So far, 0 DOTS compiler crashes. Seems like they did fix it.
can i identify an entity in the foreach by it's value, for example id=1 or id=2 etc, instead of identifying it by it's archetype? im thinking of using empty tag components, but for a 100 ids that would be 100 tags right?
filter by shared component data?
If its just for the sake identification, you can add an identification IComponent that stores an ID. If you don't care about using different IDs during different system iterations, you can skip that and just use the entityInQueryIndex
identify an entity in the foreach by it's value
You mean indexOfFirstEntityInQuery? Entity is also just 2 ints together in a struct. If you need a guaranteed unique int thats might not be in sequence, you can just cast Entity to Long.
Or just just the first int if you just need a value that no other entity has this frame
i said that a bit wrong. lets say i have 100 enemies, they all share the same properties like Id, Name, Position, etc. when the game starts, i just want to initialize the Id property of an enemy by reading from a database using WHERE enemy.id = 96 or whatever to give it Id = 96
sorry i had to rephrase my question
Shared component with an int property.
Then filter by shared component.
Entities will then be grouped in chunks by the exact same int.
Just dont over use too many shared components. Ideally you want at most 3 or 4 per entity. Beyond that, combinatoric fragmentation will lead to very low cache utilization.
okay thanks i will look more into shared components. i heard they would create syncpoints cuz of structural changes. im not too sure if i have to be weary of that
okay i will probably use 1-2 per entity
Yea, and you cant access them from within a threaded job.
well i think i would like to use the job system
Accessing and reading from a shared component requires EntityManager. So ideally you can set an entity's shared component to some ID just to get chunks separated and then have the actual data you want to read from located in a chunk component.
You can access a chunk component (IComponentData, just one per chunk rather than per entity) in a bursted job. Must be IJobEntityBatch though.
Shared components are something I would only use if I had to, or if they perfectly matched the use case. Because of the aforementioned restrictions I try to avoid them.
They're for specific use cases but yea, I generally try not to use them
well im open to any options including a different design. i just have a bunch of database tables right now
Shared component data and deliberate chunk fragmentation is specifically designed for enabling burst vectorization.
i heard the mesh renderer i think is a shared component
can i use like a non-bursted system for the shared component, and then use burst job for all the other data except the id?
If you know for certain that the operations you will be conducting on sets of entities can be vectorized so long as they were ordered in a specific way and willing to take the hit of now needing to jump across chunk boundaries, yea shared component data is pretty good
That's a bandaid solution. It's getting nuked in 1.0
One "advantage" is that shared components can contain managed classes.
oh okay xd
As there is currently no other way to link a managed class to an entity, they use a mesh renderer (which is managed) as a shared component
in 2022, the new hybrid renderer API provides a way to "register" meshes with the rendering system. Returning an int / unmanaged struct.
No longer requiring a shared component to fragment entitys by mesh / material.
Oh I didnt hear about that, that will be great.
Shared components are not intended to contain any read/write data. Just an indexer to deliberately fragment chunks if your burst vectorization or mem-copy would work with it. Otherwise, it's pretty much a noob trap. Seems easy to use but it's very easy to shoot yourself in the foot.
That being said, having 100 entities having the same exact properties and you want to minimize component usage per entity by instead designating a chunk wide component data that is identical across all entities in the chunk, yea thats one of the use cases.
Just be careful about chunk utilization and if you ever need cross chunk / universal data access as low cache utilization will harm performance.
Check out the current 2022.2 beta. It's already in the engine and you can play around with it. Fairly low level rendering API though.
I will have to take a look
yeah, the exact same properties but with completely different values. both the id and names are unique and would work for indexing. i honestly have to look into it a bit more, like how chunk utilization works and such
๐ Download the project files from this video: https://tmg.dev/SharedComponents ๐
๐จโ๐ป Code used in this video: https://tmg.dev/SharedComponents-Code ๐จโ๐ป
๐ Book: Data Oriented Design by Richard Fabian: https://tmg.dev/dod-book ๐
๐ฌ Join the conversation https://tmg.dev/Discord ๐ฌ
๐ป My Game Development Setup: https://tmg.dev/GameDevPC ๐ป
๐ See below f...
this is pretty much it right
Same properties but different values? Thats just an entity
You would use shared component data in situations where there are multiple players in an RTS game for example. Same unit archetypes but you dont want the chunks to be intermingling.
But you would not use shared components if you want to separate unit types
Separate unit types, like say a knight or a swordsman, should be identified by a component with an enum property if all other components are identical / shares same archetype for best burst performance.
If they're different, then you dont need a shared component anyways. The archetype will automatically separate the two units into separate chunks.
what i mean is that every enemy would have hp, atk, def, id, name, etc. they would not have the same hp values or name though
For example, knight and swordsman sharing same archetype. Only difference is a component governing it's speed. Knight has a speed of 5, the swordsman a speed of 1. You would not separate these using a shared component.
yes that example applies to my case
Because what if a specific knight entity was moving over mud terrain and the speed got reduced? With shared component fragmenting the chunks and using instead a chunk component to define chunk wide constant properties, you now need a component on every entity to define any modifiers to the chunk properties that apply only to that specific entity.
at that point, just define the entity component as the root speed property.
1.0 will be changing that
so a tag would be better? SwordsmanTag KnightTAg
yeah
hmmm
depends on your game structure
sometimes you want different components (thus name will be in a tag)
No. Fundamentally unit differences should emerge from variations in the components on an entity, not top down from a tag.
sometimes you want one component for all with different values
Components in ECS/DOTS replaces the inheritance structure of OOS. Archetypes are the "classes". Components are the "interfaces".
The entity itself is the "object". Would you make a class specifically for knights? Another class for swordsmen?
No. You would make a generic class for "units" and inside it will be the sprite, speed, damage, etc
That way, you can easily extend the units possible beyond knights and swordsman without needing to make a unique class for every single unit.
oh i think i would make a Knight : Unit and Swordsman : Unit
not possible
Yeaaa, but not in DOTS. This is my analogy to object oriented programming. But it's not like that in ECS land.
inheritance requires managed component, and with managed components you can't use burst
what isntead you might want
struct Unit : IComponentData{ public Type typeName = Knight;}
smth like that
a problem that comes with that - you can't easily query through them
so if you want all Knight at once
you'll have to iterate entity one by one to make a check
Shared Components solve this problem, but bring another:
they are consider managed components, but you can still differentiate between entities with them using burst
shared components basically create a unique component by it's value
so 2 entities with all same comps, but different values in same shared comp will lie in 2 different chunks
and Unity has a way to filter Query by value of shared component (so this way you'll have able to query all knights at once)
but once again they are considered managed, so you can't read value in jobs or burst
but! you can read their index
since all shared components are stored in a literal List
im having some trouble moving along
Yea. It's a completely orthogonal way of thinking from usual programming
I suggest to go through this
while true, this should not be on the case on the server
also potentially not a case for 1.0
allthough I don't see how not using such separation is not useful for graphics
ah, yes I'm finally updated xD
You dont need separation. It's basically like if mesh renderer could be stored in a blob asset.
separation is for drawing iteration
so you can easily group same entities
in graphics regard
Does the renderer really need to dictate the structure of the entire DOTS entity store if it could just sort and group the rendering data with a hashmap?
๐ค
hashmaps aren't great for iteration
You have the number of possible entries up front. You have a unique index corresponding to a shared rendering, you can just sort them by that index and boom, you have the indirect draw command buffer.
but you'll have to regenerate whole map
every time entities change
personall
I simply use separate entities for this
one for drawing
one for AI
and etc
well so if i simply just want to transfer all my rows in my CharacterClasses table to dots, and have like Class1 { id = 1; name = "swordman"; } Class2 { id = 2; name = "knight"} etc, and i want to instantiate both these entities at the start of the game, what method would i use?
you use conversion workflow
1 pass to count how many entries per material. 2nd pass to populate a draw command buffer with the relevant per instance data (local to world and so on). 3rd pass to execute a indirect draw call.
yeah, and that is somewhat expensive
structural changes will be a bottleneck
is this aimed at me?
yes
One does not simply transfer all the CharacterClasses. Though it seems reasonable you would make your prefabs available for when you do need to spawn a CharacterClass.
almost 4 years of DOTS and I still barely understand the conversion workflow. It looks straight forward but damn it's a very deep pool.
the concepts are key
and they are pretty simple
well i meant just the classes the units are gonna use, not all 100 possible ones
^ Good question
would prefer pure dots
then go and read that manual from 0 to 1 xD
pure DOTS is ECS
with a lot of unique to Unity stuff
and it has nothing to do with classic Unity
literally nothing
meanwhile ECS suffers a lot of from all good OOP practices
You must forget your earthly OOP ways
Unity seems to be constructing a pathway down to the land of ECS from OOP but the best way is just to jump off and land hard. Unfortunately there really isnt that many good guides on landing without breaking your legs on many failed projects until it finally clicks.
The manual is pretty much only useful as a reference, not a learning tool. Before I dived into the source code for the transform system group, that section made 0 sense. A few hours/days later, it's very straight forward.
it's useful for concepts of ECS
you can't expect a newbie to jump in learn correctly without not knowing any of that
If I was being paid to tutor someone to learn to code DOTS. I would tell them to completely forget the existance of classes and inheritance and start them on the Hello Cube samples. The goal will be moving 1000 cubes at once using WASD.
and then make this task harder by saying: only cubes of selected color should move
That's the next semester's course.
I say it's realistic to expect that it'll take a month or two just to teach people how to properly (read best performance) move a cube.
no way
Even longer if they come from programming backgrounds. Maybe a week or two for someone who knows just HTML.
a week max
maybe i could have a system that sets the id, then have another system that reads that id and does something based on it?
Most of it would be erasing OOP.
The system that sets the ID should be the conversion system. The other system will be everything runtime.
okay i didn't read that page issue linked but i will. it's generally used to convert from managed unity code to unmanaged dots code right?
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/HelloCube
I highly recommend going line by line with these samples.
Not just reading, but following along. Dont copy paste, type it out by hand.
Then see what happens if you change numbers, if you author more entities, and so on.
it is used to convert from good looking data for people to good looking data for machines
maybe im thinking of something else
The questions you are asking are basic fundamental ECS design. It's not unique to Unity. There's bevy for Rust and so on. But you need to know what ECS is before trying to use Unity's version of it.
we can answer your questions, it's very simple, but that wont help if you move on to the next mechanic in your project/game and dont know how to properly structure your data
i think i got misled by a video saying pure ECS vs hybrid (conversion)
cuz you said conversion happens anyway right
Yea, the current videos out there are at best very niche, at worst completely misleading. Or wrong.
The argument of "pure" or "hybrid" DOTS is filled with so much misinfomation. Yes, conversion happens even in pure dots.
okay well thanks for the ecssamples and the conversion link, im reading through it rn and things make a bit more sense ^^
Just dont watch any videos out there on DOTS. Look at the samples published by unity. That's the proper way to use their own API.
It's all open source which is nice.
videos are hit or miss hehe
some teach a really bad practices
like old CodeMonkey videos
Videos for programming in general are just bad. Programming is a text based activity. Why are there videos on it.
they didn't know back then all goods of ECS
it's like lecture online
Codemonkey is a PR man. I'm subbed for his thoughts on programming in general but not his actual code.
I figured it out...
something silly?
Very, but it was a doozie tracking down. The code I wrote for the job and all is fine, this was being caused by another job that runs when this one adds that component based on condition. There was an error, I was setting a Parent, and where I was supposed to input the item, I was inputting the character instead, which told ECS to parent the character to one of it's own children lol. This causes the character to disappear from hierarchy but remain in scene.
For for future reference, in case anyone else runs into this weird behavior.
parent the character
Burn it at the stake
๐
Even with 0.51 there isn't a built-in way to destroy entity with all children? Or did I miss something?
yeah im looking at this and reading the docs a bit
https://github.com/Unity-Technologies/DOTSSample/blob/master/Assets/Unity.Sample.BaseCharacter.Authoring/Scripts/Abilities/AbilityMeleeAuthoring.cs
i think line 11 of that pretty much does what im trying to do.. also i see they use enums, like you mentioned earlier ```csharp
public enum AbilityTagValue
{
Melee = 1,
Movement = 2,
...
this makes more sense (:
Yep, and my sprites, which is just a colored circle or square, are also enums:
public class SpriteAuthoring : MonoBehaviour
{
public SpriteType type;
public Color color = Color.white;
public enum SpriteType : byte
{
Circle,
Square
}
}``` Notice the MonoBehavior. This is a *converted* gameobject component that will be turned into a IComponentData.
LinkedEntityGroup is meant to handle that for you
LEG is giant though. It's what, 150 bytes because they made the internal buffer capacity 32 or something.
yeah its super annoying
they need to remove it from chunk
should not be in there by default
Oh yeah, how can I use that?
I dont even know why it's that big. It's ideal to be something located outside the chunk.
the second you have a LEG in an entity, the chunk capacity falls to the low 30s, even high 20s, adding on the 4x4 LTW and all the default 3D transforms.
Add on the components required for your own project and you have single digit numbers of entities per chunk.
At that point, you have a glorified game object.
I think Unity made the LEG exist inside the cache just to punish people who use parenting and hierarchy.
Does LEG show ALL children flattened into buffer so I don't need to tap into children?
Nope. It only contains the direct children.
Then you're right, it does feel redundant considering you can just use the Child buffer...
I had to check because that would invalidate the entire use of a LEG:
Referenced Prefabs automatically add a LinkedEntityGroup with the complete child hierarchy. EntityManager.Instantiate uses LinkedEntityGroup to instantiate the whole set of entities automatically. EntityManager.SetEnabled uses LinkedEntityGroup to enable the whole set of entities.
It's flattened.
Oh nice! Thanks for double checking.
Ok, I got another riddle for y`all. In what scenario would your entities be Instantiated, and when you move them (in-player) they actually move according to inspector data, but visually they are where they were instantiated. And when you click to select (via raycast collider) you have to click on their actual position and not where they are visually (stuck), like their collider updates but their mesh doesn't. WTF?
Seems like the local to world isnt being updated for the mesh?
My man, you're totally right. I just verified, the WorldRenderBounds is not updating! How can I fix this issue? I just command.Instantiate(prefabEntity) this thing...what do I need to look for?
The RenderBoundsUpdateSystem performs a query on
ChunkWorldRenderBounds
WorldRenderBounds
RenderBounds
LocalToWorld
I verified that when the entities are instantiated that they have all four components!
No clue. I roll my own rendering system (which is pain, dont recommend)
@rustic rain Here's my "sprite" renderer. Where the sprites are only circles and squares.
Main issue is that the circles draw on top of everything else because in order to render without Z fighting, it needs a non-0 Z value, which then breaks my poor lighting.
Turns out there was a LocalToParent assigned to entity without Parent.
is NativeParallelHashMap<DefData, Entity> fixed size?
Or basically: can I use it in blobs?
https://github.com/bartofzo/BlobHashMaps
someone wrote blob hash maps ages ago
but then unity broke it in 0.17 with too aggressive static analysis
i havent tested doing it in 0.51+ but i suspect it's still broken
unless you want to turn off a check in the entities package
guys says it is still broken
https://forum.unity.com/threads/hashmap-in-a-blob-asset.779000/#post-8267070
why EntityQuery doesn't work?
Is EntityManager reference valid after a while?
for example if I assign it to some class objects during OnCreate
and then use it a while after?
<@&502884371011731486>
i suspect you're doing something silly
hmmm
How to deal with Destroyed entities and their references?
for example I have Entity X that follows Entity Y
Entity Y gets destroyed. Entity X throws exception in it's pathfinding system, because Entity Y does not exist
welcome to my biggest annoyance and unsolved problem with entities
the only way I've found apart from just having Exists/Has checks everywhere
is just to have a really solid cleanup pipeline
i only have 1 DestroyEntity in my entire project
so, how does it even work?
you attach destroy tag
you know this entity is about to be smacked
what happens next?
thats a way to do it, but i have static archetypes
so everything has a EntityDestroy component on them
/// Unified destroy component allowing entities to all pass through a singular cleanup group.
/// </summary>
public struct EntityDestroy : IComponentData
{
public static readonly EntityDestroy Destroy = new() { Value = 1 };
public static readonly EntityDestroy CancelDestroy = new() { Value = -1 };
internal sbyte Value;
public bool IsDestroyed => this.Value != 0;
}```
huh, so you have existance state component
I have a CleanupSystemGroup that updates After EndSimulationEntityCommandBufferSystem with its own command buffer
that just listens to destroy changes
and destroys entities
however, libraries can add systems to this cleanup group as well and also react to certain entities being destroyed
and as the component shows above, they can also cancel entity being destroyed
this is really useful when you have a library that needs specific cleanup
for example, i have a fracture system. when something gets destroyed for whatever reason it shouldnt be destroyed
it should fracture into pieces
so it cancels destroy then sets its fracturing to all
anyway this is a recent (1 month) unification of how i want to handle this
yeah, that totally makes sense
as i'm trying to write my code in a way i dont have to check states (except maybe 1 place)
as in Destroyable
i'm not sure this style would be good in a game you want for modding though
a more defensive structure is probably worthwhile
(the cleanup pipeline can still exist)
(i just mean, never check for safety - this requires static archetypes and for everything to stick to very specific rules)
yeah, I just got the idea, now gotta think it through
I don't see how static archetypes is a requirment tbh
as nothing stops me from simply having component
that indicates the state
because if my archetypes aren't static i can't be certain something hasnt removed a component
i can't get
GetComponent<Translation>(target.Entity)
if someone has removed Translation
ah, in this regard
don't think it's a problem tbh
I want to try and make per object entities separately
so
rendering has 1 entity
"brain" has another entity
ship stats and etc has another entity
I haven't implemented it yet in any way
or just destroys the entity with EntityManager.Destroy()
well, then he made a broken mod
yet it might not be broken
until another moder has a mod
that expects the entity to exist
and it does with your base game
both work fine
you combine them
and bam game just random crashes all the time
yeah, I get that part
we used to have A LOT of crashes due to things destroying
but if I want to implement destruction pipeline
Modders will have to use it
that's how life is for a modder
the bare minimum you need to do if you use ECB is have your destroys in a command buffer system after your regular command buffer system
in RW, you mimic game logic
yeah that's fine if you set it up properly
you aren't really playing the game as normal game dev
you can define rules
but yeah that above concept is what i'm trying atm
it's been working well
any library can destroy an entity without worry
and then the owning library can let it through or cleanup, or stop it or whatever is required
oh yeah if you dont care about static archetypes you can just use a tag component
but it's a little harder to 'stop' an entity being destroyed
what do you mean by that
so entity is destroyed and other entity wants to use it to get it's LTW component
once it's destroyed, nothing changed for other entity
and it tries to access dead entity
oh yeah
i have 2 way references on my entities
so when 1 is destroyed
it tells the other entity's that are referencing it that they are dirty and needs to recheck its references
I don't think I like that one very much
but I'll have to think all options
through
why not just have state
component with value/enum
whatever
which will be readonly
for most jobs
and only those that actually destroy entity
will change value
so you do end up with checks for dead state
but you'll read component this way
oh the other thing you can do is if you know you only have 1 place in project that destroys stuff
simply have a system update after it (or start of next frame)
and simply check every reference is valid
and just assume everywhere else in your project it is safe
oof
it's actually reasonably fast to do with EntityStorageInfo
simply checking every reference not that simple ๐
I have a lot of components that have Entity field
but don't need to store entity
all my AI uses a single target buffer
for this reason
it just re-uses the same buffer for targetting whether its another actor, a resource, a collectable etc
they basically have "knowledge"
public struct QueuedAction : IBufferElementData
{
public int integer;
public float @float;
public float2 float2;
public Entity entity;
public ComponentType actionType;
}
My AI looks like this xD
I'll have to give a lot of thought
obviously easiest way (what we do at work) is just literally check every call
its gross, it works
i really do want to find a generic universal kind of pattern i can apply
hmm
what if
we get all component types with entity reference
and upon trigerring destruction
run a job
that makes a check
and swappes Entity with null
meanwhile inside of jobs
you rely on Entity.Null
comparison
if you're doing entity null checks
why not just do hascomponent check
in the first place?
how?
ComponentDataFromEntity.HasComponent
oh
{
if (!Exists(entity))
return false;```
first thing it does is simply check if entity exists
i want to solve it without have any other job in project need to check
even though least fast
if you dont use hascomponent/getcomponent with codegen
pass in ComponentFromEntity
and just use TryGetComponent instead
to combine both the calls
it's not that bad
actually i realize this is basically what i want to do
and i just dismissed it ^_^'
if (action.entity == Entity.Null && action.float2.Equals(float2.zero))
That's like the first thing I do in a job
yeah because null is probably a legit state for setting something up
but it's still the problem of setting it to null
idk how fast it would be running through literally all entities
and checking whether their references exist
๐
it depends on your scale
and number of components
but yeah you wont be getting into 6 figures without doing this with both way references and relying on change filters
unless its only like a component or two
I will probably have way too many components with Entity reference
and getting each will be a problem already
yeah its pretty normal
Feels like having checks would be the only option, unless smth way smarter is figured
hmm
I just thought of very dirty and at the same time clean way
every time you want to assign reference to entity to other entity
you have to create a chain entity
that has reference to both
entity1 and entity2
and then job simply iterates through all them with checks
i've thought of doing that
alltohugh, that sounds expensive
but adding that entity to the linkedentitygroup
so when the linkedentitygroup gets destroyed it destroys that entity
it requires some fun magic with caching archetype chunks to do checking on it
nah, I think the easier would be simply using it as trigger for when entity reference is broken
something i was having to to handle the 100mill entities i was testing with this for stats
like i should say, i wrote a solution for this
that handled 100mill effects referencing 10mill actors
nvm, I don't like that solution at all
but i had some crazy optimizations like chunk components with a list of all archetype chunks that these entities reference
but it was fast enough to handle this problem in 2ms
for 100mill entities
but yeah its not something i would actually recommend - was just a theoretical challenge for myself
ok, my best bet is callback buffer
everytime you want to write Entity reference
you access occupation buffer on it
and add entity that saves reference and component type
upon destruction system gets reference, gets component type and modifies it
but I'll probably just stick to checking
data
I don't want to create super complex and easy to break systems
yeah if you're referencing another entity you are doing random access anyway
the check is the least of your worry anyway
private bool ShouldSkip(in QueuedAction action, out float2 targetPoint,
in ComponentDataFromEntity<LocalToWorld> ltws)
{
var entityNull = !ltws.TryGetComponent(action.entity, out var gtp);
var tarZero = action.float2.Equals(float2.zero);
targetPoint = math.select(gtp.Position.xy, action.float2, entityNull);
return entityNull && tarZero;
}
I wonder if that can be vectorized, kek
hm
what's new in the new DOTS 0.51.1 ?
Fixed annoying code gen fails
i would have said it doesn't but there are a bunch of ps in the assembly
a bunch of what ?
oh
i'm just pretty sure it's not the TryGetComp because that has conditions in it
ah the call to it is later
hmmm
Idk where to start when implementing "entity separation" by logic
or should I even do that
one obivous way - use child Transform hierarchy
How would one iterate over all entities with a certain component while already in an Entities.ForEach? Currently I'm using two and even while using .WithoutBurst it still doesn't allow such. Will I need to use a pregenerated list/array/such perhaps?
yes, you need to get data about those entities beferehand
Alrighty, that's fair :P
Hey, I'm still new to ECS. I have problem with changing scenes and having entities remain. I have read this thread https://forum.unity.com/threads/ecs-tear-down-and-restart.539722/ and have this in one of my managers:
private void OnDestroy()
{
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.DestroyEntity(entityManager.UniversalQuery);
}
I have MainMenu scene which serves as level selection. When I enter level, everything works okay, on exit entities are destroyed, but the PhysicsSystemRuntimeData is destroyed as well and upon selecting another level it is still gone. I don't know how to properly reinitialize that. What am I missing here?
why not just destroy world
and create new one?
if you have scene management that relies on Unity scenes
won't destroying world also get rid of everything?
it will
but if I create new world, I would need to add manually things like PhysicsSystemRuntimeData , or I am wrong?
what is that?
nvm, it seems to work better, but now i have world is null error from WorldProxyManager when i change scene (and dispose all worlds and create new one)
it keeps on giving errors even when i'm not in play mode
did you disable automatic world creation?
no, i didn't. But the error just stopped now and it seems to work fine, not sure yet what happened
Why would this not work pray tell?
// collect locations first
DynamicBuffer<Entity> locs = new DynamicBuffer<Entity>();
Entities.ForEach((Entity entity, in WorldLocation wl) => {
locs.Add(entity);
}).Schedule();
// acquisition method things
ComponentDataFromEntity<Translation> entgettrans = new ComponentDataFromEntity<Translation>();
ComponentDataFromEntity<WorldLocation> entgetwl = new ComponentDataFromEntity<WorldLocation>();
// update agents
Entities.ForEach((ref PathFollower pf, ref Translation tr) => {
// get direction and vector from it
float r = math.atan2(pf.Destination.z - tr.Value.z, pf.Destination.x - tr.Value.x);
float x = math.cos(r) * 5;
float z = math.sin(r) * 5;
// move
tr.Value += new float3(x, 0, z) * deltaTime;
// check if at destination
if (tr.Value.x < pf.Destination.x + 1 && tr.Value.x > pf.Destination.x - 1 &&
tr.Value.y < pf.Destination.y + 1 && tr.Value.y > pf.Destination.y - 1)
{
// acquire new destination
pf.Destination = entgettrans[locs[random.NextInt(0, locs.Length - 1)]].Value;
}
}).WithoutBurst().Run();
Sorry for asking question is such succession orz
It gives me an error Object reference not set to an instance of an object Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow but I have no idea what it means...
All the values should have values. Removing the
pf.Destination = entgettrans[locs[random.NextInt(0, locs.Length - 1)]].Value;
and
locs.Add(entity);
fixes it but I'm not 100% sure why.
I've tried setting up the first Entities.ForEach with .WithoutBurst().Run() but that does nothing.
Putting the locs DynamicBuffer in the system and doing an IsCreated check in update doesn't seem to change the IsCreated bool (if that's even what IsCreated is for...).
new ComponentDataFromEntity<Translation>(); this doesn't work. use GetComponentDataFromEntity<T>
same goes for the buffer. you can't just new them
equivalent is GetBufferFromEntity
hmmm, what would be a best way to store arrays of vertices/uvs/triangles?
the trouble I experience - size is not defined
the biggest problem is that this data is meant to be per entity
Use a blob
It's better if you don't have to store them, especially if you are doing procedural meshes
yeah
I am figuring out what to do
I potentially should just use index
I am doing 2D renderer
hmmm
I realised
I can store it by Shared comp
and use index for per entity data
will the data change? i suppose not.
currently, as HR is working the same you could store it in a shared comp. it's just not future proof
yeah, I can
and I'm figuring out how
the problem is that, uuugh
I don't know full data of atlas
upon conversion
and if conversion will be split
sharedcomp + unsafelist. although you could just make a blob then
I might end up with several duplicate shared comps
then a blob is the best course. that deals with same-ish entries
here's what I think:
public struct RenderSprite : ISharedComponentData, IEquatable<RenderSprite>
{
public Material material;
public Texture2D texture;
public bool atlas;
}
so if it's atlas I will need vertices, triangles, uvs arrays
list of those arrays
how would that work?
I don't really see it
so, for example I converted 10 entities that occupied 50% of atlas
and now after a while second subscene is loaded
and sprites from it use other 50% of atlas
how conversion system will figure
that it needs to combine blob/shared comp
hmm
Can I keep native arrays in shared component?
I think I can
what kind of Allocator do I need to use then
when creating it
persistent
doubtful
oof
ok, I guess I can use blob arrays
The main issue I found with a fully featured sprite renderer is packing the sprites into 1 texture. The conversion system with incremental conversion will only iterate upon entities with something changed. However all sprites will need to be packed into a single texture so either turning off incremental conversion so all sprites are re-packed if a single sprite was changed or roll your own texture packer.
yeah
you don't need texture packer though
you pack them in atlas in editor
so you already get atlas as texture
and uvs, vertices and etc
So instead of doing all of that pain, I am only rendering circles and squares, I just made my own rendering system that dynamically computes the circle or square inside the shader and let the scale in the LocalToWorld dictate the width and height.
well, I obivously could also draw simple quads
BUT
I really want tight packed meshes
this way
I can draw any mesh
graved out of texture
fully dynamic and bursted
My very simple quad sprites are very fast. Just mem copies into the buffer.
it's also low level and not as feature present
But I have to admit, the options are... limited.
I want to have full power of sprite renderer
I thought about it, even including animation, but I have made 0 progress in my physics engine and I need something now.
And Unity will probably include their own fully featured DOTS sprite renderer sooner or later. Sprites are important in 3D as well.
As opposed to other 2D ecosystem structures like tilemaps and a conversion of Box2D.
The issue is that my custom renderer doesnt function in editor (before pressing play).
hmm uh (0,0): Burst error BC1025: Accessing the type Junk.Transforms.BillboardSystem/CameraPositionJob (e.g. using typeof) is not supported what is this all about?
Nah, I moved my renderer to a render pass due to issues conflicting with my lighting renderer:
yeah...