#archived-dots
1 messages · Page 278 of 1
while it happens only once at start, meh, i'm ready to this tradeoff
in perfect project - yes, conversion happens only in editor
I've tried
subscenes are meh
there was some issues i've found on forum which have no simple soultion. Some stuff just doesn't work correctly, i don't remember what in particular, because it was pretty long time ago. But i have hope that 0.50+ will solve my problems. Also i can't 100% avoid conversion, because i use some hybrid things + addressables to be able to load presentation layer, but i saw some kind of streaming entity prefabs, so that also can solve this part
welp, idk what exactly you don't like
but so far entities work perfectly for me
with all hybrid
I mean subscenes
didn't say i don't like something 🙂
subscenes lead to sorta fucky things with custom rendering pipelines
beyond the usual fucky things with SRP
welp, can't argue with that
never tried custom rp
but with URP it's all good for me
the idea of having serialised entity data is obviously a need. But all this live link stuff, i guess, ruins ux
I'd say, they are quite simple to use for the most basic stuff
They are hard to figure out once you need more complex stuff
and they are just godsend once you realise how they work, as they offer so much custom options
I personally use a lot of subscenes for different states of game/layers of objects
1 for player related entities
2 for background (which is reused in main menu)
3 for custom objects for new game
well it works in URP 2D renderer
Now i gotta figure out how to set the render target to not be the camera
@robust scaffold dont u have to render to cameras everytime? but u can set the cameraoutput to texture instead of screen
oh my god, trueeeeee
wait, but this brg doesnt target a camera?
no idea how that works sry
Is it ok that inherited system class doesn't automatically created?
a system that has generic arguments is not added automatically. but i think if you had a system that has no generic arguments but inherits from one that does it is still automatically added to defaultgameinjectionworld
just now i debugged an error produced by this
i have no generic arguments, just inheritance
DOTS doesnt really do inheritance
it does for systems
sry then im not sure how it should behave. its not too hard to add it to the playerloop manually though
yep, but this is conversion system
but not for ISystem i should add :S So bursted systems wont support it
i don't know how to add them manually
awkward
Not too difficult
been a long time since I added a system but it's very simple
i see how to create a world from scratch and i have my custom utility to do this, but how to initialize conversion world
i mean you get a reference to the conversionworld via entitymanager of conversionworld. cant you get the playerloop of the conversionworld then?
Can we step back
Why is your system not being added to conversion world when it's not generic?
Do you have an attribute on it?
Alright, BRG is outputting to a render texture through a camera which is iffy
well atleast consistent with the rest of urp
@rotund token the codegen to get my generic systems to burstcompile in 1.7.2 worked. i still hate it though
did u guys also see alot of editor speed improvements when updating to 2021?
like night and day for me. but alot of it could be the native support of apple silicon
so im wondering how it was for windows users
Is it intended that entities 0.51 tries to convert stuff like constants to authoring code?
That seems incorrect to me
It seems to be completely ignoring any modifiers, for example it will also attempt to set private variables
feels slightly slower for code recompile, some of the messages on that pop up loading bar seem more verbose
damnit conversion system is just such a pain
feel like i'm having to jump through hoop after hoop
can't do this, can't do that, oh this component doesn't exist yet, but this one does, etc etc etc
just convert it manually with an OnStart?
how would that work?
nevermind, probably wont help
dont you guarantee that a component exists already when you add it to the query?
also there is declaredependency()
I'm not using a query, it's just some setup inside Convert()
so for example i've used:
to grab the linked entity group from the converted object
but apparently, it doesn't exist yet
linked entity group only fully exists right at the end of conversion. you wont be able to rely on that at all while conversion is ongoing.
pretty special case too
also reading from the dstManager while conversion is still ongoing might be a bad pattern. you read from a half finished destinationworld.
as long as you dont guarantee yourself that a conversion has fully run by ordering systems etc. i would not read from dstWorld
yeah i thought maybe the rest of the conversion process would have been done, at least for that gameobject, when Convert is called.. rather than calling Convert at some arbitrary point in the process
just irritating
so i guess i'll have to do some more workaround
atm i had to resort to Systems running in the first frame instead of conversion to set some things up
i mean, grabbing linked entity group is already a workaround for another problem ( the fact that GetPrimaryEntity doesn't return the entity produced by joint components )
yeah i've done something similar previously
just annoying though.. i mean, make it easy for us Unity damnit, you're halfway there
what do you need to do with the joints?
maybe try using a conversionsystem and run it in GameObjectAfterConversionGroup?
still linked entites group is done after that.
what i'm trying to do, is basically set up my Prefab entity, and store it, so i can later instantiate when needed
prefab entity automatically created by unity?
yeah i'm using DeclareReferencedPrefabs to create and register them
which works fine
just trying to access the joint entities and do some component/buffer setup on my prefab during conversion is proving to be painful
for windows too. that's why I hated 2020.3 so much. 2021 is so much snappier in pretty much every regard
would it be so bad to create additional entities for each joint and do that setup on them?
finally a unity editor version bump that actually improved performance/iterationspeed. the last few updates i made it became more and more sluggish
yep, at least 2020.3 improved somewhat. it was total trash in the first versions
not scientific but what do you guys have for your hold on for recompile time? for minor code edits I think mine is between 20 & 30
for me i'll get application.reload etc getting progressively longer, until i restart and it becomes more responsive again, on 2020.3.3
i found 2021 to be quicker, but a friend was having constant 'redraw' or something, which i think was a known problem
i sometimes had compiletimes of 5 minutes in 2020.3...
still testing 2021 but it seems really fast
yeah even on a very basic project, it can get silly
I think after a minute or two I assume the editor hangs up and restart it
i did split everything up in assemblies etc...
this would trigger some kind of longer Project reload for me which would defeat the purpose of waiting just a little longer
opening project is 10x faster atleast too now
5 mins seems like a huge wait though, is your codebase enormous?
not really
im down to 21 sec for a small codechange in my biggest assembly now
counted until the editor is responsive again
nvm. 21 sec was the slowest time i counted after changes now. 4 sec was the fastest
not sure why there is this big disparity despite doing the same change?
given its a macbook air even more so. the native editor does alot
i always suspected it was related to caching and possibly undo
when unity has been open for a while, and you've been working on a project, you might notice it chews up a few gb's of storage
thought that was just shitty memory leaks 🙂
closing and restarting unity for me generally frees up that storage space again
hehe possibly
i'm not sure if unity is caching assemblies etc to make things 'quicker', but inadvertantly making it actually slower
anyone else seen this? :
Assets/Scripts/UtilityAI/Core/ActionEntity.cs(1,1): error SGICE003: Seeing this error indicates a bug in the dots compiler. We'd appreciate a bug report (About->Report a Bug...). Thnx! :heart: System.UnauthorizedAccessException: Access to the path .../Temp/GeneratedCode/UtilityAI' is denied.
happend more than 5 times now. requires an editor restart to fix
Id report a bug if i would know what might be triggering this. but 0 clue atm
gotten it too but editor restart fixes it so cant really repro
This is a common issue @solemn hollow in 0.51 and one of the reasons I warned people against upgrading
If you go look at that directory you'll see for some reason it's generated empty files instead of directories
If you just delete those files you can save yourself a restart
sounds like new editortooling in the making
Someone on the forums wrote a script to do it on the refresh keybind
Is possible to get singleton entity from MonoBehaviour? I looking for solution for camera update.
Or better is update camera by system?
for cameras, i just update movement with a monobehavior
bog standard movement script in mono Update(), dont try to make it hybrid
i on the other hand for cameras, have a dots wrapper for cinemachine and use no monobehaviours
Okey but how to find entity to follow?
I use for XR and I don't need cinemachine. In general I can use Input System but I need LocalToWorld (parent)
I can try spawn camera by system and connect correct EntityManager and Entity
But I looking for how to find Entity from MonoBehaviour (to know, it can be useful)
https://forum.unity.com/threads/cinemachine-conversion.1215168/
https://github.com/tertle/cinemachinedots
no idea of the state of this repo i haven't updated (and said I wouldn't)
but if its broken shouldnt be hard to fix, i still use it
Why? I think that I can update camera (as singleton) in presentation update
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Movement : MonoBehaviour
{
public float speed = 1;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
var horizontal = Input.GetAxisRaw("Horizontal");
var vertical = Input.GetAxisRaw("Vertical");
_rigidbody.velocity = new Vector2(horizontal, vertical) * speed;
}
}```
Plop this on a camera and never care about movement again
yuck 🙂
so so gross
why is discord not deleting this? 😉
me special
because it has no indents!
you just cant post code which is indented
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Movement : MonoBehaviour
{```
it would be deleted
I think it was a joke 🙂
ugh, i think batch renderer group is a dead end. There's no ability to designate the render texture target of a batch render outside camera texture. While you can set the render layer to be something other than default and then use another camera rendering to a RT, that additional camera costs CPU time and practically invalidates any improvement to using it as an alternative for post processing sequence of renders.
sry i know cause u explained before. it was more meant like it should be cause of the code itself ^^
me too xd
what is this a jokes channel now?! serious discussion only 😠
yes please
especially a post processing stack that generates a lot of intermediate lookup textures. And it's definitely not worth it since culling needs to be done manually
speaking of cinemachine, what ever happened to that whole dots cinemachine 100 camera demo they presented ages ago?
delayed to after 1.0 i bet
🤷♂️ i waited a while then went fuck it, wrap it myself
was only a few hours work anyway
and it's worked fantastic since
just dump camera, brain + cinemachine cameras in subscene, bam converted for you
or maybe they all just wait for tertle to finish the job? 🙂
I ported ufps ages ago as my weapon/camera solution and now Im too lazy/entrenched to learn something new on that front, but I probably really should use cinemachine. too many things
honestly if there is one package that feels complete from unity it is cinemachine
I remember as a junior in my first job, I found a bug in Cinemachine package. My leader told me to send pull request with the fix. But it was rejected because it was fixed but not released yet. xD
got to 17
Are you create VirtualCamera by code and to target Entity CopyTransformFromGameObjectwith created GO?
pretty much
during conversion all gameobjects get destroyed as usual but data stored on components
and I recreate and manage their lifecycles myself on loading
kind of like my own little companion objects
It means that the solution is configuration by ECS System?
yes everything is run by systems'
But Camera is a GO, y?
i never write code where monobehaviours can access entities
oh yeah you need to enable the camera conversion
which is off by default
CameraConversion? What?
HYBRID_ENTITIES_CAMERA_CONVERSION
Wow
so do you respawn the object with the camera after conversion or do you keep the camera gameobject around but copy the cinemachine components to entities?
if you add CMBrain to an entity with a camera, it'll add the CinemachineBrain to the existing gameobject
for virtual cameras it'll create its own GO and manage that, just create a CMVirtualCamera component and it'll set everything up
destroy the entity, it'll clean it all up for you
then just use the entity components how you want and it'll handle syncing states etc
very neat! atm my camera needs are met but ill keep this in mind
i wish i could write useful repos to share. im not at the point where i feel confident enough ^^
i have so many awesome libraries i'd like to share
but its like effort
the best i can do is just dump some code above and if people care enough they'll look into it and figure it out
big thx for that ❤️
is anyone already on burst 1.8?
im not because tertle earlier mentioned a burst cache bug which is only fixed for 1.7.2
damn, I had high hopes that the cache bug is gone. hm, I remember 1.7 having that too. good to know that it's at least fixed in 1.7.2
anyone has any idea why ecb.RemoveComponent<RandomColors>(entity); wouldnt remove a DynamicBuffer<RandomColors> ?
i do have addjobhandlefor producer etc
i wanted to only generate random colors at gamestart based on some seed. but somehow this system runs every frame cause the entities still have the RandomColors buffer.
hm, no idea. maybe another system adds the buffer again?
yeah what manarz said, cache bug fixed in 1.7.2 not fixed in 1.8 preview (came out before 1.7.2) should be next update
its only added in conversion
targeting wrong entity? 😬
no the entities are correctly shown in the inspector. somehow the system doesnt execute the job but is still updating. and the entities.foreach query is correct
shit it was just an early out i missed...
shouldnt code 18 hrs straight
There is a problem with LocalToWorld.Rotation if scale is not 1f. Thats why I have a problem if I using CopyTransformToGameObject. To fix it you need to use quaternion.LookRotationSafe(localToWorld.Forward, localToWorld.Up) for GO rotation.
Now I move my camera in LateUpdate based on initialized EntityManager and target Entity.
And it works correctly i think
sounds fine. i think polling the Entity for its position is ok here. just make sure to not write from GO world to Entities world.
is there a way to require an EntitiesForEach for an update of a system instead of an entityquery? i got an entityquery which should not necassarily trigger an update but an Entities.ForEach that should trigger the System update
its more for curiosity than anything else. i can of course just convert that e.Foreach to a IJobEntity and define the second neccassary query
its a problem in the sense that it's not returning what you expect - it's returning scaled rotation
scale fucks with translation matrix
you need to remove it from the matrix before you can pull out rotation
life is much easier if you avoid scale
I know, I solved the problem before. I using: quaternion.LookRotationSafe(localToWorld.Forward, localToWorld.Up)
But the system what use CopyTransformToGameObject component doesn't work and I cannot change it
Do you know if is possible to limit max. count of workers?
JobsUtility.MaxJobThreadCount
It's const
is there a way in 0.51 to show a list of UpdateBefore/UpdateAfter relationships for a system in the Entity Debugger? found it in DOTS debugger
Some more time spent with the batch renderer group. Yea, this is cutting edge as fuck. It has a lot of potential, hypothetically my entire 18 draw call lighting system can be compressed into "one" draw call with it. But it lacks a lot of the flexibility with render command buffers. For one, there's no way to specify a render texture target other than screen I believe. Which is a major pain point. And there's no way to inter-weave procedural draw calls and compute shader dispatches without exiting the BRG ecosystem altogether although that is apparently on their roadmap to implement.
Strange behavior. I have a SystemBase that has an OnQuitGame method which retrieves a singleton and uses GetBuffer to get it's buffer to read data, serialize and write to file. This is outside a Job System (including Entities.ForEach). Now, when testing it, it works, but after I exit play mode and go back in, and fire that same method, it throws the following:
Unity.Entities.ComponentSystemBase.CheckedState ()```
Things to note. I am using Editor Play Mode with Domain/Scene Reload disabled.
When scripts compile, this error does not throw, the method works, it only throws when I try it consecutively after compilation. Is there an extra step I need take to manually init system state (whatever that is) due to Domain Reload being disabled?
are you unsubscribing from the event?
Can you help me understand what event? Are you saying an event somewhere else that is triggering that method, or there is a special implied event for SystemBase?
well what is OnQuitGame?
It’s just a method. But you know what, I will comb through the code and verify I am unsubscribing from all related event listeners. I think you are on point with this, I’ll look into it tomorrow.
is there any known bug with colliders being converted into way too big versions, that randomly gain and lose force for seemingly no reason?
are you touching scale?
yup
so memory is a little foggy on this but previously physics did not support scale changes at all but i believe now they might support unified. last i heard there were no intentions of supporting non-unified scale ever.
oh that is really annoying, ive never had any issue with non unified scale with dots before, only now, and all my things are made up of non uniform scaled cubes to create stuff, so hmm, ill have to use uniform scaled cubes, and just a whole ton of them
are we talking about entity scale or adjusting the collider bounds itself? i hope the latter is supported?
Uniform runtime scale is something we are planning on investigating, however at the minute for convex hulls or meshes the easiest thing is to modify the input geometry and recreate.
Note that non-uniform runtime scale is not being considered.
from 2020
i believe the top part was done but don't quote me on it
i try not to use scale
oh that is really annoying, also mine aint at runtime though incase that affects anything, still possible, but everything will take twice as long with converting from blender to unity, oh well i guess
hmm i thought during conversion non-uniform scale was baked into the mesh
and /should/ be supported
really doesnt seem like it
judging by how my rigidbodies freak out at having a non uniform scale
in your OnQuitGame method are you destroying worlds/ Systems? Those changes would persist between Game Sessions if its a System Unity wants to keep around.
oh found a difference between entities and gameobject physics, if 2 colliders both under the same rigidbody collide with eachother, they both gain infinite speed for some reason, this usually does not happen in game objects, hence why i stupidly assumed it was scale related, sorry im very dumb sometimes
was my go for conversion
good job though, and thanks for helping me, even if it was just me being stupid without realising it
still annoying that colliders that collide with eachothers under the same rb gain infinite force, i can find workarounds though
wondering, will it be performance costly to set a gameobject's position to the position of an entity every frame?
Unity does it every frame
internal transform system
good point, i never thought of that...
it does it through transform access array
so it's somewhat fast and optimized
but certainly has it's overhead
oh, what if i do mine unoptimized?
of constant 0.16ms for me
nice
I tried it. You'll probably will run into unscalable system, that gets to 1.5ms with 500 objects
oh
hmm is there still no section about DOTS build config in the Doc?
you should use transformaccessarray no reason not to?
it let's you write it in multiple threads
i believe there is now
ill try it out then sure lol
im just tryna make it so my game object based character controller cant walk through the entity based exit door and leave without beating the level
best time to start. will run into all the problems there can be and "learn" alot -.-
game objects shouldn't have access to ECS world
though personally i just setup my configs in 2020.3 and copied them in
once components are on its all fine
exactly, that is the issue, hence why im tryna fake it in a way that works nicely, but thanks for the thing about the transform array thing, it sounds like it will be fun!
why not just keep game logic in ECS?
half my game was build without dots, and im a real newbie to dots, and only a few parts of my game need dots, so for now im not going to convert everything over if i can avoid it
you might not need ECS at all with this approach? You can just use Jobs + Burst
Getting access to ECS from GameObjects is a pain
it was meant otherwise: ECS gets access to GameObjects
unlikely, i need so many spheres with rigidbodies, without using ECS lag is a big issue
welp, good luck then
yup, i have a feeling ill need it
quite weird, Unity still doesn't use DOTS inside their classic Physics engine
perhaps there is an easier way of making my character colliding with entities using some kind of jank method though
raycast does, somewhat from what ive heard, but otherwise i also would have no clue
i could do it the reverse, and have the entities grab the gameobjects positions and change them to be the same as the entities, which would probably be cleverer, still annoying to set up, but easier perhaps
wait im an idiot, i only have 1 exit door per level, so i dont need to use the transform access array, cause ill only have 1 level loaded at a time, so only 1 door needs to stay accurate at once,
laziness once again triumphs in simplicity
the real question is, how do you get a game object in a system base? Is there some way to get them by name, or tag, or something else?
my unity 2020.3 is still starting -.- in the docs there is no guide on what components i need to use to make it work. should i just copy them over from sample repo and go from there or do it manually?
now that im thinking about it, cause every level will have one, it would probably be better to get it by tag if possible, so i can tag it with level 1, 2, 3 etc and then it will make it easier to work out whether or not to sync the game object or if the player is not in that level
An approach i've used in the past is to have for example a public field inside a System, whether it's a nativearray/vector3/float3/whatever and inside your monobehaviour, read/write that System field. Then when the System runs it can do it's own ecs logic, and read/write to that field as needed..
So for example if you have a mono that needs to send a gameobject pos/rot into the ecs world, just write the Vector3 and Quaternion values to the System field inside the mono Update loop, and the System can pick it up when it runs.
A System as i understand it is a managed class in any case, so if you're running mono's there's no reason why you can't just write to the System
Yeah just grab the ones from the samples or netcode sample if you're using that
that is clever!!!!
thank you so much!
guessing i reference the system as a c sharp file, or something like that in the monobehaviour?
World.DefaultGameObjectInjectionWorld.GetExistingSystem<MySystem>() is how you can access systems from monobehaviours
thank you so much!!!!
before i go to bed, with all my new knowledge, im wondering, does float3 convert naturally into vector3 or will i just have to manually convert beforehand?
You can cast it from float3 -> vector3 and vice versa
ok nice, thanks so much!
I'm running into a weird issue with Hybrid Renderer.
After updating the RenderBounds for an entity, the updated bounds don't seem to come into effect until I select its entity in the DOTS Hierarchy editor window.
Has anyone seen something like this before?
Quick example to show what I mean
u sure it has nothing to do with near clipping plane?
I don't think so, it happens for far-off entities too
i had similar issues while working in the editor. focusing on another object fixed it for me so i didnt dig deeper
Interesting. It happens in the player for me too (where I can't open the DOTS Hierarchy), so I'm doing my best to fix it.
if you find the cause let me know 🙂
Nope, none of that going on, but thanks for the question, I’ll keep that in mind in future. Now that I slept on it, I’m more than confident that @rotund token was right.
he usually is 🙂
I think I've found the issue to the rendering issue above.
Hybrid Renderer doesn't update batch bounds unless an entity in that batch has moved.
That seems like a bug in Hybrid Renderer to me.
if nothing within the batch moves, how does the bounds change?
Updating the RenderBounds component on one of the entities in the batch
I'm updating the meshes at runtime
Adding this after each RenderBounds update works around the issue for me:
var localToWorld = EntityManager.GetComponentData<LocalToWorld>(job.Entity);
EntityManager.SetComponentData(job.Entity, localToWorld);
hm ISystem doesnt work with IJobEntity? annoying waste of an 30mins to figure out that one
I have never tried IJobEntity with it but very possible as only some IJobs are actually implemented
it should, i job entity gets code gen'ed to IJEB
and I believe they fixed the burst job scheduling
Are there any issues with storing a BlobAssetReference inside another blob?
Nope. It's just an intPtr, aka a regular int.
I was wondering since there's stuff on the wiki about the data in blobs needing to be "moveable", but I think that only refers to pointers pointing to something inside of the blob, not the blob itself
No, there's no system that combs though all the BARs and keeps them up to date. If the blob moves, all BARs pointing to it are invalidated.
But Im 99% sure blobs dont move past creation. If the blob gets disposed, then you need to manually go through all the BARs and unset them
When do they move then?
No clue. They're stored in allocator persistent memory block so whenever that shifts
I imagine that can't happen during runtime since that would be catastrophic
I dont think any of my BAR ever got invalidated outside disposal so I think you're fine to store them
I don't really understand why internal references need to be stored as offsets instead of an actual pointer to the data then, since the blob moving would break everything anyways
Maybe for some authoring time stuff that uses blobs? I don't know
I don't do a lot of subscene authoring stuff for my project, can you serialize a custom created blob asset into a subscene?
Then I'm guessing this is the actual issue with storing direct pointers. I'm guessing you also can't store a BAR in a BAR that you are writing to a file, since the address would have changed when you load it again
Oh yea, that wont work
Ok, then that part of the wiki makes a lot more sense. I only use BARs for runtime stuff, that's why I was confused
Subscenes are streamed from hard drive byte file through blob assets. Storing BARs in blob assets will result in invalid BARs so dont save a subscene with it.
What's the plan on unity's side in the future? Since there are now two very different scene systems that exist at once.
Or is it just "keep the current one for GOs, and this one for DOTS"?
Actually nevermind, I think I misunderstood it
I'm guessing only the "DOTS" version of the scene is saved as a blob
According to the guys making the batch renderer group API in 2022.2 alpha, the end goal is being able to put everything, GOs and Entity conversion into a subscene that will all be rendered in one super draw call with the BRG.
Huh, interesting
iirc I remember reading somewhere that they want to port a lot of the current GO stuff to use DOTS stuff internally for performance gains, but I haven't checked on that in a long time
One draw call per subscene and you can have multiple subscenes streaming in.
How does this work if things in the subscene use different materials?
Or is that what the BRG does
Yep. That's the magic of BRG.
Multiple materials, multiple meshes, multiple objects.
Does it even batch other normally un-batchable stuff, like non-uniform transforms on dynamic objects?
everything front loaded at once and then it's GPU for the rest of the frame.
The transforms are per instance in a massive array buffer. So that doesnt matter.
Sounds pretty cool
Very interesting but it's apparently GO/Mesh rendering to camera only. Wish I could do things like post processing with it.
I'm assuming that will be added at some point
Post processing ability? Probably not. Im getting the impression that the current render features are the method for that
Doesn't the final image still exist in a render buffer at some point, and couldn't you just blit it then with effects?
No, it's straight to camera. You need to set up a second camera just to capture the output.
And you can't set the camera's output to a render texture?
You can, but the camera itself eats about 1.5ms of CPU just for the setup and rendering. The blit to RT can be measured in nano seconds so the entire camera is a massive computational sink
I guess it depends on the time saving you have then compared to "traditional" rendering, might still be worth it
I doubt it. Using single camera with DrawMeshInstancedProcedural with a ComputeShader selectively updating GPU side buffers and meshes is very cheap. My current 2D lighting stack which is intended for hundreds of lights visible simultaneously and casting shadows costs 0.020ms of CPU time to schedule.
Full screen pixel perfect circles with 500 lights costs about 6.5 ms to render per frame. Using half resolution (which is barely different than full res especially with bilinear filtering and a small gaussian) cuts that down to 1.5ms. 1/10 rendering and it's CPU limited.
I can render 8000 lights (max supported currently) with 1/10 resolution which looks "okay" at CPU limited speeds. It's a completely empty scene otherwise.
The setup of the camera takes longer than rendering 8000 lights, and that's just one cam.
I dont know what you have to be rendering in order to make a post processing stack work on BRG. Which is a real shame.
Didn't know the setup and rendering alone takes that long, never checked. Yeah not being able to use post processing seems like a big downside
Oh you can still use post processing through URP/HDRP render features. That's not an issue.
You just have to do it though multiple draw calls.
TBH I do so little rendering stuff I doubt I can add very much to the conversation, but you certainly seem to know your stuff
And you cant "schedule" those draw calls on a job thread to async call them from the main thread.
I've spent the last few weeks neck deep in the post processing stack
I tried using the hybrid renderer a few years ago and it was so buggy I never tried again
Yea, dont. Hybrid is a mess
Just build your own renderer if you're doing something simple or stick with GOs and handle the data processing entities side before re-distributing it to GOs
URP and HDRP were made with GOs in mind. Hybrid is trying to get in between but it's real difficult.
I've also never looked in depth at how URP/HDRP works vs the default rendering pipeline. To me it's still "URP/HDRP needs you to set up some extra stuff in scriptable objects to work, and supports the 2D renderer" 😬
The fanciest I've gotten on the rendering side is write a really simple shader for "prop-up" 3D shadows on a 2D plane, which is on the very low end of complexity
BRGs are basically a completely new rendering system, kinda. Instead of trying to Indiana jones replace GOs to entities that feed into the URP/HDRP rendering system, it's completely replacing the rendering system and making URP and HDRP basically optional post processing stacks.
It's a third rendering pipeline, despite unity constantly saying HR will not be a third rendering system
Ah ok, I thought it was just some additional renderer feature for URP/HDRP
Currently yes. 2022 version, no.
Then it makes more sense that it doesn't "natively" work with post processing
yea, which is sad.
Just make the game so performant you have the milliseconds over for the normal post processing 
the issue with BRG as a post processing system is that it's practically "single pass" only. I think, i dont see anywhere in the API that allows for the specification of subpasses to be rendered per material.
What happens if you use multiple BRGs, are they rendered separately? I assume the separately rendered objects in this case can't occlude each other
You can specify multiple draw "commands" in a single BRG targeting different cameras / layers and each command has it's own (single) material, (single) mesh, any number of instances, buffer for per instance data for each of those instances, and rendering layer target. You can chain multiple commands with different materials and different mesh combinations and it will all render as one draw call.
I cant think of why you would need more than one BRG.
One for opaque, one for transparency?
But BRGs and the normally rendered URP/HDRP rendered objects "mix" correctly? e.g. a BRG object can be "between" two URP/HDRP objects on the Z axis from the camera's perspective?
Yea, it just draws it to the screen at the proper location and depth filtering like the other two RPs. No occlusion culling so if a regular GO is rendered by URP right in front of the camera, BRG will still render in the target mesh except nothing will show.
If you want occlusion culling, ya have to do it yourself.
At least there's vertex culling, that's built in Core rendering feature.
Is occlusion culling even needed if this system is so fast?
I guess it depends on what you are doing
unitys hybrid renderer dynamic occlusion culling has a lot of potential
high hopes in the future
The benefit of BRG is that it's single GPU data upload and launch point for all object rendering to camera. There's no need for small sync points with main CPU thread for further draw calls or whatever. It doesnt revolutionize how things are actually rendered.
What is happening right now is with a bunch of different objects with different materials, the RP takes each individually and draws them one at a time if none of them are batched. CPU halting until GPU says it's done rendering and then it sends in a different object with different materials and so on.
Sometimes like dynamic batching and the SRP batcher, it detects identical meshes and materials just different transforms and it can merge it into one, but it's really fragile.
Is that what the profiler shows as GPU.WaitForSomethingICantRemember?
I don't know what it is specifically called
GPU.WaitForSignal?
Yeah
Is the "new" game view VSync still done by stalling the CPU?
It's Semaphore.WaitForSignal that's what I was thinking of.
The editor game view stalls the cpu to achieve FPS. Build I think drops GPU frames.
Random rendering question: Do you know how Unity's 2D tilemap renders the Z ordering (the Z position of the Tile) to screen? I've never been able to get the Z position inside of a shader, and I need it for an effect
There's a tilemap Z coordinate and then there's a tilemap Z layer. The first is used by the tilemap internally for hexagonal cell positioning and indexing and is not the same as Z coordinate layering for rendering occlusion and such.
A tilemap is completely flat. If it's the default tilemap and you didnt change the transform's Z value, it will be 0 according to the shader.
you might be better off basically recreating a tilemap. Use the unity provided one for editing and rule tiles then mirror the changes somehow to a plane you create and manually render
if your tilemap's rectangular, that's a lot easier to find the tilemap XY from the transform and bounds at least.
I only need the Z position 😅
hexagonal? You might be able to calculate it manually from LocalToWorld, center point, and bounds but it's gonna be rough.
Like different tile maps overlaid?
Yeah, I know I could use multiple tilemaps, but I'm not sure how that scales performance wise
Basically I re-use a lot of sprites by passing a 1D texture to the material property block of the sprite and using it to re-color based on the sprites R channel.
I'd like to expand this to the tilemap (meaning I would probably pass a 2D "remap" texture, basically a lot of 1D textures"), then I need to pass another array to the shader which maps positions to remap colors, and then remap.
recolor specific tile types or recolor specific locations
Specific tiles, basically all tiles belonging to a biome
But then I would need to store the texture multiple times
(in recolored variants)
Or programatically create it on initialization and create a new texture internally
Hrm, yea. You might want a shader for that. Hrm. The tile type itself is stored in TEXCOORD0 but I dont know what it's referencing.
I know the tiletype since it's procedurally generated, and I know what biome each tile belongs to
That's stuff I could write to arrays and pass to the shader
do you use rule tiles?
No, I have a custom editor for creating auto tiling tiles, these are then converted to TileBase instances, and used inside a scheduled job to form arrays after the procedural generation part, and are then batch passed to the tilemap
If you dont use rule tiles or are willing to implement it yourself, a tilemap is literally a giant quad with a RInt texture plastered on, then post processed on transparency queue to fill in sprites for each.
The most definitely easiest thing would be to just copy the tiles and re-color them to a new texture, and then set that to the TileBase's texture
Easiest but not what I would recommend. Especially since recoloring dynamically is extremely easy on shaders.
Yeah, and it would also open up more effects, e.g. dynamic recoloring for snow or something
The issue is that camera color buffer isnt exposed for custom rendering until post transparency queue on URP at least
I think it should work if I split up all layers into separate TileMap instances, and then pass the correct array to each one?
One performance "drop" in this case is that I would need to call SetTiles for each layer, but it should still be fine
hrm, i dont know. Tilemaps arent hard to code, especially if you just render your own custom tilemap at Z coordinate -1 so it's behind all the sprite rendering earlier in Opaques.
And if you use your own custom tilemap editor, then rehooking it up to your own custom tilemap wont be difficult.
I have an editor for tiles, but not for tilemaps. The maps are all generated, so I never used the one from unity
You can even offload the entire thing to GPU.
Oh hrm, still. It's very easy relatively. You dont even need to touch a single actual mesh other than a quad.
So how would that work conceptually? I've never done it. For each tile grab the UVs which correspond to the sheet it's on, set the UV array on the mesh to the correct ones?
iirc unity's tilemap doesn't even do more complex stuff like greedy meshing, and it's still pretty fast
Nah, you have one massive quad with scale the size of the tilemap bounds. Then you have 1 render texture plastered on it with the same bounds. Each pixel on that render texture will be an int value that corresponds to a tile type and sprite. Then in a full screen camera render, you replace that single int index with the actual sprite of the tile.
See that seems like a lot of complex stuff for somebody that's never done it before 😅
you calculate the UV of that sprite to sample in replacing the pixel on the screen with the local space UV / tilemap bounds to obtain the cell's UV.
very simple, 2 shaders at most. The hardest part of this will be making an editor for this tilemap.
I don't have any authoring time tilemaps, they're all generated
ah, that's even better. Yea, all of this can be done on the GPU. Alternatively you can have an compute bufffer array of ints and then populate the camera screen with single sprite quads.
That's what I'm doing with my 2D lighting engine. 8000 "tiles" max in a single screen.
I take a single quad, scale it GPU side to the size of its radius, color it in with an appropriate inverse square circle falloff and light color, black out tiles in shadow, and then paste it onto the game view scene.
And do that for every light visible, up to 8000 times
Are the "lights" here actual unity lights?
nope, just my own custom struct. A float for radius, a float2 for position, and a float for wall illumination. Then a float4 for light color.
Why the 8000 limit then?
I color in a texture with the light's 1D depth map. Maximum texture size in unity is 8126 or something, which means thats the max amount of lights.
I could add extra channels for extra lights, for a total of ~24,000 lights if I want to (currently I only use the R channel, it can be expanded to G, B, and A if needed) but the lights start noticably laggin hard past 8000
And more if I enable more textures but at that point, the screen will be white.
modern art
For these 4 lines of light
if you disperse those lights, the depth textures will look like complete noise.
but each row represents a single light's 360 view
If you jack up the light radius, thats what it'll look like for 500 lights
flashbang
Yea. It's also chugging at 500 which is pain
Just so I understood this correctly, I write the tiles as integer indices to the render texture on the CPU, render that texture as a quad (which scales it up to the "world"'s size), and I do this for each layer of the tilemap, correct?
How do I then render the actual sprite ("replace" the indices)?
As long as all the tiles on my sprite sheet are square and the same size I guess I can use the index to just index the sprite sheet directly
You have a pixel coordinate in camera UV space in a frag shader. You can use some of the matrixes available to convert that to world space then, when using orthographic rendering, subtract the camera's Z position from the pixel's Z position to get tilemap's XY world space position. Then you use the tilemap's local to world to get local coordinate for the pixel on the screen. Then you use the tilemap's bounds to determine the cell's UV position that is then used to sample the target's sprite's UV.
using the camera's RGB, you can have a maximum of 4 billion tiles.
riddle me this
{
for (var index = 0; index < statValueBuffer.Length; index++)
{
StatEffect* effect = statValueBuffer[index].Effect;
ref StatModifier modifier = ref this.statModifiers.ElementAt(effect->Type);
modifier = modifier.Add(*effect);
}
}```
effect->Type is 0-99 and by default randomly ordered
why is it if I pre-sort it on Type this chunk of code takes reliably longer every time
0.22-0.34ms vs 0.35-0.45ms tested a dozen times over a lot of frames switching between
I expected either no change or an improvement
What does burst say?
burst doesn't change
this job doesn't change
it's sorted outside of the job in oncreate
the only different is this.statModifiers buffer is ordered by Type
I dont expect an improvement because a property access via pointer isnt detected by burst to be a constant for multiple iterations. But the reduction in performance is odd.
Yea, this is random access so no vectorization so it's not like the vectorized were replaced.
// ..
foreach (var entity in entities)
{
// ..
// values.AsNativeArray().Sort(new Sorter()); // This is only piece of code changed between tests
}
}```
only reason i'd expect a change in performance is simply i might have it preloaded in memory but in reality i expected no change
i don't understand how it's significantly slower
Is the profiler measuring the sorting?
no it's in oncreate
this code is in a job
running every frame
try mem copying the results of values into a new array and deleting the old sorted array?
How many entities is this and how large is statValueBuffer?
values is just a DynamicBuffer
10,000 entities and in this test statValueBuffer is 20-60 elements randomly generated
So the data layout changed between your tests?
If you instead generated these values in order, the performance will be in the 0.2Xms range right?
does sort generate garbage?
why would that matter
How would you design animation system? Say i have animation data which stored inside blob asset, and system which want to access to this data. What will you use? Enums/ids/String -> Hash/etc?
Did you try changing the seed? Maybe the data layout is just "randomly" much better for the way it's currently layed out
If i remember correctly, sort requires use of burst discard due to the dynamic sorting function
but it's completely irrelevant
even if i coped it to a List<T>
sorted it
wrote it back to the buffers
danced in circles
it has nothing to do with the profile
well yeah it has 0 size allocated
it's always out of the chunk
[InternalBufferCapacity(0)]
public unsafe struct StatValueBuffer : IBufferElementData
{
[NativeDisableUnsafePtrRestriction]
internal StatEffect* Effect;
}```
And nothing else was running during this job
there is the only piece of code running
even if i get rid of the markers thinking there's something wrong with that (and it does make the job go from 0.65->2.5ms) it's visually noticeable just profiling the actual job
nothing initialized between the creation of the buffer and the execution of the job
nope
was the buffers initialized in sequence?
yes
ok my code trick has broken =S
my entire job
that's all that is running
in the project when profile
try instead initializing one, creating a native array with random length in temp memory, then initializing another entity and so on to break the sequence
there are no native arrays
because I think sorting the array is creating a new array of sorted values and replacing pointer of buffer and invalidating the old one
there is no allocated memory
sort does not allocate anything
it just does a swap
moving sort out of the loop and doing all the sorts at once at the end does not change the result (just tested)
It allocates something in temp buffer when merging the sorted segments with a custom comparable
It does memcopy it straight back into the original buffer though
Oh, same file. Just keep scrolling down. I dont know. If the pre-sorted at generation doesnt result in the performance drop, uh hrm
Result is the same even with a different seed?
does the sort actually sort from 0-99 and not from 99-0 by accident?
I would have also guessed that it doesn't matter which order it actually is though. strange results that you're getting
Why would you need it twice
Since forever. You cant have 2 buffers of the same type
i'm an idiot
nm
😛
couldn't see the wood for the trees 😐
i thought they'd introduced a restriction of one dynamicbuffer for ForEach 😮
i already tried in reverse because i thought free performance! it made no sense anyway
regardless just going to ignore it as there's no benefit to sorting so no need to do it
havent tried this yet but think this would be a dumb idea to used a managed class component to pass around a nativestream to different systems?
you are somewhat describing my popular event system (at least the 1.x version of it)
except without the need for a component
actually i guess using a component is a bit different than a system to manage it
it's not the worst idea, at least it handles safety for you
yes it just doesn't work
https://forum.unity.com/threads/0-51-build-configuration-failed-to-add-component.1296681/#post-8216532
workaround here supposedly - i haven't tried, i just had all mine setup from previously in 2020.3
oh thanks for the thread 🤩
hack doesn't seem to work but I'm probably doing it wrong
guess I'll just steal a config from somewhere for now
Ever since Entities 0.50, I been getting the following issue. Everytime I make a successful build, as long as I had DOTS Hierarchy window open, it will fire off this error: The specified HierarchyNodeHandle(Scene:-119930:0) does not exist in the hierarchy. every editor frame. A simple script re-compile (right-click reimport) make this stop. Or if you close the DOTS Hierarchy and open it again it also stops.
This has been going on all the way through latest Entities 0.51 and latest 2020.3.36f (started from 2020.3.30ish). Anyone else run into this issue? It doesn't break the game or the editor in any way, just get's annoying to have to recompile after each build is all.
been trying to do this, and i cant seem to find any easy way of doing it, anyone know any easy methods? It seems from googling that Reinterpret<Vector3>() would be the best way to do it, except that it cant find that method
thank you so much!
wait no, that is the wrong way, sorry lol, is there anyway to go from float3 to vector3?
hehe well i don't want to risk reinventing the wheel here but:
some values will cast directly like that and some won't
other ways in c# are like:
im just tryna set a position of a gameObject to the position of an entity, incase that helps
Vector3 v = Vector3.one;
float3 f = v as float3;
or
Vector3 v = Vector3.one;
float3 f = (float3)v;
but you don't need that in this case obviously
just in case it's helpful
thanks lol
also none of those ways you said up top are working for me, they all give me errors, perhaps im missing a library?
which way isn't working?
both
actually 'as' only works with reference or nullable types sorry, i forgot, so that method works with classes etc
could you show
sure, should i show with or without the methods in place?
just show a clip of what you have atm
ok,
doors[door_comp.door_id].transform.position = translation.Value;
this is inside a for each loop of entities btw
so what about it isn't working
well i need to convert the translation.value float3 thing to the vector3 thing, cause it does not do that automatically right?
or have i assumed something completely false accidentally?
what you've written is technically ok
ah so it will work?
the t.Value will convert directly to Vector3 and assign to transform.position
welp i feel like an idiot now
i kinda made a stupid assumption that it wouldnt lol, oh well, thank you so much!
we're all idiots, welcome to the club 😛
yay
except tertle, he's not
lol
🤡
i saw tertle in the wild web answering a post about dots while googling stuff earlier
i just hid my 2 years of stupidity while no one else was using dots
lol
also, unrelated, but i only just realised your username is "midnight cow" and not "midnight crow"
also is it possible to use TransformPoint in a systembase, or is there some other way of converting from local space to everything space (i dont remember what it is called...)
really inside systembase you don't want to use ANYTHING from any managed classes
so no methods from Transform or anything
i dont quite know what that all those things mean, but i vaguely understand, what should i do instead?
to get the world position of a position:
globalposition = parentposition*localposition;
oh ok cool!, how on earth do i get the parent of an entity?
hi, how do I get DOTS working on linux?
(entities packages are installed but entities dont get rendered and I get hybrid renderer V2 errors)
welllll it depends on the context really, you have to figure out what works best
makes sense, ill find something chaotic that works, i always do, ish, lol
a child entity has a Parent component though, with a reference to the parent
aha, so i should probably use that get component thing that the entities own
there's a LocalToWorld component also, which holds the world position of an entity
oh that sounds nice! I'll check it out!
if i were to add and remove it every single frame, on a scale of 1 - 10 how terrible would performance be?
i realise i could do it only on the first frame, but eh i can do that later
uhh add and remove what, the ltw component?
probably
why would you want/need to do that
i dont really know, morbid curiosity combined with tiredness i suppose, i should really just not be lazy and do it first frame only, thank you so much!
ah ok
well adding and removing components are structural changes.. so doing that involves creating new archetypes and stuff..
so really it should be viewed as something to not do constantly
fascinating, so no burst, meaning ultra lag, how intriguing lol
oh ok cool
but adding/removing components should really in an ideal world only be done when needed
lol, i probably will do that lol
hehe ok well have fun, you'll figure it out eventually, at least you're making the effort to learn
yay thanks lol
instantiating a prefab that consists of a hierarchy of physics joints in unnecessarily painful
at a specific position i mean.. because you have to manually position each physics object rather than just specify a position for the prefab to spawn and done
ok figuring out the whole localtoworld component thing, judging by googling stuff, guessing you gotta add it while looping through all the entities and then just add it to the right ones only, this is fun!
so you need to store the relative positions of all the physics bodies, then set translation of each relative to your 'spawn point'
annoying
same with rotation
your entity should already have it, so no need to add/remove
just read the value when you need it
oh ok cool, thankyou!
yas now i have the exit doors actually have proper colission, now you cant just walk through them and skip the level, thank you so much!
although im gonna do more testing, cause i got a theory, i wanna see if it is more performant to have an if statement that checks if the positions are roughly the same then do nothing, cause i have a feeling it will be!
weird question, why is transform.position a variable, but tranform.position.z is not?
due to this i have to set all 3 axis at once, instead of only setting the 1 axis that moves
is there anyway to make transform.position.z a variable so that i can set only 1 axis instead of 3?
also the mathf approximately thing completely breaks sometimes for seemingly no reason, and it says stuff like 10 is approximately 15, so eh ill pass true, although this appears to be quite rare
Inside systems use Unity.Mathenatics.math instead of mathf
oh ok thank you so mcuh!
so what would be the alternate function then?
There are equivalents for most of the mathf methods in math
oh ok, ill go do some research and report back, thanks so much!
oh from research it appers it is still being discussed on what to name it and how it should work, so currently there is no equivelant, according to the github issues page atleast
should i just round each of the floats to a certain amount and then just use == then?
from more research it does seem that i should just continue using mathf for the approx function, as there appears to be nothing better unfortunately, unless im missing something obvious
Ahh sorry I hadn't noticed u were using approximately, not at the pc atm so cant check :|
its ok lol
Mathf.Approximately is just abs(x1 - x2) < epsilon afaik
yup it is
as such why bother reinventing the wheel, shouldnt i just use the mathf one then?
It uses Mathf functions internally, not math functions
If you're getting rounding problems could maybe multiply the float by 100 or so and compare the integer value
Just copy the Approximately code and replace the Mathf versions with math versions
oh ok ill try that
This is the code: public static bool Approximately(float a, float b) => (double) Mathf.Abs(b - a) < (double) Mathf.Max(1E-06f * Mathf.Max(Mathf.Abs(a), Mathf.Abs(b)), Mathf.Epsilon * 8f);
not really, ish
thank you so much!
Also, if you plan to use your new custom math.approximately function a lot, I would add a [MethodImpl(MethodImplOptions.AggressiveInlining)] above it for good measure
oh ok ye, i plan on using it every frame, so ill do that thanks!
and make it static
ok thanks!
I think that's a given unless he creates a new math struct and puts the function in there
Hehe yeah I realised as I'd used aggressive inlining yesterday and forgot to add static, duh
I wish it was possible to add static functions to namespaces as extension methods, I hate naming stuff like this <existingstaticclass>Extensions
bit of a noob to the whole static and agressive inlining thing, so i have a few dumb questions sorry:
- what library do i need to import to be able to use it
- how do i make it static?
Uhh, from memory.. system.something :P
lol
to make static just put static in front of the method return
what does that mean? What return?
Like 'static void myMethod()'
oh ok, i have to make this thing a method, i thought i just had it as a bool, this is cool lol
oh this is gonna be harder, apparrrently unity maths does not have any equivelent for epsilon, so imma have to create my own one then
ah this is really complex, when i wanted to make doors have collission as a goal for today, i did not realise how deep i would sink into math madness, oh well, onwards i go!
and do i use epsilon b or a when creating an epsilon?
Mathf.Epsilon is math.FLT_MIN_NORMAL in the new math library
thank you so much!
making certain, did i do it all right: ```csharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Approximately(float a, float b) => (double)math.abs(b - a) < (double)math.max(1E-06f * math.max(math.abs(a), math.abs(b)), math.FLT_MIN_NORMAL * 8f);
math.FLT_MIN_NORMAL * 8.0f is likely still math.FLT_MIN_NORMAL
It's Unity's Mathf.Approximately implementation 🤷
oh ok, sorry, im just tryna follow the mathf implementation...
yas thanks
also due to how there is not much info on unity.mathematics, im going to ask a stupid question yet again! How do you round?
math.round
Thanks so much!
Also the mathematics package is on UPM, you can check the current implementation here: https://github.com/needle-mirror/com.unity.mathematics
oh that will be very useful, thank you so much!
also i think "thank you so much" is becoming my catch phrase lol
It can just be a bit tricky to navigate since a lot of the code is auto-generated due to a lot of overlap between types
The majority of the static math functions are here: https://github.com/needle-mirror/com.unity.mathematics/blob/master/Unity.Mathematics/math.cs
oh ok, thank you so much!
Although, again, a lot of overloads for many type combinations
makes sense, thank you so much yet again!
No worries
lol
aha, how do i round something to a specific decimal point, cause it appears that round() is with no decimal places, sorry lol for being vague earlier
I'm not sure what the fastest way to do it is, and Unity also does not have a round to digits function afaik, but this is the implementation in Math.Round
perhaps i could use the weird trick of multiplying the float by something then dividing it like i saw on an ancient post?
Why do you need to round to specific digits?
i want to use my approximately thing in combination with a less accurate position from a game object and an entity to save performance in a way that the player wont notice that the collission aint accurate
it is a little jank, but it should work in theory
Just a heads up, approximately will not tell you if two float values are close, it will tell you if two float values are functionally equal to one another
i know, it is great
aha i got it!
so i multiply it by the amount of decimals i want expressed in the 1 with 0 the amount, if that makes sense, then round, then divide by the same
oh, and that lets me choose the amount of decimals?
woah ok than you so much!
But your version is probably fast if you don't need midpoint rounding
It skips the midpoint rounding check in the function I posted above
Which makes it equal to your version
i dont know what midpoint round is lol
ooh nice, thank you!
It doesn't really matter in your case though, you want performance, not accuracy. I think rounding approach is more important in a banking context and not in a video game 😅
good point, so overall which method you think is faster lol?
I think you are fine with calling System.Math.Round, but it's up to you. The compiler and CPU are pretty good at predicting branches that are never taken
oh ok, ill do the system math round thing for tonight, but on the weekend ill test both and see which one performs better
I don't think you'll be able to see a difference
and do i need to import System.Math im guessing?
probably, but its fun!
You can also just write System.Math.Round
oh so i dont need to import anything then? nice!
The System name space is part of the language, so no
(double)1f
I just checked, you can't use System.Math.Round to round to a specific amount of digits. You'll need to write your own function. Burst converts it to vroundss and strips the parameters, and it is specifically stated as unsupported in the burst docs
It will just round your number to the nearest integer
Kind of odd that burst doesn't throw a compilation error in this case, maybe it's because I'm on an old version
You can likely get away with math.round(float * 10^n) / 10^n to round to the nearest digit, where n is the digit you want to round to
is there a way to get thread index inside a system ForEach
ooh that is sounds clever!
ill try that!
trying to implement the method shown here for Unity.Mathematics.Random:
https://forum.unity.com/threads/solved-gen-random-number-in-job-execute-causes-hang.779987/#post-5191244
But in ForEach rather than jobs
basically the method creates an array of Random structs, one for each possible thread
then each job can access and increment it's own random for it's own thread, in order to get true random
( using one single random struct across all threads will produce the same results )
wondering if there's something similar to ForEach (in int entityInQueryIndex) but for thread index
try Entities.ForEach((int nativeThreadIndex) => { }) https://docs.unity3d.com/Packages/com.unity.entities@0.51/manual/ecs_entities_foreach.html (custom delegates section describes the 3 special params)
Ahh, thanks a lot
Was getting zero results searching for it:
I hadn't realized not to use 'in' with entityInQueryIndex
why EntityCommandBufferSystem do GC alloc?
In the recent 0.51 announcement (that they finally posted), they mentioned
A new simplified
SystemBasetype that allows for implicit job scheduling and the ability to schedule jobs to run both sequentially and in parallel"
Does anyone know what that means?
I think its just talking about .Schedule and .ScheduleParallel and SystemBase replacing the old EntityComponentJobSystem or whatever it was called, because I noticed there was a lot of mention of that in the 5.0 docs, maybe for the benefit of people who'd used the old way of doing it 🤷♂️
As well as emphasis on the Dependancy return for controlling scheduling order etc
Any idea how this should be handled better? Like you have SystemA and SystemB. SystemA schedules jobA and SystemBs job needs the handle from jobA. In a SystemBase this isn't really a problem. You can just get the handle from the systemBase class. But how should we handle this in ISystem?
Unitys built in dependency management!?
Ideally this hard dependency coupling is something you'd want to avoid
But if you really need it, my event system 2.0 branch can handle it
And works with ISystem if you want inspiration
ive not run into a case yet where i had to pass handles between systems. i quite like the automatic management. most i do is order systems manually in some cases by creating them in a specific order
I'm not aware that unitys built in can manage 2 systems. yeah trying to avoid it. what's the most reasonable then? schedule all the jobs from 1 system ao i can set the proper handles?
if i merge it all in 1 system it's gonna be huuuuge 😅
Im refering to the Attributes (UpdateAfter etc.) that handle dependencies between jobs in those systems
i think tertle is too
huh i thought this only manages the order of updates? so it puts the dependency jobhandle from the system in the attribute too?
it makes sure that the dependencies between the systems are resolved correctly. each job in SystemB will indirectly have a dependency to each job in SystemA
atleast if you use the dependency of the System itself as a dependency in its jobs
alright, i gotta try this then. could be a little crude though. but maybe I have to move dispose jobs somewhere else then
i dont know how hard it will be for you to refactor but writing it like that from the getgo is really simple
And btw even if you dont use the attributes unity does some automatic dependency handling. it makes sure jobs are resolved in the order you scheduled the systems. so if 2 jobs in 2 different systems want to write to the same component those jobs are handled in System Order
I use this in my AI to schedule the systems in an order defined in a graph without having to know which systems actually will exist at runtime
not too hard to refactor. I just need to know what I'm doing 🙂 So, having UpdateAfter(SystemA) on SystemB would also give me the dependency of the job scheduled in SystemA? I sadly have never quite figured out how the first state of Dependency in a SystemBase is formed.
i should debug it at some point to understand it better.
the first dependency (Dependency of the System itself) in a systembase is formed by looking at the system order in the playerloop. Unity figures out dependencies on other systems for you based on the entityqueries the systems have
so if you tie all your jobs of a system to the systems dependency its all automatically resolved
ah well, i have only a small amount of actual queries
and only if you need to run it in a specific order u need to use the attributes
well the jobs would still run in the order you scheduled the systems
to be more specific. i have 3 systems that write to arrays. all 3 are not dependent and run in parallel. once one is done i run another data transformation job for each and when those 3 are done one job reads from all 3 finished data. so that's why i have the handles in place. easiest solution.
i don't think i can handle this just with update after
i didnt fully understand the second step there. the last system could just have 3x the UpdateAfter Attribute
ok i'll try this. thanks
is that second step actually a step that could be merged into the first job of each system?
cause i found it improved performance alot to schedule less but bigger jobs
yeah it could be moved without trouble
maybe this is useful to you
ah no it cant run in the same job. one is parallel, the other single
ah i see
The current implementation of inter-system dependency is fairly simple. Between systems, Dependency.Complete() is called. What?
not true
yeah ok 😄
i think what Kmsxkuse saw had something to do with which components he used. if he always wrote into the same component he would see something like syncpoints because each system would have to wait for the previous system
thats why its so damn imortant to declare read and write dependency correctly for unitys automatic dependency management
ah, right. i have the last system already in another systemgroup so that should mean i don't need any updateafter
if you made sure the systemgroup is executed later in the frame you dont
im still not certain about what happens if you'd not use any queries and no attributes. it might be possible that your last system then updates after the first few systems but before the first jobs are finished.
Since the system has no clue that it has any dependency
i expect it to crash and burn 😄
yep, it's crashing and burning. seems it doesn't figure it out (as expected)
then use the attribute and it should work
i already do
0.o must work then
do you Update the System dependencies when you schedule the jobs?
like : Dependency = job.Schedule(Dependency);
That's not really how it works
yah i worded that badly :S
Individual jobs do not get their own handle, the system just has s single dependency which is based off all queries and GetX operational used it
thats why you need to do this "Dependency = job.Schedule(Dependency);" too
As for the attributes, update before /after they actually do nothing except choose the order the systems update
thanks for clarifing tertle. im bad at explaining stuff ^^
Unless you're using simple dependency mode, a system that updates later is only passed a previous dependency if it needs it because of a component
And this is what makes read and read write definitions important
But yeah you covered that 👍
i hope poor enzi isnt too confused now 🙂
His problem is sharing containers right
Which is just not handled by dependency system automatically without some magic
i understood it more as a job dependency problem. i think he got the containers covered
if he needs to manually pass the containers between systems then it wouldnt rly matter much to also pass the handles i guess
are you certain you dont declare a dependency between systems with this? sure the mainthread execution of the SystemB wont wait until SystemA's handle is done but i thought the jobs SystemB is Scheduling with its own Dependency do wait for jobs with SystemA's Dependency
yep, I figured. can you share the solution you mentioned earlier?
Only if you enable simple system dependency
Systems have no inherit dependency from order, just that the jobs scheduled first
Dependency is driven by queries
My event system repo is public, not sure it'll be what you need as it might be more complex but yeah the 2.0 branch supports I system and my event system is just a way to share containers between system - so in a round about way doing that
okay so [UpdateAfter] wont work for enzi. i see...
im just lucky all my systems have queries i guess
i have to say, even ifit woukd work with just updateaftet and Dependency. the code gets horrible and loses a lot if intent that is visible through jobhandles. like I would be the only one who knew the real dependencies.
thanks! and you never share handles between systems tertle? i know of your dislike of systems being dependent on each other. maybe i just need to merge them all i to 1
I don't mind systems within its own library being dependent on each other
i agree. having huge systemchains gets very confusing. i started out like that but now write larger systems and group them better. i wish unity gave a visual way to inspect dependencies between systems
i actually wanted to write a tool for that some time ago 😃
i think i read somewhere that unity had done this in an internal hackathon. just never released it :S
I just realized I'm still on Burst 1.6.6 (default dependency when setting up DOTS). I see latest stable release is 1.7.3, I would like to update, but before I do, can I get some input on whether I should[n't] do it and why?
1.6.6 is actually reasonably new
but you should upgrade to 1.7.2+ as it fixes some critical issues
its mostly stability and compiling performance improvements
i updated to 1.7.2 2 days ago and can confirm its faster for me
Ok Awesome, thanks for tip
i heard 1.8 has a caching bug. am i misremembering or did 1.7 had the same bug?
its fixed in 1.7.2
very cool, need to update myself then
1.8 was out before 1.7.2
so it hasnt been fixed in that yet
i really dislike writing code that works with simd
makes it all so much more gross
but the benefits...
yep, i can relate
its like putting your hands behind your back to scratch your nose. but yeah the benefits are just massive
[ReadOnly]
public NativeArray<StatSchema> StatSchemas;
[NativeDisableContainerSafetyRestriction]
private NativeArray<StatModifier> statModifiers;
using (new ProfilerMarker("CalculateModifiedValue").Auto())
{
for (var index = 0; index < stats.Length; index++)
{
var schema = this.StatSchemas[index];
var modifier = this.statModifiers[index];
var value = schema.CalculateModifiedValue(modifier);
stats[index] = new Stat { Value = value };
}
}```
[ReadOnly]
public NativeArray<float> Mins;
[ReadOnly]
public NativeArray<float> Maxs;
[ReadOnly]
public NativeArray<int> BaseValues;
[NativeDisableContainerSafetyRestriction]
private NativeArray<int> added;
[NativeDisableContainerSafetyRestriction]
private NativeArray<float> increased;
[NativeDisableContainerSafetyRestriction]
private NativeArray<float> reduced;
[NativeDisableContainerSafetyRestriction]
private NativeArray<float> more;
[NativeDisableContainerSafetyRestriction]
private NativeArray<float> less;
var mins = this.Mins.Reinterpret<float4>(UnsafeUtility.SizeOf<float>());
var maxs = this.Maxs.Reinterpret<float4>(UnsafeUtility.SizeOf<float>());
var baseValues = this.BaseValues.Reinterpret<int4>(UnsafeUtility.SizeOf<int>());
var addeds = this.added.Reinterpret<int4>(UnsafeUtility.SizeOf<int>());
var increaseds = this.increased.Reinterpret<float4>(UnsafeUtility.SizeOf<float>());
var reduceds = this.reduced.Reinterpret<float4>(UnsafeUtility.SizeOf<float>());
var mores = this.more.Reinterpret<float4>(UnsafeUtility.SizeOf<float>());
var lesss = this.less.Reinterpret<float4>(UnsafeUtility.SizeOf<float>());
var stats4 = stats.Reinterpret<float4>(UnsafeUtility.SizeOf<Stat>());
using (new ProfilerMarker("CalculateModifiedValue2").Auto())
{
for (var index = 0; index < baseValues.Length; index++)
{
var min = mins[index];
var max = maxs[index];
var baseValue = baseValues[index];
var added = baseValue + addeds[index];
var additive = 1 + increaseds[index] - reduceds[index];
var multiplicative = mores[index] * lesss[index];
var value = math.clamp(added * additive * multiplicative, min, max);
stats4[index] = value;
}
}```
but the benefits 😦
0.74 -> 0.21
ah yeah, the expected 4x speedup
total clusterfuck to read. no wonder simd experts say, write the algorithm until it's stable, then vecorize.
well, it's much better on desktop to read. was on mobile before haha
oh, cool you did something I wanted to test some time ago. pack all into type4 but I missed that reinterpret exists so the code was a mess. pretty cool that this works!
reformatted before/after
ah you did the other way around. reinterpret from float to float4. even better
nearl 1:1! haha
now I'm back at my desktop, taking another stab at the jobhandles. are you sharing any jobhandles for ISystem in your events repo? Was for something different, right?
it shares the handle
let me show you the magic
again this is likely way more complex than you need
public struct Writing : ISystem
{
private EventProducer<int> producer;
public void OnCreate(ref SystemState state)
{
this.producer = state.World.GetExistingSystem<EventSystem>().RegisterProducer<int>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var writer = this.producer.CreateWriter();
// pass to job, do stuff
this.producer.AddJobHandle(state.Dependency);
}```
public struct Reading : ISystem
{
private EventConsumer<int> consumer;
public void OnCreate(ref SystemState state)
{
this.consumer = state.World.GetExistingSystem<EventSystem>().RegisterConsumer<int>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
state.Dependency = this.consumer.GetReaders(state.Dependency, out UnsafeReadArray<NativeEventStream.Reader> readers);
// pass to job, do stuff
this.consumer.AddJobHandle(state.Dependency);
}```
pass in the handle at end of writing, and read it beginning of reading
(its returning UnsafeReadArray because you can have multiple writers, this is an event system after all)
cool thanks! i can figure out the rest
are you passing from ISystem to ISystem?
if so you can just access the other system in the OnUpdate
that's the plan. oh really? i thought i can't get an isystem
SystemRef<Writing> writing = state.WorldUnmanaged.GetExistingUnmanagedSystem<Writing>();
What's the purpose of all that low lvl stuff?
that basically gets you the pointer to the system
in my case i want to share some jobhandles around
Sometimes I wish we could just have publicizer for production
So many annoying internals privates protected...
can the SystemRef be cached too in OnCreate?
never tried
i've never used this api actually i just know it exists
i'm only really heavily using ISystem for my current library i'm working on
I love how pure it makes my code
I'm trying to use material overrides with Hybrid v2 but the MaterialProperty attribute doesn't exist for me
These attributes do not exist
Namespaces:
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine.InputSystem;
using Unity.Rendering.HybridV2;```
This is pretty interesting to see the difference in the data layout and speed.. I'm curious does burst not already do something like this anyway when it compiles the 'before' code?
Nope
From memory it won't/can't simd slices but I was going to confirm this shortly anyway, just have no power atm due to electrical work
How could it?
I'm giving it float float int structs
Not like it can magically jump out of my job and rewrite my code for me
Best it could do is use slice
Now it's not certain I need to reinterpret to float4 etc
I could maybe keep it in float and burst would figure that out - it's just easier to confirm I haven't missed something if I convert it myself.
But yeah the big issue is the original struct layout
And breaking the struct into seperate arrays
yeah that's interesting.. i guess i thought maybe when it compiles, it would break up the struct and maybe even reinterpret as float4's etc
It can do the reinterpret bit itself under certain circumstances
i didn't realise Reinterpret actually did that btw, nice bit of code 🙂
You've achieved a 3x speedup which is pretty significant on top of what burst&ecs can already do
Can your ide not hint what assembly it's in?
I had to restart unity and VS, then it showed me
arrowx would disagree! 🤣
I'm still training my transformer network so that one day it can tell me what line of code I should type next...
does ecb already work in ISystem?
Why wouldn't it?
Have any of the existing "default" ECS systems been converted to use ISystem?
wait, I don't know what you mean with the plural 🙂 ecb from EndSimulationEntityCommandBufferSystem doesn't seem to work, correct?
I think he meant EntityCommandBufferSystem, not the plural of ECB
ok 🙂 hm, that makes things a bit more difficult
it's pretty nice that packages as dependency now show up but is there also a way to update them to a newer version without editing the manifest file?
they've always appeared, you just need to turn the option on
nah, I mean showing up like that
that wasn't the case in 2020.3 but I didn't find a way to change the version. (wanted to update burst and had to do it through manifest)
oh yep
hmm, i could always update dependencies though
it didnt have that nice text there though
yeah 2020.3, mathematics is only a dependency and not in manifest but could be updated separately
i'm not going insane
haha, sorry 🙂 so this is a regression because the ability to change versions is now gone :/
oh yeah in 2021 just completely hides most package updates
it's super annoying
even when show preview packages is selected a lot don't show
there needs to be a new, show super preview packages option
Did you try the konami code yet? I think that's where the packages are hiding...
oh right, with how many are you testing?
huh, what's your underlying data structure? buffers?