#archived-dots
1 messages ยท Page 242 of 1
@rustic rain
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
public class MapGridNeighbourManagementSystem : SystemBase {
but I think now, by default every system goes into that group anyways from my recent test
@coarse turtle I get, cannot assign void to inplictly typed variable
wait a second. What components will be in Instantiated entity from this prefab?
or we should use the non ecs job system?
https://docs.unity3d.com/Manual/JobSystemJobDependencies.html?_ga=2.92731934.2014815354.1641065380-1774713299.1640232477
Not sure what you're seeing exactly, but this compiles in a SystemBase.
JobHandle handle = Job.WithCode(() => {
int a = 1 + 1;
}).Schedule(Dependency);
so, looks like DOTS creates a lot of components itself
ok nice one thanks, I needed to be using Unity.Jobs
so last q, how to make it so nothing is waiting on it (e.g I can pick it up a few frames later without fps hits)?
I guess converted objects will have those components no matter what?
I removed everything from object, but it still has all those components I don't really need
I'm assuming I can remove all components I don't need in Convert()?
//This will add our dependency to be played back on the BeginSimulationEntityCommandBuffer
m_BeginSimECB.AddJobHandleForProducer(Dependency);
Any tip for exactly this is doing?
Now that Unity announced that Hybrid is the way forward. How are you guys handling ECS Physics? I don't want 2 running physics simulations that need to be synced. Any straight forward MB implementation that uses ECS Physics for collision?
It adds the calling system to the list of dependencies using the ecb system's buffer
Dependencies on what?
On the command buffer job managed by the ecb system
Basically it tells the ecb system that it needs to force complete all these jobs before it runs the buffer
oh, so by default it might run before this job is complete
Otherwise it will cause a dependency error
Pretty much, it has no way of knowing there's a dependency between the ecb system and your system since the ecb system runs on the main thread. so that's how you tell the safety system that there is a dependency
That's my understanding of it at least
hybrid is not the way forward, it's more the way how 1.0 will initially function.
Why would there be 2 physics systems?
"Hybrid" basically just refers to the conversion system, everything at runtime should be pure entities
I feel like the best way to render things is pure code:
Calling DrawMesh() or DrawMeshInstanced()
But I might be totally wrong as I never even touched that subject yet
no not really. hybrid refers to the whole game. different systems will not be able to be used in pure dots yet. e.g. cameras
This means the scope of 1.0 includes strong conversion workflows allowing you to choose ECS for its value in solving specific challenges while leveraging GameObjects for other aspects of your production
hybrid renderer for now
Okay well physics is not one of those systems
@viral sonnet my somewhat current setup has skinned monobehaviour characters which have ecs physics attached to the bones for entity collision and entity ragdolls, not really sure if its straightforward but its not exactly difficult either, just a bit fiddly to setup
Any idea what is better approach to this subject:
For example there's a universal Velocity component, and movement system will move all those entities based on it.
But what if Some of those entities have VelocityModifier component, which shouldn't affect Velocity itself
My guess are either creating several systems WithNone and WithAll for this extra component
or maybe there's some other solution?
I doubt checking entities for components during job is any good
why would velocity modifier not affect velocity???
It's just example
So you funnel everything into ECS physics? No MB physics at all?
I think maybe you want write groups? https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/ecs_write_groups.html
That's kind of what it sounds like from your description
@zenith wyvern hybrid is a bit misused by unity imo, it can refer to anything that uses unityengine based things(ie hybridrenderer uses meshes and materials), as well as when people refer to actual monobehaviour components on entities
It lets you override certain systems based on extra components
ecs is very use case driven and logic defined. if it's a bad example, then solutions for it could differ extremely and the best solution is not even among them
yeah, the hybrid term is very vague with the Hybrid Renderer. Not sure why it's even called HR when it's pure ECS
True, kind of pointless to argue over the semantics of what hybrid even means at this point
I understand it as MB + ECS
Unity has kind of mashed the meaning into nothingness all on their own
@viral sonnet yeah but tbh Id like to ditch it because it makes pooling & saving more complicated(for my inferior brain)
hybrid on unity's definition refers to unity engine stuff and dots. not monobehaviour components on entities
im kind of glad that class based component data still serialize decently w/ subscenes ๐ค
because it doesn't use pure ecs / dots
actually that term has been nebulous from the start, unity were referring to it when the initial proxy components existed
so it kinda stuck with the community I guess
And then they were seemingly using "pure dots" as an actual thing, which is no longer an actual thing as far as they are concerned
monobehaviour components on entities is deprecated anyways
not currently unfortunately
and im just explaining how its definition has been used and varies by person to person @haughty rampart
and i stated unity's latest definition of hybrid workflow
my comments werent directed at you when I mentioned this previously
i'm pretty sure only 'hybridcomponents' are deprecated
not actually attaching components to entities
I don't get it, it updates so fast, it's actually inactive most of frames?
I have 2000 objects, I kind of assume that there's should be at least 1 per frame that gets removed
yeah, that's what I mean by "too fast"
still "not run" with 20k
funny, I really think it's a bug
Impossible that most of frames are without queries
put a Debug.Break or Log in the system. You will not catch it in the Entity Debugger
not trying to take a dig at you more a frustration at work but, why do devs always jump to, there's a bug in the library/compiler first instead of a bug in their own code ๐
nature of most ppl I guess xD
I know exactly that it actually runs, because if I turn system off, no entities get destroyed
it's just funny it's not getting caught by debugger
yeah but if it only runs 1/30 frames you'll never see it here
he's suggesting a debug to show how often it runs
ah
if you debug the framecount you'll know exactly the frames it runs
Is it safe to call debug from different threads?
exactly, it's impossible to catch 1 frame systems in the debugger unless you step through every frame and look for it
debug.log yes
just to follow up this, you can subscribe to either the main thread only or the threaded version
Application.logMessageReceived
Application.logMessageReceivedThreaded
How to get some kind of unique per frame value?
why is it not being called from main thread
I'll just assume it's the way it is, because it's threaded
you're testing how often the system runs
all you care about is the log in the systemUpdate method
not in your job
but isn't it called every frame anyway?
OnUpdate is only run if there is a matching query in the system
if there is no matching query, it shows not run
i.e. your above picture
if its run, it will always have a time
but how does it know if query is matching before running OnUpdate()?
it's all handled in systembase
{
var state = CheckedState();
#if ENABLE_PROFILER
using (state->m_ProfilerMarker.Auto())
#endif
{
state->BeforeUpdateResetRunTracker();
if (Enabled && ShouldRunSystem())
{
if (!state->PreviouslyEnabled)
{
state->PreviouslyEnabled = true;
OnStartRunning();
}
state->BeforeOnUpdate();
var world = World.Unmanaged;
var oldExecutingSystem = world.ExecutingSystem;
world.ExecutingSystem = state->m_Handle;
try
{
OnUpdate();```
uuugh, I wonder how it'll interact with Harmony patches
a lot of stuff goes on before OnUpdate is called
if you want the system to always update regardless of query, add [AlwaysUpdateSystem] attribute
well, system runs about 40 frames per second
hm, why is Convert To Entity with "Convert and Inject GO" not intended for childs for a GO in normal scene. How should this be handled?
seems I've to use manual conversion instead
(there is a chance ConvertToEntity does not exist in 0.5; been deprecated for 2 years)
(i should actually go ask unity this)
i would use subscenes but MBs get removed in builds
MBs?
MonoBehaviours
consider how much you like performance, surprised you use MB ๐ง
demo usage ๐ I want to support MB spellcasters
for animation, movement, etc...
is there any intended way currently for GO conversion other than subscenes?
Is it possible to have a Singleton accessed by many JobComponentSystems and SystemBases?
For example, I want to apply damage to entities
no
I think writing one damage apply ( armor/shields/etc adjustments)
So I just have to make hacky ugly bad style screw design patterns for now
I can make ugly code if that ain't available now
Is it possible to have a Singleton accessed by many JobComponentSystems and SystemBases?
For example, I want to apply damage to entities
Sorry I'm not seeing the connection between your question and example. [You can use GetSingleton in any system, though if you ever edit this you should use GetSingletonEntity and get the actual component in the job]
huh, so when considering MBs are not saved in subscenes, there's no real intended way for hybrid then other than the soonish deprecated ConvertToEntity. Man ... haha
how are gameobjects not saved (via hybrid components which is now deprecated but we can come back to that)
lights etc on gameobjects in subscenes etc load in builds
personally my approach @viral sonnet would not to be to convert the gameobject part at all
There's ConvertToEntity scripts
just build a gameobject view data base and put a component/key on the entity in the subscene
and instantiate/match them at runtime
So you gave me two different conflicting answers. My question is: If I have a function that applies damage to an entity: Do I need to rewrite it in every single jobComponentsystem and SystemBase file I make, or can I make a global method all jobComponentSystems and SystemBases can reference it(proper software architecture).
thats been deprecated for 2 years
attached MBs on subscene GOs were not loaded. I have not tested adding them manually
oh you mean function. i would not call a function a singleton
It's all I used up until I stopped developing in Unity, which was still the latest version. Subscenes are not well documented enough
they will not be loaded unless you call AddHybridComponent<YOURCOMPONENT>
but this is deprecated in 0.5
anything not marked as a hybrid component is stripped in subscene
yeah, guess this is the way forward. thanks, gonna stick to this. I don't like the other way around anyway ๐
(but again not a good idea going forward ๐ but it should still work in 0.5, but removed in 1.0)
I gave up making subscenes work yesterday due to no one knowing what was going on. I pull all my scenes in the main scene and enable/disable em now for a hack.
the best approach if your logic is complicated is usually to write your logic in a struct and pass that struct to both jobs
ty tertle
a struct?
will do
This will save me hundreds of hours over the next few years.
{
public BufferFromEntity<DamageInstance> DamageInstances;
public void DealDamage(Entity entity, int damage)
{
DamageInstance[entity].Add(new DamageInstance {Value = damage});
}
}```
you can pass this struct to multiple jobs etc
I know how to use a struct ๐
You're a boss tho
for bustin out straight 'zample code!
Remember, track me down at paradise city and get your greenbacks in a manilla gorilla envelope
i'm not always the best at explaining things and personally find code examples much easier to understand
100% yah
I understood you with struct
I was just impressed
you went full on example
Thats what a boss does
You a boss
Do we have any info how the new approach in 0.5 looks like?
hybrid is just being marked as internal only pretty much
sounds like issues supporting it except for specific components
they say to just use managed component data
but yeah i'm not sure if there's anything in place to handle the gameobject lifecycle
your game doesn't run on the HR, right? How are you handling this right now?
my personal game or at work?
at work
and your personal one uses HR?
yeah i only have 2 gameobjects
a direction light
and a UIDocument script
so you're using the animations package successfully?
haha no, my game currently has no animations. that's future package update problem
i've intentionally just not worked on that area at all
hehe, i see. I'm at a point where I got to get some animations though. This part sucks ass
sorry i kind of lied
i do have idle animations playing through animation package but that's about it
but yeah most of the code i write myself is more libraries, i don't care that much about actual game implementation
yah tertle buddy, worked
i'm a bit weird, i'm all about game architecture
I'm launching my MMO today or tomorrow
I'm beyond weird then
Cuz I'm not just architecture
I'm about it looking pretty
and speed
People know me as one of the fastest prototypers out there
yet my architecture is super boss too
You can tell the difference between a software architect and a software maker
the larger the project, the more it is easy to expand for an architect
as I'm building an asset foremost, I'm puzzled how to deal with this. Investing into a deprecated workflow makes no sense but not sure how far the animations package is off. from the blog post it doesn't look to good when they imply we are still able to use GOs
for a regular software engineeer/coder, often stuff falls apart like a house of cards built on a tower of jello
I need a moment, I'm dorking out how easy it was to solve this, okay, back to the grind. YOu can watch the live stream of me dev here: https://www.youtube.com/watch?v=qeBptUN1vSY
MMORPG coming out: www.starfightergeneral.com
Soul gamer, 150,000 hrs played
CrazyJim Aka GoodNewsJim banned 2x on twitch for calling terrorists and drug cartels evil.
hmm, how New Input System is supposed to interact with DOTS?
sampling in main thread and writing to structs
@viral sonnet im sorta at the verge of canning my old mecanim characters in favor of using the dots anim package, depending on what you specifically need for animation it may already suit your needs. currently events dont exist, and not sure if statemachines exist either.
public class InputDefault : IComponentData
{
public InputActionAsset Asset;
public InputActionReference CursorPosition;
public InputActionReference Move;
public InputActionReference PrimaryAction;
public InputActionReference SecondaryAction;
public InputActionReference CameraTurbo;
public InputActionReference CameraMove;
public InputActionReference CameraMoveY;
public InputActionReference CameraLook;
public InputActionReference CameraLookMouseEnable;
public InputActionReference CameraLookController;
public InputActionReference CameraZoom;
}```
the reference component is created in a subscene
originally i sampled on update but i decided to stick with the intended inputsystem event approach
The best way to do it
is tokeep your old player controller for gameobjects
then just load in the entity pos/rot/velocity, map to gameobject, controil game object with old player controller, then set rot/velocity/etc (not position)
Then what happens is
You can have your old gameobject style game with its hundreds of levels or whatever
and start adding new levels
and still have your player act normal
just make new enmies
its the proper software architecture, like no one knows it
I posted the holy grail video about this, and no one seemed to care
if anyone wants me to drop it, its an hour long video saying the same thing over and over in different ways
I'll conciseify it later once my mmo is outs oon
If you understand this video, you do not need to make new games from scratch. You can simply use your gameobject games and entityfy new levels with em. I apologize for this video being extremely rambling on, but I was also doing some dev and I plan on getting you a great video soon, but to some, this will be a God send Holy Grail of Dots ECS ...
For people who dork out over software architecture and wish Dots/ECS could be used in everyone's old GameObject games... You'll be stoked.
DOTS/ECS is marketted too hard towards making entirely new games.
Its like no one figured this out but me.
my controversial take is a bit different - you shouldn't use entities if you're writing a hybrid game
just use monobehaviours and existing well developed libraries and write jobs for critical code
By saying this, you do not know what I present
The only monobehavior in this is the playercontroller
i'm basing this off having actually built a hybrid game released it
Yes
and it was a huge mistake for my company to rewrite their game with entities
You don't get it man...
Everyone thinks that
Because they didn't watch this video
I actually have invented an ENTIRELY NEW thing
I don't really get what's going on in OnUpdate besides putting some data in singletons?
Also what are these types "InputCommon", "InputCamera"...?
Literally, no one on the planet, but me posted this.
So, yes, its a huge headache
If you try any way but this way, I know this.
This is the Holy Grail of hybrid game solutions.
The gist of it is what Enzi said. You read your input in OnUpdate (on the main thread) and then run your jobs/update your entities according to that input
That's the input result that various system use
{
/// <summary> Point in screen space. Screenspace is defined in pixels. The bottom-left is (0,0); the right-top is (pixelWidth,pixelHeight). </summary>
public float2 ScreenPoint;
/// <summary> Point in viewport space. Viewport space is normalized. The bottom-left is (0,0); the top-right is (1,1). </summary>
public float2 ViewPoint;
/// <summary> Is the cursor currently inside the view port. </summary>
public bool InViewPort;
/// <summary> A ray going from camera through the current <see cref="ScreenPoint"/> using <see cref="Camera.ScreenPointToRay(Vector3)"/>. </summary>
/// <remarks> Displacement is set as a unit vector. </remarks>
public Ray Ray;
public bool InputOverUI; // TODO
public ButtonState PrimaryAction;
public ButtonState SecondaryAction;
}```
wait this one is probably an easier example
{
public float2 Move;
}```
Move is just say controller stick, or wasd
any system can read it, player controller, camera controller, map controller etc whatever
depending on state of your game
any github, repo link?
see you're missing my point. i don't think hybrid solutions should exist
so, basically when any move button is pressed, you assign data to singleton and once it's not you assign it to 0,0
and all your Character Controller systems are simply accessing that singleton?
pretty much. you can just poll it on OnUpdate instead of using events (which I suspect most people do)
Concept is this: Code your playerController once in monobehavior. Map the entity to the gameobject not being rendered or collision detection. Then take in position/rotation/velocity from Entity at start, processess player controller, output rotation and velocity to entity after.
I'm with you but this is more of a symptom that we are even talking about hybrid. Unless Unity doesn't reach feature parity it'll be relevant for a long time ๐ฆ
So as you change the player controller, it changes it for your old GameObject Only maps and your future Entity Only maps later.
You code one and done.
i hate to say it, but that sounds like the default (and only) hybrid approach gnj
I actually now wonder if it is, kek
yeah, we are doing this for years ๐
ALlthought seems like it's just fear out of nowhere
i'm not seeing what's special about this?
so you need to be careful
You can watch the video, I explain it for like 45 minutes straight. This is very very very huge for anyone who has an old game they want new levels with entities, but don't want to rewrite their player controller: https://www.youtube.com/watch?v=GIEV14B20Pc&t=780s
If you understand this video, you do not need to make new games from scratch. You can simply use your gameobject games and entityfy new levels with em. I apologize for this video being extremely rambling on, but I was also doing some dev and I plan on getting you a great video soon, but to some, this will be a God send Holy Grail of Dots ECS ...
GetSingleton actually creates a sync point on writers
GetSingletonEntity
then using GetComponent in job avoids this sync
oh, so it might ruin perfomance by overusing?
going back to coding.
depends what your singleton depends on. if you're sycning on an input call it's hardly going to stall anything. but if you say were writing your terrain gen to a singleton then did a get on it, could stall quite bad
you mean size of data matter in this case?
no, the logic you're executing on your writes
say you're generating a giant density field and then write it to a singleton, if you call getsingleton on onupdate you need to wait for that field to be finished generating
if you getsingletonentity and then do the get in the job, no main thread sync, the job will be scheduled to after the density field generation occurs
most of the time it doesn't matter, it's just that a lot of people overlook getsingleton is really just a entitymanager.getcomponent
so same sync rules apply
I'd recommend not using Singleton entities unless for a very specific reason. The alternative is a public field in your system which you can access from other systems too
It's fine as long as you're aware of how your data is being accessed
tertle's 4th rule of entities development. Systems should never access other systems
the beauty of ECS is the decoupling of code
It's literally the same as writing a query for a component
Except you know, only on the main thread, unless you use the CDFE like tertle said
have you more of these rules?
they're all in my head ^_^'
:<
you should avoid single component singletons due to wasted chunks
And the second last rule
it's an infinite list that keeps expanding the more i read code people write
i'm struggling with ECS hard, i suppose to not have references, so everything should be processed by "ticket"/event systems?
events are controversial and can be abused really easily
I guess we should be worried if any of our code inspires one of these rules
like "AttackComponent" with attacker and target?
events really depend on what scalability you want to achieve
(also a lot of the time are just abused and used poorly)
so how I should manage finding and attacking other units?
anything else I came with is huge system with multiple jobs, like 1 job looks for nearby enemies and second one attack with intermediate data between with whatever form I need
so result of that system would need one structural change at the end
so result of that system would need one structural change at the end
Why
structural changes are not good
sorry my bad, not structural change but ECB set component
not ideal (depending on what you're doing) but much less bad
what in particular are you struggling to implement? Targeting? Dealing damage?
you might want to look into alternatives to handle this like NativeStream for example. 1 frame data that just gets chained from one job to another is not fit for entities
connecting those, every system is trivial but I struggle when I need one system to select something and next system doing something based on that
without going into like, best practices or optimal performance ideas etc
would you just not have a basic 'Target' Component which simply has a reference to the entity your targeting
then the attack system can attack it, damage it etc
but it uses entity refereence
and it needs a check
seems like something I shouldn't do
often you can't linearize non-linear algorithms
(side note, I consider the lack of safety on entity references to probably be the biggest flaw in entities atm)
by default with how they are used it's hugely problematic and performance limiting
i guess lifecycle management would be a better term
true
the push for static archetypes solves half the problem, but not the destroyed part
One of my more fun bugs was trying to track down an ecb accessing a destroyed entity. You get zero help at all
"The entity is destroyed". Thanks Unity. Thank you.
entity.Exists check is very inconsistent. it's not in ECB destroy but it's in HasComponent
i liked eizenhorn approach to avoid this and have adopted it
that's why I assume entity references shouldnt be used like that
and Exist uses EntityManager so it can't be bursted?
You can use BFE.Exists but it's very unintuitive
it cannot be parallelised*
which is basically add this
[UpdateInGroup(typeof(SimulationSystemGroup), OrderLast = true)]
public class EndSimulationDestroyCommandBufferSystem : EntityCommandBufferSystem
{
}```
And only this EntityCommandBufferSystem is allowed to be used for destroy (and no other commands are allowed in this)
What's the Eizenhorn approeach?
CDFE HasComponent can be used in burst jobs
this way a destroy on an ECB can never break another ECB
why not just use EndSimulationEntityCommandBufferSystem?
because something may be writing to it
System1 calls ecb.Destroy(entity)
System2 calls ecb.AddComponent(entity)
game crashes
by enforcing all your destroys occur after any other ecb calls, you don't need to worry about rare timing crashes
hm, surprised I havent actually run into this yet
is there any way to have an array beside a dynamic buffer?
It only happened to me when I was trying to do parenting between entities. I stopped doing that and never looked back
you can attach FixedList to components
Can't you just make your own system groups?
but it's maxed at 4098
so you can put it's in correct order
You can use unsafe lists, if you're careful about disposing them
and put all your destroy system in it?
trust me, you will fuck up eventually once you are in the 100s of systems
and then you luanch your game, start getting random crash reports with 0 debugging info
and spend weeks trying to track down a super rare timing bug
isn't groupping helps with that tho?
I really cannot stress how little info unity gives you when you run into this
It's literally just 'The entity was destroyed'
No info where it came from, nothing
it's even worse in builds @zenith wyvern
can't wait for new update, maybe it will help
it just crashes with a really bad stack
or does it on the wrong memory then crashes the next frame
or at a completely random time because you've done something bad and corrupted your entity component store
another fun little refactor to do while waiting for 0.50
so, entity references are good?
i had this plaguing me for the last 3 days ๐ฅฒ
Sometimes you surely need one entity to interact with another
i haven't implemented it, but my current project i'm looking at having only 1 shared entity reference (Target) then a buffer with any extra secondary references that all systems use
so the system that has a creature attack something uses the same target component as another system that the creature is mining wood
and then simply validating the target component at the start of each frame and then avoiding all checks on it
as a way to do this performantly and safely
again - not implemented yet, theory in my head
I can't belive how much structural changes costs, it would be fairly easy to do this just by adding new component
(but conceptionally it works really well with my AI)
at the end of the day @hot basin what's your scale and target hardware
You can use dynamic buffers and change detection as well
if you're only making a basic game, few hundred thousand entities and only doing a few dozen archetype changes a frame
it doesn't matter if you're not targetting like xbox one/ps4
what about mobile?
you mentioned consoles, I just think whether mobile have anything related to that statement too
but i don't do mobile development so i haven't experimented with it
Is there a way to have a local copy of the DOTS packages so I don't have to download them each time I start a new project?
whereas my life at work atm is making ps4/xbox one work
Do dots projects even export to mobile?
all packages are cached
my proportions are switched, I probably end up with couple thousands of units but I think all of them could change archetype in a frame
I can't seem to install them from the cache though
Besides megacity showcase was presented on iphone
appdata Local\Unity\cache\packages\packages.unity.com
all your package cache exists there
I think TINY does
Have they mentioned tiny at all in the recent news push?
I haven't really been following it
nope
Thanks
There must be a lot of stories about all the project starts and stops that have happened around dots. Poor tiny
it had strange niche
Playable ads
When will it reach beta?
I looked it up only to check sprite renderer integration with DOTS
Making dots games that worked in a browser could be a massive benefit, for things like game jams even
But yeah, seems like it never got off the ground...again
I actually need to use it.
Tiny was interesting since it used bgfx to handle the rendering and miniaudio to handle the audio playback ๐ค
do you guys use hybrid renderer?
In my game I kind of did. It was just a single hybrid entity with a big mesh that I redrew every frame
Not really typical usage I guess
I was using it until 2021 got some shader features I needed
and I ended up with my own GPU skinning with GPU animation instancing
I wonder what UT will offer in this area
yes, though i feel trapped with 2020 and lack of point light support in urp
in the end I even write my own mechanim-like animation graph as animator is slow as hell
hybrid with 2021 and urp deferred was working fine until like b12 or something, and then of course, the stay on 2020 announcement
I mean I wonder if I'll benefit from this because UT seems to be not interested with this area much
Are the SRPs actually in a usable place now? I feel like they were in limbo for years
i really dont know what their plans are, but that recent post did mention they wanted to make the sample projects showcasing specific use cases for 1.0, nordeus crowd sim was one of them so I have to imagine they might be considering updating that gpu animation package?
i'm hoping the animation package is getting some love
or maybe it will just be an official example showcasing unofficial workflows to be forgotten to the wind like occlusion probes lol
considering they said the animation team was basically dropping stuff in 2021 for it ๐
if we don't see something in 0.5 going to be massively disappointed
animations by far the thing that's always held pure implementations back
by dropping stuff you mean just no public updates statement?
that's why I end up with my implementation but I had fairly easy case
honestly i know a lot about future dots plans... except animations
black box on that one
what is even animation? in terms of data
main thing I'm waiting for is enable/disable of components
keep waiting ๐
but seems it will not be in 0.50
i don't understand how unity didn't realize this concept was hugely problematic from the start
in my case is position of bones in time
there are so many issues with it
so basically it's just arrays of transforms?
yep
number of bones * number of frames big
well, I can see how it can be done directly through code then
@rotund token what specifically do you have issue with the animation package atm? scalability or something else?
I probably could minimize it to keyframes and blend, but why bother
after all, everything will just come down to different matrix4x4 for mesh
usability
like lack of ui? ๐
i want designers/artists to be able to use this package, not programmers
oh yeah, I didn't think of it
well at least that definitely seemed like it was around the corner
I think I know, Unity doesn't make games
like Epic does
i think fundamentally the concept of enable/disable on every component is potentially flawed
and should be an optional interface
90% of my components i'm never going to enable/disable
yeah I think the same, probably should be avaiable only for tags
so it could potentially be doing millions of checks a frame for something that is not needed
(that said, who knows how they've implemented it)
and potentially tags shouldn't be counted in archetypes
im not sold on the idea that component sets should be relatively static
I think they should and tags should define it's behaviour
i.e. I have unit, ad that unit will be doing same few things over and over so I would like to have static data and something to tell me it's behaviour
isn't it going against data composition pattern?
you either have data to use or you don't
i just think for certain procedural games, changing components at runtime just seems like a more ideal workflow than having everything known beforehand
you shouldn't have any data you don't use
you can use bitmasks like Jonathan said somewhere in the forum
my data is not where i want it to be anymore
for simd
(this is actually the other flaw on enable/disable components, it breaks this)
and then they talk about optimizing this by grouping disabled components
at which point, you're making structural changes anyway ๐ค
yeah, you're right
hence i have so many questions
why avoid structural changes tho?
Is the enable disable components tied to the networking in ECS
structural changes kill performance
bookkeeping is costly
it limits your working entity count from 100,000s to 1000s
cause somewhere I read that you can't change components on networked entities
yeah netcode requires a base static ghost archetypes
you can add/remove components (that aren't ghost components)
but these won't be serialized
That is too bad. Seems to break the point of ECS
but bitmasks don't make them and filtering only meas that you use entities at 0 or 1 value dependant of you want them or not
I feel like the actual reason behind this problem might be actually unrelated to structural changes
everything else works as always
if your data is
enabled, disabled, enabled, disable and you're only filtering on bitmask then yes you're not making structural changes
but your data is now not simd friendly
unity have publicaly stated they are looking at grouping enabled/disabled components so they would restructure your chunk to
enabled, enabled, disabled, disabled
so now your data is friendly
but as far as I know this is not a structural change but part of the bookkeeping
I mean that copying entities between chunks is not nessesary
thats really all adding/removing components is doing if you are swapping between 2 chunks
it's the exact same cost as long as you do not need to create new chunks (which does happen a lot)
but doesn't need those checks
just memcopy inside chunk
but yeah that needs a lot more than a bitmask
but you just know people are going to abuse it and make 1000s of enable/disables a frame
but it's missing the point if it will cost alot
nearly the entire cost of a structural change
is the memcpy
ok sorry im saying this wrong
i'm saying, if the chunk already exists
its nearly just as fast to do it
Doesn't a structural change force all jobs to complete immediately
the big cost of structural changes is it creates huge amounts of new archetypes and chunks
if you managed to organize your code in a way that you only made structural changes that moved components between existing chunks, you could scale this without too many issues
there should be a way to tell "keep this chunk" in common archetype case
you can probably tell ahead of time which archetypes will be used
anyway way off topic the point was just that, enable/disable components are way more complicated than unity thought and that's why it's taken 18months and counting instead of the original 3 week estimate
but now it seems that enable/disable components as a thing could be a wrong approach
in theory it's very ideal right
but why, you are doing in best case scenario same work as structural changes
with a lot of additional work
stops archetype explosion
side note, the more archetypes you have the slower your queries become which effectively slows down all your systems
though i believe there is some major improvements to this in 0.5
with system queries caching the chunks
I hope it brings something good
way back when i joined the company i work at now, they just did the classic approach of constantly add/removing components
samples included
ended up with 100k+ archetypes and counting
as there is not much of learning material now
the entity queries became incredibly slow
something like 6ms/frame was just getting entities for queries
(hmm may be slightly miss-remembering, that 6ms might have been when i pushed it over 1mill archetypes. i think it was closer to 1-2ms actually)
6ms? and no one did anything with it?
but anyway, it was a measurable performance problem
oh over time i managed to cull most of archetype changes down
still more than we'd like
i think we need to increase archetype space by 1.5x
unity only allows between 8-12k archetypes before running out of memory
how do you count how many archetypes exist?
oh nice window
so i can quickly load up the source code and tell you!
EntityManager.GetAllArchetypes()
ahh cool
ui toolkit?
yep
i write all my debug code so it can run in development builds
and this toolbar controls it all
scales the camera etc to not obstruct view (can be minimized)
so it's like SR debugger but for DOTS?
technically its not just for dots
do you instantiate different view for non dots project?
i don't do non dots projects
is there a company that do only DOTS?
nice! best workplace ever
but yeah, you just create a system, inherit from ToolbarGroupSystem, point to a Visual element and it's basically all done
its nice in the sense you can put your system in client or server
and it will only show if the server/client world runs etc
and if you shut it down removes from the bar
all the good stuff
(i love debugging tools)
i just like writing tools, frameworks/libraries that makes other developers/designers/artists life easier
i don't care so much about writing say, a complex level editor
i'm just trying to make this library the most developer friendly experience you could imagine
maximum workflow
nice catchphrase ๐
that physics debug is beautiful
you actually have no idea but i don't want to brag >_>
current physics debug is just horrid, no sorting hurts my brain
yeah it really bothers me the unity physics debugger uses gizmos
and i want something i can use in development builds
as much as i try to discourage it, management and QA just love testing in builds instead of editor ๐
then how do you draw your debug?
but what you call to draw?
yeah
RenderPipelineManager.endCameraRendering += this.RenderPipelineManagerOnendCameraRendering;```
depending whether its using new SRP or old pipeline
i just inject it into the render pipeline with a commandbuffer
{
this.commandBuffer.Clear();
this.BuildFrame(camera, this.commandBuffer);
context.ExecuteCommandBuffer(this.commandBuffer);
context.Submit();
}
what can i say, i'm a sucker for auto generated naming ๐
pretty much
strange that IDE don't scream at you
the ide named this when i hit auto generate method
i just forgot to rename it
thank for explanation! it's quicker than gizmos?
how many archetypes does your current(steam) project use approx? just tested for my fps, 680ish in a small test scene
i havent checked in like 6 months since we havent had issues
but last i looked between 6-12k
and can you draw a line?
didnt you say you run out of memory at 12k?
we edited the package to increase what's allowed
ah
we were hitting 30k for ages at a somewhat acceptable amount
but yeah slowly got it down
i think we're still at 3x memory allowed for it
i think we only need 1.5x
but rather burn 20MB of memory than crash
if someone sits down and plays a 20 hour session
i currently support these types
now I'm more interested in your rules ๐ should make a forum post for it
i've been meaning to expand this drawing library a bit and support more types and features
been sitting idle for probably a year now
ive also been meaning to make it public
but it currently uses just a tiny snippet of proprietary code i need to rewrite
yeah sadly you can't share much when made in the company
its not done in company
all this is my own code
i share a lot of my code with my company, not the other way around ๐
for the record, aron granberg has a library that's more polished that lets you do a similar thing
https://assetstore.unity.com/packages/tools/gui/aline-162772
I made that mistake with my renderer
(im not as much of a fan of the implementation from an entities perspective but it works in burst)
(it's included in a* pathfinding if you own a license)
i highly recommend a burst friendly drawing library, either aron or write your own. i don't think we've had a more useful debugging tool than being able to draw out data from burst jobs
I'm hard case of "I'll make it myself" and made a HPA pathfinding myself
drawing out pathfinding has been one of our best uses for it ๐
yeah aline is quite handy @hot basin
oh yeah here you go, aline has a benchmark which would pretty much match what im doing
comparing gizmos and yeah its legit this different
would buy a native ecs 3d pathfinding project so fast if aron put one out. or anyone really
i feel like if i wasn't so lazy, i'd have so many assets i could sell
because i have exactly that
frywallet.gif ๐
i ported recast to dots
then added pathfinding to it
i also have a version before this that used unitys navmesh
pretty sure i posted pictures of that on the forum like 18months ago
i added optimal reciprocal collsion avoidance to it
which runs amazing well, 200k entities at above 60fps and one day i'll solve my spatial query limitation and double that
so yeah, i have all this sort of jazz
did you publish it somewhere on git?
nope ๐ฆ
i don't really like publishing stuff until i consider it production ready
or simple enough it doesn't matter
good approach
how did you avoidance in parallel?
is that ORCA made with this in mind?
that paper i linked supports it
the whole concept is each actor does half the work without communication
oh nice! saving it for later
oh I know what should I ask
how do you keep you map/graph for pathfinding
I ended up with field in the system
for my navmesh?
but I assume that is wrong approach
as i ported recast it's basically all c++ like code
I mean between frames
oh
dont have my project open atm and its been a few months but from memory it's likely just stored as a pointer on the system (or on a singleton cant remember)
dynamic buffer with nodes seems wrong but it's the only way besides unsafe magic that will work
oh yeah it's stored so i support multiple navmesh worlds
for different actor types right
you might not like this but, this is how it's stored on a component
{
private readonly NativeArrayProxy<NavMeshWorld> worlds;
[NativeDisableUnsafePtrRestriction]
private readonly AtomicSafetyManager* safetyManager;
internal NavMeshWorldsProxy(NavMeshWorlds world, SharedSafety sharedSafety)
{
this.worlds = new NativeArrayProxy<NavMeshWorld>(world.Worlds);
this.safetyManager = sharedSafety.SafetyManager;
}
public NavMeshWorlds ToNavMeshWorld()
{
return new NavMeshWorlds { Worlds = this.worlds.ToArray(this.safetyManager) };
}
}```
i have this concept of native container proxies
basically it lets me store native arrays on components
then rebuilds the safety in the system that needs it
I don't speak in unsafe ๐ sorry
so yeah, to answer the question
it's NativeArray<NavMeshWorld>
stored on a singleton
singleton monobehaviour?
so it's unsafe ptr to native array?
not exactly
so these native proxies are actually a concept i kind of yoinked from the physics package
any other system simply goes GetSingleton<NavMeshWorldsProxy>().ToNavMeshWorld()
which is basically just a wrapper for NativeArray<NavMeshWorld>
why is RaycastInput so damn weird? it only has start/end ??
read the source, it actually tells you why
lol google sent me to an old doc haha
so raycastinput just converts to a ray internally for use
and ray says this
/// This struct captures the information needed for ray casting.
/// It is technically not a Ray as it includes a length.
/// This is to avoid performance issues with infinite length Rays.
/// </summary>
public struct Ray```
unless your question was you wanted other features?
not the fact it uses start/end
instead of origin/direction
huh, i don't have these code comments
you can't see the actual source?
if not time for a new ide ๐
because unity does an overall exceptional job documenting the source code in their dots packages
no, that's weird. i'm using VS 2022
oh yeah classic
VS does not show package documentation at least not by default
right, that's annoying. yeah unity code comments are stellar
i believe there might be a way to do it, but don't ask me
otherwise resharper plugin lets you see proper source
or our whole dev team has pretty much switched to rider because of dots development
overall just a superior unity ide imo but dont want to start anything ๐
my company uses msdn action pack. otherwise I'd be on rider too probably
what is this private readonly NativeArrayProxy<NavMeshWorld> worlds;
everyone says how great it is
yeah I'm also using rider
anyway, thanks tertle, that has answered my question
and led me to another task because having no comments sucks
this actually exists, for the most part, in the Unity.Physics library
com.unity.physics@0.6.0-preview.3\Unity.Physics\ECS\Base\Components\PhysicsComponents.cs
(avoid me posting a huge amount of source)
i have my own copy and have expanded it to other native containers
but the concept is based off this file
line 176
the tldr is it's just the nativearray ptr + length
the other part
com.unity.physics@0.6.0-preview.3\Unity.Physics\Base\Containers\AtomicSafetyManager.cs
is what lets you regenerate the safety handle to allow the native array to work safely in different systems
in collections sometime after 1.1 when they remove dispose sentinal (1.1 is already out, it has a conditional wrapping of dispose sentinels to allow removal)
you should be able to simply attach native containers to components
and this won't be needed
there's some stuff about this i can't talk about so i'll leave it at that
but collections 1.1 changelog has
Added
REMOVE_DISPOSE_SENTINEL ifdefs in all containers for future removal of DisposeSentinel.```
DisposeSentinel is the class inside native containers that stop them being unmanaged and going on components
1+1=?
Seems like it would have the same restrictions as unsafe containers no?
Just faster I guess
except you know, safe ๐
huh, is this not going completely against entities? I mean, I welcome the change
Oh like, the safety is going to be handled in a way other than disposesentinal?
Huh
dispose sentinel isn't for safety
it's for memory leak detection
AtomicSafetyHandle is for safety and its already unmanaged
i actually have a collection of semi safe containers
containers with AtomicSafetyHandle but without dispose sentinal
I guess I thought safety was about memory leaks
is collection package fixed?
with entities? no
you still need 0.15
i'm assuming entities 0.5 will use new collections
(on the memory tracking, i actually dont know what magic unity is going to use to track leaks. using a class was such an easy approach)
oh collections are released now
(i suspect it'll have something to do with their new memory management)
anyway i've said way too much today and done way too little coding
be more intermittent
but latest jobs + collections works?
if you aren't using entities
if you were doing a monobehaviour project with jobs for specific optimization then yes its considered released
in most projects in my company I don't
latest collections totally work with latest entities
i'm getting errors
anyone using github copilot? when it works, its kinda creepy how well it works
made a simple ascii cube unwrapped to faces in comments with numbers at each vertex and it was able to figure it out each face after the first
its also very handy for writing non lambda jobs and all the boilerplate code
sounds cool! the code completion from vs2022 is also pretty great.
copilot seems way more advanced
funnily enough i found the code completion for vscode to be pretty poor
vscode is shit tier ... lol
the only redeeming factor is that it's free
writing python and setting it up was pretty cool but for c# and bigger projects... ooff
yeah its crazy(and also super dumb at times), but for some things you can prime it, like add a comment of your intended functions purpose and it will spit out something that can occasionally be on the money
Does it do any DOTS stuff?
the first good auto completion I saw was in vs2022. it's often totally on point.
yeah it handles dots stuff
like setting all the variables in jobs was pretty much just tabbing though and auto completing ๐
maybe vs has way improved since but i find even rider isnt that great at it for jobs
vs2022 has improved a LOT
kind of welcoming because I use it for work and intellisense was degrading to something really useless over the years
either it was slow or had wrong suggestions
really interesting what AI has brought to the table in terms of code completion
I mean we write similar stuff all the time
to have that shared now in a model and the implications of how that will look in a few years is pretty mind boggling
especially for such a large repo site like github
on the other hand, programmers have cried when new blood was using intellisense. can't think of how we will think when fresh programmers use such forms of auto completion ... haha
[old voice] back then we still had to write line per line
yeah, at times it feels like star trek holodeck command ish, "give me something that can handle player movement", boom
before or after dots ๐
dayuuum
How is it even possible to reach mil archetypes
Or dots saves literally all of them?
Even those that aren't used in jobs?
any archetype that ever exists
exists forever
nCr explodes pretty fast
you have 50 components, and say you have 10 components per entity
this gives a potential archetype count of 10,272,278,170
how do you reach that many?
Uugh
add/remove them in random ways
Why not just have registry of what archetypes should be saved
say you have component ABCD
you have an entity with component A,
you add B, now you have archetypes A, AB
you add C, now you have archetypes, A, AB, ABC
now say you remove components B then C
in that order
you now have A, AB, ABC, AC
Yeah, I get how it grows exponentially
if you removed them in C B then you'd still have the original A, AB, ABC only
chunks are never destroyed
only created
(its something that unity should/will probably address at some point)
ALSO something people don't realize is for every archetype you create
you actually create 3
say you have 1 component, A so 1 archetype
unity also Creates A + Disable, A + Prefab
But why create some archetype you don't ever need in the first place?
i reduced our archetype count
from 30k
to 12k
removing 1 component
because this 1 component, pathfindingcomplete or something (was a long time ago)
was added at very random times/states
so it could be added to pretty much any archetype combo in the game
and then other components could be added or removed after
Sounds just like architecture flaw
funny enough it only became an obvious issue
in entities 0.10 i think it was
before that unity didn't have fixed counts
So, about archetypes again
Does dots create them itself for every possible combinations
Or
any combination you that you create
Only when such combination occurred?
Like first entity created
Ok
That makes much more sense
But still it's useless waste
var entity = ecb.CreateEntity();
ecb.AddComponent<A>(entity);
ecb.AddComponent<B>(entity);
ecb.AddComponent<C>(entity);
ecb.AddComponent<D>(entity);
this is 4 archetypes
even if
A, AB, ABC never actually exists in update
because it exists for this fraction of time
(this is why instantiating with archetype is important - or better just using conversion. well apart from performance issues)
So
Once again, why not keep registry of entities you want to keep
Create all archetypes at the beginning
me or unity?
how can unity know what archetypes you need?
it only creates them as you request it
You tell it
well that's exactly what happens if you use conversion
So it only keeps archetypes that are used by jobs
Kind of force coder to put some code about archetypes in OnStart
Entities.TryAddNewArchetype(compA, compB)
And if code tries to access unregistered archetype either error it or create it dynamically
Nah
Just error it
Creating new archetype during job excecution seems bad
So, any of this makes sense?
Maybe I suggest it to unity or smth xD
what you're suggesting is just adding overhead to what it already does?
it's not like it creates random archetypes
it only creatures archetypes when you ask
You mean when you actually request it in job?
jobs have nothing to do with archetypes
I actually mean to not create archetypes just because entitiy with such archetype appeared
but an entity doesn't exist without an archetype?
But create archetypes because they were requested by code
an entity is just 2 integer values pointing to an archetype
Only 1 archetype?
each chunk has an archetype assigned, and inside the chunk is a collection of components
the entity index/version effectively just points to this position in memory
I thought archetypes are all possible combinations of components that existed
And entity knows about all of them
Or system somehow...
Well, then yeah
Just requires garbage collector for unused archetypes
You can make up an archetype and then spawn an entity of that type
I don't like the terminology of archetypes. Really hard to understand
There are the archetypes that exist as chunks and then there are templates that you use to create an entity which is then put into the chunk with all the rest of its kind
is UI toolkit working fine with entities?
I guess you'd need some kind of static object with UI component for it
Same deal as input - there's no built in interaction with dots. You have to do your ui stuff on the main thread and build the bridge between ui and dots yourself
Hey can anybody help me with this?
https://github.com/Unity-Technologies/DOTSSample/blob/5a8230597a8c4b999b278a63844c5238dacf51b6/Assets/Scripts/Game/Main/NetworkStatisticsClient.cs
I am trying to use and show the RTT in my game but its value is always zero!
So I have this prefab for player.
and by following guide I defined this HYBRID_ENTITIES_CAMERA_CONVERSION in build player settings
So what exactly is happening when I create this prefab as entitiy?
Gameplay wise camera just moves to position local to spawned Player
whats the issue @rustic rain ?
HYBRID_ENTITIES_CAMERA_CONVERSION just marks camera as a hybrid component
I'm trying to understand what is exactly happening, since MainCamera still exists
why game view is given to freshly created camera
and what would happen
if you create more cameras like this
Also, any tip where do you put your InputSystemGroup?
I tried this solution but
apparently Unity doesn't want me to use it
[UpdateBefore(typeof(FixedStepSimulationSystemGroup))]
[UpdateInGroup(typeof(InputSystemGroup))]
public class PlayerInputSystem : SystemBase
{
private InputActions input;
private float2 movementValue;
protected override void OnCreate()
{
RequireSingletonForUpdate<InputMovementComponent>();
}
protected override void OnStartRunning()
{
input = new InputActions();
input.Player.Movement.performed += context => movementValue = context.ReadValue<Vector2>();
input.Player.Movement.canceled += _ => movementValue = float2.zero;
input.Player.Enable();
}
protected override void OnStopRunning()
{
input.Player.Disable();
}
protected override void OnUpdate()
{
var inputMovement = GetSingleton<InputMovementComponent>();
inputMovement.value = movementValue;
}
}
What is wrong with my system
it doesn't appear in debugger
during runtime it looks like this
I have my group, but no system appears in it
I don't know but I just had an issue where my system had no reason to be updated, which was the issue. I don't know exactly how DOTS decide when to update and when not to, maybe it checks for both "ForEach" and "EntityQueries", read the components they look for and use that to run or skip the update ?
I say that because your update has no queries (not sure if GetSingleton count as one)
this example has no queries as well
also
it's not just not getting updating
it's literally not even showing up
I mean
I just created new system 0 changes xD
Maybe I needto declare some kind of work
job
You generally want the [AlwaysUpdateSystem] attribute for a system that's polling for input
Otherwise by default a system will not update unless it has a matching query (unless it has 0 queries)
InvalidOperationException: Cannot require EntityQuery for update on a system with AlwaysUpdateSystemAttribute
Unity.Entities.SystemState.RequireForUpdate (Unity.Entities.EntityQuery query) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/SystemState.cs:748)
Unity.Entities.SystemState.RequireSingletonForUpdate[T]```
oh wait
I forgot to remove some code I pasted for checking
As nibbler was guessing, the GetSingleton call creates an implicit query for your system
Meaning it doesnt have 0 queries meaning it won't update unless it matches
hmm
{
RequireSingletonForUpdate<InputMovementComponent>();
}
this might be the case
bruh
secret errors
yep
that was it
some class broke due to name change
thanks, actually helped with that info
Hmmm, is there a way to remove all components from entity?
this entity is created through conversion
which I don't really need in the first place
or maybe there's a way to create singletons without it?
Basically an entity to keep track of player input
for all other jobs
World.EntityManager.CreateEntity(ComponentType.ReadOnly<InputMovementComponent>());
ok, that was easier than I thought
Is there any way to ref component in my own code?
outside of job loop
I guess after creating component won't move anywhere, so I can just have memory pointer to it?
You store the entity and access the components through it with the entity manager
yeah, I kind of wanted to avoid that process and write directly to component
The "component" is just a piece of data in a chunk. A piece of data that might move in memory any time a structural change happens. The whole point of the entity/entity manager is to track that and provide access to it.
Essentially the entity is the "pointer"
Singletons move during structural changes too?
Yes, a "singleton" is just a wrapper around a query that points to a single entity
getting by value is fine then
I'm trying to think of a way to record input actions, that happen only once per button press
Or maybe I could just use direct reference to Input system
Track the input in OnUpdate, and go from there
and subscribe whatever other action system needs to performed event
yeah, I either need to make an 'Update' solution
or which seems to not work well with ecs
event system
I don't know what you mean by "update solution". What exactly are you trying to do that doesn't work with ecs?
by update I mean, just assigning value per frame
instead of just doing smth like this
input.Player.Spawn.performed += _ =>
{
};
Why wouldn't you be able to do that?
I am, but that would mean
I can only access that event in main thread
so I can't really schedule parallel jobs that depend on action inputs
OnUpdate() {
if( Input.Performed ) {
Entities.ForEach(Whatever) {
// Do Some crap as a result of input
}
}
}
How is that not doing what you just said?
The "subscroption" style of input polling is still doing the exact same thing. It's still doing an update every frame polling for your event, you just don't see it. I think Tertle posted an example of using the subscription style input events yesterday. I just use the polling method as it's easier for me to follow
yeah, but it's still doing it. So why should I do that job again?
I know it's just a drop in an ocean
but looks like it's just made for OOP
Brother if you're not willing to make some concessions on how Unity normally does things in order to work with dots you're in for a rough ride
Maybe some day we'll have an input system that's beautifully integrated with ecs, but we don't have it yet. For now we have to poll on the main thread and execute jobs as a result of that. That code I posted is the easiest and simplest way to do that
Like I said tertle posted an example of what (I think) you actually want yesterday, you can dig from that if you're desperate for the event response style
yep, I'm fine with it
but doesn't hurt to try find a better way
I am digging from it tho
at least partially
~~I've got a probably dumb problem. I'm trying to alias a FixedList64<byte>.Buffer pointer into my own custom struct.
So I have something like this
unsafe struct ReadOnlyQueue<T> where T : unmanaged {
public voic* Ptr;
public int Capacity;
}
ref FixedList<64> fixedList = ref structWrapper.FixedList;
var readonlyQueue = new ReadOnlyQueue(fixedList.Buffer, fixedList.LengthInBytes);
so I'm looking at readonlyqueue's Ptr content and I can see that it's pointing to the correct address, but the contents of the pointer are different compared to FixedList64<byte>.Buffer's content ๐ค~~
ah nevermind, figured out my issue, I guess don't alias a pointer contained in a struct and write an extension method which takes a readonly reference
Pointers are a pain. Does the pointer change at some point after initialization?
ah nope the addresses are the same, so my issue was actually elsewhere where I was writing a sort of "safer" api so no one else has to deal w/ pointers
but I guess passing a reference via in versus ref made the biggest difference for me. I should probably look into how in works on a compiler level when I grab a readonly reference to the struct ๐ค
cause that's all I had to change to fix my issue
I think IN assumes that the data is read only and won't change and ref is readwrite and will always assume it will be written to
yea
i figured, technically since I only have a readonly queue, I could just grab an alias to a reference readonly FixedList<64>.Buffer, but I got garbage data when I read from the pointer
// NOTE: Pass the FixedList64<byte> as an actual reference instead of a readonly reference.
// Not sure why, but passing the collection by in causes the contents of the pointer to be
// garbage data when aliased inside another struct.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// Originally I had it as `this in FixedList64<byte> collection
public static unsafe ReadOnlyQueue<T> AsReadOnlyQueue<T>(this ref FixedList64<byte> collection)
where T : unmanaged {
var size = UnsafeUtility.SizeOf<T>();
return new ReadOnlyQueue<T>(collection.Buffer, collection.LengthInBytes / size);
}
Should any Jobs questions be asked here?