#archived-dots
1 messages ยท Page 58 of 1
just inherit from as well
oh ok, thanks a ton!
ok now i just gotta workout how to add the parents correctly, as it seems doing it like this: ```cs
state.EntityManager.AddComponent<Parent>(SomeChildEntity);
state.EntityManager.SetComponentData<Parent>(SomeChildEntity, new Parent
{
Value = WhateverParentEntity
});
turn off burst and get the full error
clever, thanks!
hmm, how would i get a component out of an IJobEntity? i thought to use a NativeReference<TheComponent> but unfortunately nested native containers are illegal
hmm perhaps i could instead pass an entity instead of the component, and then just grab the component from the entity later? But i would have no clue how to get an entity inside an IJobEntity... Update: think i found a way!
hmm the entity that it is now passing to me seems to not exist, weird Update: got it working finally!!!
how would i instantiate an entity, and have it keep all the components of that entity?
tried that, but it isnt keeping the components, well isnt keeping the local transform component atleast
i suppose i could manually go through every component the entity has, then add that to the instantiated entity? Or is there a better way?
perhaps im doing something wrong in the baking? Is GetEntity(GameObjectPrefab) the correct way to get an entity version of a gameobject prefab?
is there anyway i can check how baking has converted the GameObject prefab into an Entity?
how?
Do you wish to see the baked entity? As in the entity hierarchy information?
or do you want to step through the baking process?
i want to see the components of the entity created by GetEntity() to see if it has the right components
Switch entity hierarchy view to runtime (the yellow circle next to the triple dots) and the baked entity will be shown under the relevant subscene
ok, and then from there how do i see the entity created by GetEntity()?
You might need to hunt for it as if it was baked previously, the entity should resolve to link to the original GO
Well for one, you can create a debugging component that contains the entity as a field. Then check that in the inspector.
oh, so check the gameobject prefab! Thanks
oh ok, i tried that but cause im using an array of structs containing an entity it refuses to serialize
Arrays are not allowed in components. Have you tried a buffer component?
really, even native arrays, as my other components with native arrays seem to work fine?
Native arrays can not be baked because they are unmanaged and must be disposed manually.
ah, that is unfortunate, so what should i use instead?
Buffer components.
ok thanks a ton
how about native lists, they fine, or do i also have to replace them aswell?
A dynamic buffer component is a native list. And yes, you need to replace them with a buffer.
ok thanks
Nothing NativeX is allowed.
ah ok thanks so much!
ok so if im understanding this right, i add 1 buffer for every element in the array, right?
The buffer itself is the native array / native list. And you add one element for every element in your array.
For each array you add a buffer and for each element, well it's just a native list tacked onto an entity.
fascinating, so i put the native arrays and lists inside the buffer component then? Or am i completely misunderstanding this?
oh wait i think i get it, so i treat the component like one element in an array, and when i add the component to an entity, i can specify elements and stuff that is itself?
No no, the buffer component itself is the native list. As in the buffer = native list. Here's an example of a buffer baking:csharp DynamicBuffer<EntitySceneReference> scenes = AddBuffer<RequiredClient>().Reinterpret<EntitySceneReference>(); foreach (BakedSubSceneReference subScene in authoring.client) scenes.Add(subScene.GetEntitySceneReference());
ok fascinating, thanks so much
Where RequiredClient is:csharp public struct RequiredClient : IBufferElementData { public EntitySceneReference Value; }
seems you bake buffers very similarly to the way you convert an array of structs to be entities instead of gameobjects, thanks so much!
The equivalent list would be a NativeList<EntitySceneReference> scenes = new NativeList<RequiredClient>(Allocator.Persistant).Reinterpret<EntitySceneReference>();
ok fascinating, thanks so much!
is there anyway to get RW access to a singleton form of a buffer? Sadly GetSingletonBufferRW<>() seems to not exist...
GetSingletonBuffer<>(Entity, false)
The boolean after the entity indicates RW state (false = RW, true = RO)
wow, and it is a reference, meaning i wont have to set it afterwards?
Yea, you can directly use it as a reference to the buffer.
awesome, thanks so much!
Right, an i'm off to sleep. If you have any further questions, hopefully someone else can help ya out. Good luck and see you tomorrow.
good job, and thanks a ton!
now that i know you cant use native stuff in components, what would be the replacement of a NativeHashMap?
you can, but it won't bake
i dont need to bake it, so can i just use it then?
yeah, I think so
so it is only native array and native list that can't be used in components?
oh wow, judging by what KornFlak said i thought i would have to replace them, was what they said incorrect?
while yes you can put native containers on components
it won't really work how you want
you can't access the container in a job
you can only access it in a system and then pass it to a job
oh ok fascinating, so i should use the buffer components when im planning to do something in a job with them, and native containers when i dont plan to use it in a job?
i would suggest, for the most part just don't put containers on entities
unless you really know what you are doing and have a very specific reason for it
well i need to store containers somewhere, unless there are replacements?
basically only put them on singleton entities you get on main thread then pass to jobs
to share a container between systems
ok fascinating!
I've got a project (in 0.51) with a dynamic buffer on an entity.
Very specifically on the entity - created at runtime - because storing a reference to it in a component caused problems. Unity crashed, the "solution" would probably be to update the reference every frame with GetBuffer on the entity but then why even have the reference on the component anyway?
also if i have an array of gameobjects and i then during baking convert it into a native array using GetEntity() is this going to mess anything up, or will this work?
ok i dont think it works, as it just passes me blank entities, weird
dynamic buffers
true, ill start using dynamic buffers where possible
ye it definitely doesnt work, this is a major issue as i either i can hardcode my gameobject prefabs, or i need some other way to get an entity version of a gameobject...
How are you instantiating your prefabs?
state.EntityManager.Instantiate()
I meant the process more than the function call itself ๐
oh sorry lol
How are you getting the prefab and sending it to the Instantiate() call?
essentially i have a biome component, with an array of feature structs, each feature struct contains a gameobject and a few other details about the feature, i then bake this into a component version of the array of feature structs, with entities instead of gameobjects which i get via GetEntity(), whenever a chunk needs to be generated i grab all biome components and go through them to decide which one to generate, then go through each feature and pick a random one, once i have my random one i then instantiate it
More complex than I expected.
Here's a sample file. I imagine it'll be easier ๐
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/EntitiesSamples/HelloCube/Assets/4. Prefabs/SpawnerAuthoring.cs
i've seen that before, but i cannot get it to work with my logic, either the entities i store on the components somehow become invalid, or GetEntity() is going wrong, or instantiating is going wrong, and i cant tell which
is there anyway i can debug what is going wrong?
You've got that kind of authoring component, set the Entity reference to your prefab and get and instantiate it as the SpawnSystem does?
If so, I don't know what the problem is. I'd probably start by adding a Debug.Break() call, check the reference, check the prefab entity (in the DOTS Hierarchy window) and possibly debug print the prefab reference you get in the code. See if they match.
Makes sense to also print the entity returned from Instantiate()
Oh and, try to do it in a small environment first? Just one prefab with limited systems and not a whole slew of collections with references to prefabs or whatever.
Simplify, solve, expand.
ooh fascinating, ill try that thanks
ok i've done a bit of debugging and now i can confirm that my prefabs are being correctly converted into entities! But they are not getting instantiated correctly, instead of duplicating the prefab, it decides to do this:
which lets me know that i have no clue how to instantiate stuff
ok after many googles i can say that instantiating should be really easy, but for some reason just wont work for me, how odd
wait a second, do entities have to be passed by reference, as that may be the issue?
entities are effectively just a key
made up of 2 ints
they do not need to be passed by reference
You can see that on the screen grab above too. Index and Version.
i just a wrote a packet fragmenter for netcode
Basically if you add any data to a DynamicBuffer<NetworkPayload> (which is just a byte) on a ghost entity
it will compress then split it into smaller 512kb ghosts and recombine them on the client's ghost NetworkPayload
designed for binary data that's mostly static between 1-20KB
i thought about writing it as a separate socket side channel
but i really wanted to be able to just tie into netcode relevancy for this
I'm guessing that during baking, the GetEntity() that you store and later use to instantiate is getting invalidated.. Normally that'll happen if for example you don't store the GetEntity() result in an IComponentData or a buffer ( because using GetEntity() during baking returns a temporary entity value which gets tracked and then updated on your components/buffers after baking is complete )..
During baking entity id is 100% not the one that will be assigned in runtime, yeah
only whatever is supported by baking will be properly remapped to actual entity
To be fair it does look like it's instantiating something.. May be it's an invalid entity value as mentioned above so it's instantiating some random entity and not the actual prefab, or as Issue is saying the gameobject isn't really baking properly so you're getting an empty entity instantiated..
How do I use WeakObjectReference during baking?
The inspector just shows me the struct contents, nothing to e.g. drop something in
Are there any serialization bottlenecks with data that large? Since it would still need to check if the data changed
(Also I'm guessing you wrote this for sending your navmesh?)
I feel like the editor for WeakObjectReference is just broken for me, WeakSceneReference shows a scene field to drop a scene into..
bruuuh, is there just any fix to avoid restarting editor if you stop play mode with entity inspected?
Does anyone have a new guide? The pinned github is gone
Thanks
I'm extremely frustrated
smth in my physics is doing very funny stuff
as soon as I get my trigger event
my entities are getting swapped with another
their position
is swapped somehow
and there is nothing in my code that does smth even relatively close to it
here logs are thrown before and during trigger event job
and now 1 frame afterwards
same for entity 175
Trigger event, no collisions, just overlap?
yeah
Do you have a image of before and after of the overlap?
Here's moment couple frames after overlap
basically
tree1 got swapped position with tree2
Tree1 should be left, Tree2 right
yet
feels like someone in Unity made a very funny joke
I did tons of records in journal
huh... hrm
and nothing modified LocalTransform component except for Unity Physics Export System and my system that moves entities by a bit
during that trigger event time frame
And my movement system looks like this
private partial struct MovementJob : IJobEntity
{
public float2 playerVelocity;
private void Execute(Entity e, ref LocalTransform local, in Movable movable)
{
Discard(e.Index, local.Position.x);
local.Position.x -= playerVelocity.x * movable.speed;
Discard(e.Index, local.Position.x);
}
[BurstDiscard]
private static void Discard(int ind, float val)
{
Unity.Debug.Log($"{ind} {val}");
}
}
and it is pretty clear from log, it's not my system
You dont need the discard on that job but yea, try logging player velocity as well
now I will test one other thing
I used it to avoid trashing my editor with tons of messages
ah true
now I will make a backup of LocalTransform
before physics import
and then write it back
because in my world, physics should not move anything
Are the bodies dynamic?
Try making them kinematic or even static
Hrm, no clue then
if I make them static, triggers don't work
which is odd
hmm
now static works with trigger
god, this is driving me crazy
๐ฅด
ok
seems like static thingy solved it
welp, but that only delayed me going crazy ๐
I think it's a bug
and I want to see if it's reproducable
Okay, no clue what's going on. GL.
That's the reason it's broken up to avoid bottle necks. It's got minimal priority.
It's really just designed for small static or rarely changing binary data
Checking if data has changed if as easy as change filtering the buffer and then just checking length != 0
As the payload buffer is cleared once split
I have an editor script that unselects leaving play mode
is it part of library? ๐
What broke and requires editor restart? I leave entities selected all the time and outside of a default inspector, it's fine.
if I leave entity selected and stop play mode, editor starts throwing 35 error per second
I get disposed world issues
That's concerning. I just get this replacing the entity inspector:
Hey. I've got a question. In Entitas, there is a thing called Reactive System. It only updates if specific components have changed and it automatically queries for the entities that have those components changed. Is there something similar in DOTS?
I think it's addressables
Kinda. You need to manually check for change filter but it's 2 lines.
The addressable header does a get hash code check on the object which for entity selection proxy hashes world
could you share it?
This is a system that will only run if a singleton GameResources changed since last time it was checked.
In bed but just subscribe to https://docs.unity3d.com/ScriptReference/EditorApplication-playModeStateChanged.html
and how to unselect?
Thank you, exactly what I've been looking for!
Unityeditor.Selection.ActiveObject = null
Or something like that
You can check if the entity proxy is selected first if you wanted etc
I guess that's it
static EntitySelectionErrorFix()
{
EditorApplication.playModeStateChanged += LogPlayModeState;
}
private static void LogPlayModeState(PlayModeStateChange state)
{
if (state == PlayModeStateChange.ExitingPlayMode)
{
Selection.activeObject = null;
}
}
IsEmpty is a probably tad faster and just looks nicer
Yea. Eh. nanoseconds faster.
oh man, finally
no more wasting precious time restarting editor
Kek
kek indeed
So anyone know how to use WeakObjectReference?
I just don't feel like it should look like this
@light badger When you accept join requests from a client in your OnlineFPS sample, is the send RPC component suppose to be broadcasted to all connections?
If a client sends an RPC it's always only sent to the server
That's server side.
Ah, my bad
That seems like a bug then
Unless the clients need the information for something ๐คทโโ๏ธ
As in the code sample is from server accepting a specific client connection request and now is sending a join request RPC back to all connections apparently.
Same here
Wasted archetypes ๐ฑ
Yeaaaaaa.... ugh
I will waste as many archetypes as I please
You suggest it'd be better to add component types set first and then set data?
I'd probably do the same thing as I'm lazy but yes you should create entity with an archetype then do a set instead to avoid creating an extra unused archetype
I tried it and my FPS doubled, insane
Looks to me like SchnozzleCat adds a RequestEnterGameRPC component and you're adding a ServerJoinAcceptRpc component as the only notable difference
I wish AddComponentData has overload for multiple component types
It does
There is no common component that should be used for the RPC request, these are just the names we picked
Look at the componenttypeS overloaf
And mine is obviously better because I capitalized RPC violating my naming conventions
Happy?
Much better
I wish new[]{} was burstable. Damn bill gates and managed arrays.
That does look kind of horribly excessive in complexity for the same end result.
Not that atypical but still
same result?! he's saving 16KB of memory and removing an archetype from query searches!
game changing
I think a better version would be AddComponent(Entity, new ComponentTypes())
But this hyperoptimized version skips one add component.
I'm sorry, I should've specified "for the same result on the entity". My bad, I'm a horrible scrub who does not know how to code etc etc
Like I said, it doubled my FPS. I'm now a believer
If I have a complaint with it, it's that the interface for getting that (apparently very significant) performance increase is so much more cumbersome than the simpler "add components one at a time" approach
(I was also joking with the doubled FPS ๐ )
Pretty sure you are fine with adding components one at a time. Ideally you'd instantiate a prefab most of the time and then set the data on that
(at least that's what I try to do)
I mean, if it's 16KB of memory per time you do that, it's a significant improvement in a larger project
it's once per new archetype
Yeah same, if I know I need some components on a prefab I want to have them on there already if I can.
The one thing I haven't figured out how to do on a prefab in that regard would be adding a DynamicBuffer. Doubt you can do that on a prefab in the first place.
basically the AddComponent ServerJoinAcceptabledRpc will create a { ServerJoinAcceptabledRpc } archetype
then the SendRpcCommandRequestComponent will create a { ServerJoinAcceptabledRpc, SendRpcCommandRequestComponent } archetype
Does unity never "clean up" unused archetypes?
no
:[
it's also not unused, you'll use it again on next connection
Not the ServerJoinAcceptabledRpc
there is a limit of around 8-12k archetypes and it's really easy to hit if you add/remove a lot of components
that's just the intermediate from adding twice
I'd say it's probably closer to "temporary" rather than "unused"
or, yeah, intermediate
in this small case, it really doesn't matter
but i have seen people have large dynamically generated entities at runtime
that just do like 50 addcomponents 1 after the other
and we did something like this at work
and using an editor analysis and pre-computing the archetype saved us over 2,000 archetypes
Oof. That seems just plain painful.
Much cleaner to just have the components on the prefabs so you don't need to cross reference instantiation to figure out what components are associated.
Ah, and no time allotted to technical debt?
haha you have never seen a project with more technical debt
god damn awful
can't wait till we start a new one which will be built upon my own libraries
That sounds painful to work in
so painful
being in charge has perks though, i can just assign all the painful tasks to others ๐
now imagine companies that hire for working with 2020 editor ๐ด
At some point, just fucking upgrade lol
we use 2020.3 ๐ฆ
there's no way we could upgrade this project to 1.0
I know
I couldn't upgrade my own SMALL project from 0.51
I straight up redo it
because it's easier
i tried upgrading us to 2021.3 and it was a nightmare
and too close to launch so gave up
Don't have to go to 1.0 just because you're upgrading the editor lol
the 0.51 upgrade took enough effort
entities are tied to editor
you can't use 2022 without 1.0
You can do 0.51 in 2021, I wasn't necessarily talking all the way to 2022
yeah i tried 2021
I was also not aware of this
too many issues
we are just using 0.51 on 2020
and since our gold build pre is due on tuesday
be a while before i try again
Makes sense ๐
Rough time to release too
we're just going from early access to 1.0
though it's a huge update
basically a new game
Even if it was from 1.0 to 1.1, I'd consider it a release. Probably a case of definition differences though
oh yeah i got ya
ah, yeah that's something that should be changed
Okay, thought so. Good network framework though. I'm going line by line and overhauling my own to largely match what you're doing. Although I am hesitant on using ECBs for deferred structural changes. Are they really better than just direct EntityManager calls for network initialization and spawning?
Maybe I'm just old but i still remember those benchmarks that showed even bursted ECBs required 2x or even 3x more execution time to structurally change the same commands as directly using entity manager calls. But this was 2018-2019 profiles back when ECBs just managed to get bursted. I havent seen any comparisons since.
Don't know about comparisons so the only input I have (sadly) is that ECBs help with sync points since you're not doing structural changes interspersed throughout the system updates
direct EntityManager calls would be totally fine in most cases, although sometimes ECBs are required in order to do structural changes in a loop without invalidating data
Yea. i'll just stick with ECBs then.
the one thing i've been trying to do recently is avoid every frame empty ecbs
making sure systems early out that don't need to run or avoid using ecbs where a system needs to run constantly but only rarely writes to the ecb
i find the overhead of playing back an empty ecb a bit high
whats an empty ecb?
ecbs.CreateCommandBuffer()
dont do anything with it
just the ecbs.Playback overhead on the command buffer
and disposing
this is the cost of an empty ecbs
ah
hmm, now im paranoid if i do this alot or not
but if you have 15 systems with ecbs, that's a ms per frame
Every frame? Potentially multiple ECBs? Ouch
now ok i'm a little exaggerating here from an editor profile as it's a bit less in a build
(about half that)
but you still get the point
So what's your pattern? A TryGetECB on a system?
i just removed structural changes or do them in OnUpdate for singular entities or once off changes (init)
Ah
all my destroys go through a single system
i have a whole destroy pipeline
Store the entities to be destroyed in a buffer or what?
where you can react to things being destroyed, cancel it etc
private void TryGetEcb(WorldUnmanaged world, out EntityCommandBuffer ecb)
{
// * Command buffer for deferred structural changes.
ecb = _ecb.IsCreated
? _ecb
: SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>()
.CreateCommandBuffer(world);
}```
I think the biggest thing for me is just entities being created and destroyed on the client by the server
not sure what this is doing? you can't cache an ecb from a ecbs
and you can't use an ecb after its been playedback
I think they mean re-use the same one across a single frame by multiple systems
oh is this for a single system?
It's only existing temporarily per update
yeah ok
you could probably wrap this behaviour in your own ECBS + singleton if you really wanted
where you write a custom CreateCommandBuffer(x) that would return a cached version for a system or a new one
hmm
๐ฅณ
Oh, very nice. I thought you also had a fadeout as well? I've been kinda mirroring this implementation using ghost relevancy which is slightly buggy.
fadeout for what sorry?
fadeout for distant objects that just got spawned in on that navmesh
Ah
the first draw is the servers full navmesh
i decided not to regenerate it on clients and instead send it
because ghosts streaming in constantly just ends up causing it to rebuild constantly
and runtime navmesh generate with complex meshes is just not that fast
(about 1.5 seconds for this scene using 50% of threads)
what i did was add support for sending navmesh via netcode relevancy
and then added a packet fragmenter so i wouldn't run into network issues
by default compressed most of these cells are 0.5-1KB
but in the centre with a lot of details they go up to 10KB which is too large for netcode ghosts
so i wrote a generic network payload implementation
basically you put any type of binary data in a NetworkPayload buffer
and it will auto split it into 512KB chunks over X number of ghosts
then recombine them together on the client after they've all synced and assign to the clients local NetworkPayload buffer
great for static data in the 1-20KB range
@light badger Also, is there a reason why you're not using the existing linked entity group for tracking owner relationships?
when i was helping shinclef setup rival with my game library we had the same thought
adding stuff to a LEG on a ghost broke a bunch of stuff or something when we tried
oh, huh. Hrm.
They're all just 1 element and otherwise wasted space.
hate to say I am finding LEG very useful recently
though i am still at war with the forced LEG and default capacity
I was thinking about adding a LEG to a network ID component for automatic owned ghost destruction.
i think unity did something similar in the car demo
Fighting the good fight, although the capacity override at creation system ya made works well enough that I'm not ambivalent to LEGs instead of actively hostile.
to be honest I can't really remember if I had a real justification for this. Some vague sense of maybe having more explicit control over things
Yea, i'm reading through it. I'm gonna try my LEG format and if it explodes, i'll go your custom buffer way.
definitely worth a shot, our use case might have been different
I was thinking this instead of a ClientOwnedEntities buffer and also using the CommandTargetComponent to indicate player entity instead of a custom component. csharp // * Using LEG for easy cleanup of owner controlled entities when the network is destroyed. ecb.AppendToBuffer(srcEnt, new LinkedEntityGroup { Value = playerEnt });
oh this is on the network connection?
yeah that's what i do
rival from memory uses network connection -> player (commands) -> character
i think we had issue putting character onto the player leg
ah, hrm. Okay. I'll need to see if i run into the same issue
What is this LEG of which you speak..
linked entity group
Ahh, LinkedEntityGroup
Need to look that one up
HNY tertle I assume you're in 2023 already
well into morning ๐ ty!
bruh
for some reason some AnimatorController gets serialized
and other don't
in subscene
what do you mean by others
literally just 2 different animators
practically no difference between them
and they are simple
what do you even mean by serialized?
(and what is AnimationController)
just this
public override void Bake(Animator authoring)
{
BakingUtility.AddAdditionalCompanionComponentType(typeof(Animator));
AddComponentObject(authoring);
}
I'm making a build rn to test
whether it'll be fine
hmm from what i understand AddAdditionalCompanionComponentType might not actually work in builds
I'll use native animation system
๐คฃ
at the worst, I'll migrate to graphics
and do my animations by swapping id
are there any plans for the foreach to ever compile to jobs in the future or is it strictly mainthread access?
systemapi query? it seems intended for main thread
was a little surprised it wast an all in one replacement for EFE but just curious really
i'm glad it's not
i find efe just caused bad code constantly
sure the job starts out small and maintainable
then someone adds some functionality
and someone else some more
and then a bit more
next you have a 400 line EFE with 12 local fuctions
oh yeah, that was my character controller in 0.17
๐
huh
looks like my VisualTreeAssets on the other hand don't get serialized for some reason
in a build I mean
๐ฆ
some do, some don't which is odd
yeah, indeed
some are nulls, some are not
what the
ok using chat gpt to figure out ik lookat solver for animation was pretty damn neat.
oh no, the first step to being replaced
when it blends to run?
edit oh misread to instead of is ๐ - still blending could be improved to take foot position into account
I want a reload timeline
trying to wrap my head around buffer components, is the InternalBufferCapacity() how many bytes each element needs, or something else?
It's how many elements you want to allocate to be located inside the chunk.
oh ok fascinating
You have 2 memory locations, inside the chunk and outside on a heap. It's like stack and heap memory.
fascinating, im not the best with memory, so i have no clue what stack and heap memory is im afraid
Memory inside the chunk (indicated by internal buffer cap) is fast but you balloon the size of the entity. Outside the chunk is slow but more entities can fit inside the same chunk.
Rule of thumb, just set the internal buffer capacity to 0 outside of some very small edge cases.
ok thanks a ton
More entities inside a single chunk is almost always better than having immediate memory access to a dynamic buffer element.
ok cool!
98% of the time, you want an IBC to be 0, 1.5% you use a fixed field. 0.4% you use a copy pasted field (like how the fixed X bytes are done). 0.1% you use a IBC of a larger value.
ok got it, thanks!
wondering is it possible to get a buffer in an i job entity like regular components?
yea, DynamicBuffer<buffCompType>. Standard rules of in for RO and ref for RW.
thanks a ton!
do dynamic buffers get passed by reference in job fields, or do i have to instead just store a native reference to the entity and then grab the buffer afterwards? (i hope that made sense)
You can use the dynamic buffer passed in at the parameters list directly.
ye but i mean i want to pass the dynamic buffer outside of the job, does that make sense?
hrm, I think that's possible. Using a IJobEntity to query for a specific dynamic buffer then writing that buffer into a NativeArray<DynamicBuffer<BufType>>(1) for use in another job. But the safety system might throw a fit.
perhaps it would be better to just store the entity from the parameters in a NativeReference then, and just grab the buffer afterwards?
Yeaaaaa, that's more advisable. Use a BufferLookup<BufType> obtained from SystemAPI
ok thanks a ton!
nice tool
Huh, I didnt realize needle made stuff rather than just being a unity repo mirror.
is there anyway to get a component of an entity created in an ecb before it is played back? (tryna figure out how to set the pos of an entity while using an ecb...)
Three options.
ah no, im trying to set the position of an entity, and i dont think the position is a buffer?
I've tried this, and I get an animator component added now on my entity, but it doesn't seem to actually animate... T.T
You want to get the component value of an entity created in an ECB that hasn't been played back yet?
You can just apply the position using set component. If you're trying to read the value, that might not be possible. It depends on how you made that entity.
ok thanks a ton!
@light badger All over your code, you check GhostOwnerComponent NetworkID against local connection value to operate on only local ghost owned entities. Is there a reason why you're not just using GhostOwnerIsLocal enabled component in the query?
wondering, is it better to do parenting first then do positioning, or should i setup positioning first and then setup the parenting? (also if the parent's position is 0 0 0 then any child's local position should be equal to its world position right?)
Ideally, you have no parenting at all.
Parenting and inheritance in DOTS is a bad pattern. Sometimes necessary though but aim to minimize as much as possible. If you must parent, setup parenting then set positions using the TransformAspect.
ok fascinating, thanks a ton!
Has anyone managed to get the IInputComponentData working for thin clients? Or is ICommandData the only way it'll be serialized?
Hrm, seems like it.
No, input components should be working for thin clients, all the required systems are hooked up and enabled for thin worlds, but the buffer isnt being populated. Why
There we go, i forgot to set the ghost ownership on the instantiated player entity. Woops.
@light badger Another suggestion, in AuthoringKinematicCharacterProperties, move CustomPhysicsBodyTags below the two interpolation tags. This will remove the double "General Properties" headers that appears when the imgui tag sets a header and the uielements also does so.
@light badger First is original in rivals and the second is the proposed change:
You also need to manually update animators
How so?
Stop abusing the poor companion GO. Just roll your own hybrid.
It works with everything, no internal access required. Just spawns a GO and mirrors the transform.
It even works in editor. Like magic
I dont want x2 gos per entity
Replace all companion GOs with this hybrid setup.
ah, i see
well, stop being lazy.
It's more like 1 go and 1 prefab but still, laziness is bad. Companions are gonna get nuked soon.
Then we'll get alternative for sprites
and this is from the companion king!
I've converted. or just gave up and rolled my own.
if netcode is anything to go by, the alternative is basically just what kornflaks posted
netcode already has a hybrid presentation implementation
which just spawns gameobjects/manages them
I only need hybrid because of sprites
Yea, i just wholesale copied the hybrid presentation but used a component to indicate linked GO rather than a native list.
It's one prefab, not that bad.
what are you doing with your audio lights etc?
So you just store prefab on comp and then instantiate?
yep
And i use fmod
Imagine using audio, my game will be as silent as the grave. People (i.e. me) have youtube anyways.
Workflow might be painful
you're just being inclusive to the deaf
There ya go, game is fully accessible to the audibly disabled.
I shared the entire folder above but here's how it looks:
I build scene with them
Yeah, but I need to see sprite in scene view
Works with spawning anything mono, including tilemaps that are updated like a regular monobehavior.
(this is basically the same concept as my original hybrid implementation i was promoting months ago and no one was interested. suddenly 1324123 copies)
here in dots we love reinventing the wheel.
So beautifully circular, so round and spherical.
How does it work in scene view? (sorry, on phone, haven't seen folder)
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.Editor)]
Ah
If you dont have netcode, you might need to change client simulation to default.
You have editor system
It's the same system used in runtime, just also runs while outside of playmode.
The transforms are there, the mono prefab is also there, why not also spawn the go as well?
Same as companion gameobjects (I copied pasted this)
It took about 15 min to throw this together
oh interesting. i just clean them all up in system ondestroy
but that seems like a maybe even more reliable approach
Note, this only works if the subscene is open, havent figured out a way to render the go's with the subscene closed like hybrid renderer but eh, it's good enough.
It renders in runtime with the subscene closed, just not in editor.
That means workflow is still miserable, sadge
I mean, just open the prefab in scene view
This is play mode
And this is outside of play mode. Might be because of something in netcode though.
But scene view is important, in edit mode
So just open the subscenes then
Oh and there's no picking in scene view, if that's important then uh, that'll require quite a bit of work.
Yeah, and then close them on every change... Gotta be a better way
Just close before you enter play mode. But a better way is gonna be harder.
wait no, it does work
I just had the subscene not loaded because I custom load them for netcode
If you have them on auto load scene, the game objects show up
as I said, netcode might fuck with things, lots of things are toggled off and only manually ran in code.
Jeez, networking sounds painful
The only thing now not working is scene picking. Give me a sec i got an idea.
It is, it really is.
netcode is trying to make a lot of historically difficult network things a lot easier
Dont get me wrong, netcode has made networking go from 1000 painful to 100 painful, 10x less painful but still like pulling teeth with a doornob
Btw, you can make auto switcher on awake for subcene load mode
Should help with authoring
Probably but it's not too bad. Quite obvious if I forgot to turn off auto load if anything shows up
Or the 50 million errors on awake also halts execution until I fix it
That's the point
Auto load on default
And disab
Led in runtime
Oh, hrm. Could work.
Alright, the picker's internal because unity is evil, gonna get some asm hacks to see if this works.
Damn, no, picking doesnt work even setting editor render data
Could use a static go registering
So on click it goes over spaawned gos and compares to registered
Seems rather bad performance.
Editor one
Yea, there could be a lot of things in the editor
Or other way
Picking only happens in editor anyways
https://forum.unity.com/threads/hide-object-in-hierarchy-but-still-allow-selection.536184/#post-5402763 You'll probably need to do some temporary component on the cloned GO prefab that disables the hide in hierarchy hide flag on the overlapped GO and only if the sub scene it originated from is open. Well, opened might not be necessary
In ECS physics is it more performant to make a trigger collider that is added to the world or to do casts manually?
Depends on your use case and frequency of use
specifically for weapon projectiles, though in my case they can be large so just doing raycasts isn't enough
Are they simple, like spheres? Then a sphere cast is probably better. If it's a complex mesh, a reused trigger collider will probably be more performant. Profile it.
oh boy, 2d character controller is a lot harder than I thought.
i'll figure it out tomorrow...
same as 3d though, no?
with 1 less axis
in a SystemBase how would i get rid of entities?
entitymanager.destroy
commandbuffer.destroy
thanks!
Top down means that one should assume characters are always grounded. Which changes a key assumption at the root of the controller. So I'm gonna have to change a lot of things to accommodate that assumption.
ain't you having isometric?
this should be pure 3d
No, it's just top down. No z axis at all.
then why do you care about being grounded at all?
Exactly. The character controller does however. So I need to change that.
Hopefully without editing the actual package. It seems flexible enough to allow for custom overides.
No, rival
you could probably just delete the whole concept of being grounded
I don't want to edit the actual rival package.
But yea, I'm gonna try to do something along those lines and see how far I can get.
but it's literally tells you to
in rival manual
it wants you to modify package
in order to add features
Problem is maintaining it as dots moves forward and physics might change
I don't want to maintain an entire character controller, one that I didn't write myself so I don't know it as well.
then I think Rival does not suit you really
package is built around the idea of modifying it, so...
But I don't want to write one myself. So I'm gonna work around the existing api
One that will enable me to drag and drop any changes coming into the assets folder and not worry about maintaining compatibility with whatever the physics team does
Because rival works as I wish it to in 3d, it's just several key assumptions must be injected at the foundations of the asset for it to work in a 2d top down format. 2d sidescrollers are a lot easier than this.
could anyone remind me
how to select Entity through code?
what package
do I need to publicize?
nvm
I think I found it
yeah
now the problem
is that how do I trigger on editor clicking hybrid go
I tried this, but no luck
[InitializeOnLoad]
public class LinkSelection
{
public LinkSelection()
{
Selection.selectionChanged += SelectionChanged;
}
private void SelectionChanged()
{
var selectedLink = Selection.activeGameObject;
if (selectedLink is not null && selectedLink.TryGetComponent<HybridEntityData>(out var hybridEntityData))
{
EntitySelectionProxy.SelectEntity(hybridEntityData.world, hybridEntityData.entity);
}
}
}
// Selected entities should always try to show up in Runtime mode
SelectionBridge.SetSelection(authoringObject, context, DataMode.Runtime);```
if you want it to play nice with data modes
otherwise yeah, EntitySelectionProxy.SelectEntity is fine since it probably doesn't matter
oh wait
my constructor is wrong ๐
it's simply not working though
seems like nothing changes
if I try to click hidden go
is it possible to get access to component data from a monobehaviour? (seems it would be easiest to setup a ui using a monobehaviour)
that's hardest way to setup a ui using mono
๐
ah, what would you recommend then?
the most simple way - use Model View Presentation pattern
And just for each presentation (view) create a system
access your UI objects from here
and manipulate from within system
ok but you cant access ui from components right, unless there is an ecs version of the canvas?
this is easiest for small application, but it won't really scale
Object.FindObjectOfType<> is static
just don't use it in OnCreate
because Scene is not loaded
yet
ok thanks a ton!
How do I specify that system should run in runtime and editor
[WorldSystemFilter(WorldSystemFilterFlags.Editor)]?
| localsimulation
Can anyone help me understand what is going on here?
This issue only appears when I launch standalone build of my game
Scene loading works fine in editor
No one has any idea what should I do with it?
you could try finding the object that breaks subscene
The issue is, that there is literally nothing to break
Even a scene like that causes problems
With or without a subscene
And only on a built executable
In editor in play mode everything seems to be working fine
subscene is the one that breaks
not scene
@rustic rain what changes do you need in your animators to make them animate as a companion ?
at least from the error
you need to update them
Animator.Update
for now I literally just use companion link hack
and then query each animator as component
which is extremely slow
0.2ms to update 10 super simple animators or smth
It might not be too obvious on the screenshot but the subscene is literally empty
well, try empty project. If it doesn't work too - smth wrong on your end
I'm still not sure what exactly is wrong here but I've found a bypass for my issue
Instead of loading the entire scene I'm just loading the SubScene itself
subscene is just a monob that points to serialized entities
you can't load it same way as normal scene
Well, it somehow works for me
bruh, I hate that hybrid workflow with double prefab
I'll stick to companions
even though functionality is same, keeping twice as much prefabs for same price is meh
what is the parallel version of GetComponentLookup?
it is can be used as parallel
if you want write access and you ensured it's safe
there is attribute
[DisableParallelWhatever]
my use case isn't safe thought ๐
I guess there's not really anything I can do to get around that
then you are asking for crashes and corrupted data
I guess I'll just have to do that bit serially
do I need to do something special to destroy an entity with children?
well, you need to destroy all children
is there a proper way of doing that or do I just have to do it manually?
nah, people just come up with their own ways
Here's one way
public static NativeArray<Entity> GetAllEntitiesInHierarchy(this BufferLookup<Child> lookup, in Entity parent,
Allocator allocator = Allocator.Temp)
{
var list = new NativeList<Entity>(1, allocator);
list.Add(parent);
if (!lookup.HasBuffer(parent))
{
return list.AsArray();
}
var buffer = lookup[parent];
foreach (var child in buffer)
{
var children = GetAllEntitiesInHierarchy(lookup, child.Value);
list.AddRange(children);
children.Dispose();
}
return list.AsArray();
}
works with EntityManager too
if I do CommandBuffer.DestroyEntity(entityIndexInQuery, entity); can I only call that with one entity, or as many as I need?
one entity per entityIndexInQuery I mean
just look at all available public methods I guess
I'm feeling pretty dumb, can't even get this 'easy' hack to work >_>
Systems finding animator components and calling update on them (with delta time), but still nothing happens.
If i drag a prefab into the normal scene it does work though.
your animator game objects must be saved as prefabs
or else Animator Controller will not be serialized
it's some kind of glitch I found out yesterday
I think they are prefabs? or do they need to be like an extra one
the animators are a component on a prefab which gets baked
@rustic rain both the animator and companion components point to the same item, and if i click it, it can find it....
try to make some static collection ticker
which adds your animator to tick in OnAwake
or OnEnable
ok, I'm done with Hybrid
I just hate it
I want to make sprite renderer within entities graphics
tell unity to add 2D to entities graphics please
I'm trying to learn how to make one
Can you use material property blocks in entities graphics?
there is material property ovverides
but it's funky
MaterialPropertyFormat this type does not exist
I'm pretty sure mpb are superseded in batch renderer
Superseded by what?
Sorry srp batcher not batch renderer *
How does the batcher replace the need to override material settings
(I'm asking since that's all that SpriteRenderer really does)
You just use different materials with the same Shader
Seems kind of weird to have to create an in memory material for each sprite, especially if you aren't using atlasing, but I guess it works
I wonder if that will still dynamically batch
I'm guessing no, but I've never tried it
If it has the same compatible Shader and mesh, it should batch
The mesh isn't the same though, since it needs to write the sprite atlas UV coordinates into the vertex
And it won't be the same anyways if you do something like tight packing
(I'm talking about dynamic batching, not the SRP batcher)
I've also thought about trying to write something for 2D sprites for graphics, but there's too much I don't know about how unity handles sprites
I still have no idea how the sorting groups work for example
I hope unity releases something in that direction some time soon, although I doubt it
but you were asking about entities graphics package
so now i'm confused
Yep, I'm an idiot ๐ my bad
Then you'll need to create a material per sprite / atlas
Do you know if Unity has said anything regarding 2D support for graphics? I don't follow updates that closely
I wish the companion linked object at least had support for more 2D stuff
There's no reason for e.g. SortingGroup to be missing from it
can I iterate only on all of a chunk's enabled entities or is it strictly a per entity basis?
wait maybe need to use entityquery for this
You always iterate chunks, and then decide if you want to iterate an entity (e.g. based on enabled status)
If you want the "disabled" entities to not be in that chunk, use a tag component so they are moved
How do you even access the companion linked component? It just says SpriteRenderer in the inspector but that of course doesn't implement IComponentData...
Or do you need to get the CompanionLink and then call GetComponent on the game object?
Does anyone have any tips regarding how one could think when wanting to implement things in a "generic" way in a chunk job for example.
My case in particular is about abilities, and I would like to add different behavior for my different abilities, but process the abilities in the same way. But I'm having a hard time figuring out how I can do that without adding a big switch to check the abilityType in all my systems that do work in the ability ๐
My OOP brain is having a hard time haha
I implemented a prototype for an ability system recently. It is node based though, but does use a switch statement to call the correct code for each node
And you can access these nodes in your jobs?
Yes
The graph is stored in a scriptable object during authoring time, and is then converted to a blob-based representation of the graph for use in bursted jobs
A single job then executes all running abilities in parallel
Yeah that's the behavior I'm working on. I'll see if I can use the blob asset too
The switch statement is kind of annoying, but I'm not sure if there's a good way around it
You don't need to use blobs if you don't want to, I just like using them since it's easy to serialize them
Yeah, I guess the challenge is being able to describe an ability "pattern" with unmanaged types
Might end up breaking up my ability system to multiple too to make it a bit easier (buffs vs offensive etc)
If all nodes store their type it's trivial with a switch statement. How that "pattern" looks (e.g. an array, or a graph stored in an array) is up to you
I went with a graph this time since I hadn't done it before and it makes it possible to design more complicated abilities
e.g. something like an If-else node is much easier to parse in a graph than in an array
(during authoring)
Yeah graphs do sounds like a good thing to use, as it could be used for various things (life-time, acceleration, etc)
Yep I plan to (hopefully) reuse the entire authoring part for other graph stuff (e.g. AI)
Actually, unity has said a lot about 2D support in graphics. It aint coming any time soon.
Then at least give me the 2D components as companion objects
The graphs you're using. Is it some type of package? Or is it built-in already
It's the experimental graph view UI elements stuff from Unity
it's what shadergraph uses
I see
scroll up and you'll find my hybrid folder. Works with any monobehavior on any game object. Only downside is that it requires 2 gameobjects per entity. One converted and one prefab. And no picking of course.
Works with sprites both in runtime/play mode and in editor/scene view. With the subscene open and closed. Works with tilemaps and more. Only restriction is that it's entity authoritative. There's no GO -> Entity transform communication.
I followed this tutorial, and adapted the parts I needed. I thought it was pretty well explained: https://www.youtube.com/watch?v=nKpM98I7PeM
That's fine, I'm currently just writing all my client side rendering updates from inside systems, saving the GO references on a managed component
Yeah that's the one I'm watching. I was thinking of trying a method of using curves to define the behavior of my abilities too (slightly more mathematical), but should be able to be represented well in 2d arrays
like animation curves but for other types of behavior of an ability as well
I scrolled really far but I can't find it ๐ฌ
Pulled straight from my current project. It has some netcode attributes so just delete them if you're not using netcode.
heh. Thats what I call all my bakers.
Now I'm tempted to rename mine to Oven too. Mine are just called Baker 
I started with baker but the autocomplete always mis-selected the proper class name.
I only scanned it quickly, is there a reason why the MonoLink isn't the ICleanupComponent?
You'd need to check for destruction against something like Simulate though
Simulate only matters inside the predicted loop of netcode (assuming one does not do something with simulated themselves).
Ideally you wont be destroying something inside prediction as there's no rolling pack of destruction anyways
I mean checking for destroyed by doing WithAll<MonoLink>().WithNone<Simulate>()
And having MonoLink be the ICleanupComponent and get rid of TransLink
MonoLink only contains the reference to the game object. The cleanup component is TransLink which contains the array index for the UpdateLinks system to clean up with.
I mean, yes you can merge translink with monolink...
And then track destruction off simulate.
Just wondering if there was a reason you split them, I guess your version is cleaner than checking a component that may not exist on the entity
(although Simulate should usually be on the entity)
Very cool though, thanks for sharing. If 2D support is really that far out I'll experiment with this ๐
Did they say this on the forums somewhere? Just wondering
The last dev blitz. Asked a lot about the 2D support. They near universally said it aint on the roadmap for the next year and more. One said to make a custom hybrid format as companion GOs are getting axed / deprecated. So I threw together that folder above.
Good to know I won't need to keep up my hopes ๐
Nobody plays 2D games nowadays anyways...
Something I was also wondering when looking at the code @robust scaffold , is it better to use WorldUpdateAllocator instead of Temp when working on the main thread? I've not used WorldUpdateAllocator a lot
I guess it will better "preserve" the temp memory pool for use inside jobs? ๐คทโโ๏ธ
If you're re-using the same buffer a lot, I prefer WUA because it allows for the re-use of the same buffer space without reallocation.
Here's the revise version using your suggestions. Seems to work. Nothing exploded.
For the record I thought it was fine before, was just wondering ๐ Thanks for checking it out though!
I thought it was a great idea as well, removes 4 bytes off each entity using this component.
Looking forward to trying this out, since I have a few client side rendering stuff that is "part" of the sprite, but since I currently don't have entities on the client for sprites, it makes reading and writing that data a lot slower than it needs to be
Codegen?
That is code-gened I believe
this is the codegen result
Composite = true?
Epic programmer moment when you crack the 10k lines
yeah
this might be my solution
hmm didn't change anything
what are you trying to network? FixedList?
i just want to serialize a 512 KB packet nicely
so i'm going to remove all substructs and at a minimum use longs
[GhostField(Composite=true)] did nothing?
Try putting it onto the field as well.
let me restart and force a recodegen
Wait no, this is for specific overrides.
hmm now it wont even generate into the temp folder
You have to change something inside the component for it to show
runs fine
still the same 11k file
I think you might need to write your own serializer.
i did
the source gen? Then why would it produce this?
yes
It should produce whatever you put here and nothing else.
the actual serializer is just this
this whole other part is the has changed
load from backup
etc
part
i'm not sure what you're expecting? it has no subtypes
this is a custom ghost template
not a variant / subtype
Is it still generating the 11k lines of change filter? Or have we moved beyond that?
it is
would you mind sharing the serializer, I want to try something
Thanks, give me a min
i basically just need to custom implement these methods
since all i did was the serializer/deserializer
mimicking the fixedstring implementations
oh yeah definitely i see, fixedstring uses 32 as a base and then has overrides on a few methods
Yea, i'm trying to override the change mask calculator
using fixedbyte510 because I dont want to make a fixedbyte512
oh i just did it
public unsafe bool Equals(FixedBytes512 other)
{
fixed (void* ptr = &this)
{
return UnsafeUtility.MemCmp(ptr, &other, UnsafeUtility.SizeOf<FixedBytes512>()) == 0;
}
}```
via IEquatable<FixedBytes512>
oh
public void CalculateChangeMask(ref Snapshot snapshot, ref Snapshot baseline, uint changeMask)
{
#region __GHOST_CALCULATE_CHANGE_MASK_ZERO__
changeMask = snapshot.__GHOST_FIELD_NAME__.Equals(baseline.__GHOST_FIELD_NAME__) ? 0 : 1u;
#endregion
#region __GHOST_CALCULATE_CHANGE_MASK__
changeMask |= snapshot.__GHOST_FIELD_NAME__.Equals(baseline.__GHOST_FIELD_NAME__) ? 0 : (1u<<__GHOST_MASK_INDEX__);
#endregion
}```
huh
well, you wouldnt need sizeof fixedbytes512...
but I guess that's for future refactoring.
it's true but i am considering changing the size of this
to 256
i dont know what packet size i want
Why not sizeof(FixedBytes512)?
habit
though in this case i already chagned it
{
fixed (void* ptr = &this)
{
return UnsafeUtility.MemCmp(ptr, &other, sizeof(FixedBytes512)) == 0;
}
}```
write after i pasted it
^_^'
I've been using sizeof() rather than unsafe utility... ah. Okay. Thought I was doing something wrong
but i always just use utility
as it avoids need of unsafe
but i already have unsafe here
I just tack unsafe onto the parent class / struct so I have access to all the pointer goodies.
all SizeOf is doing is wrapping sizeof()
i'm slowly removing pointers from my libraries
I thought SizeOf<> also resolves generic types?
public static int SizeOf<T>() where T : struct => sizeof (T);
oh wait, regular sizeof can also do so
what was that catch with sizeof() instead of marshal.sizeof<>()?
no idea, what's an efficient way to make a hashcode of this struct
i feel like burst has a tool for this
oh wait no that was just for hashing a struct
hashwide for the 4x structs.
I dont think mathematics has built in md5 generators
this.offset0000.GetHashCode(),
this.offset0016.GetHashCode(),
this.offset0032.GetHashCode(),
this.offset0048.GetHashCode()));
hashCode = (hashCode * 397) ^ math.hashwide(new int4(
this.offset0064.GetHashCode(),
this.offset0080.GetHashCode(),
this.offset0096.GetHashCode(),
this.offset0112.GetHashCode()));
// .. etc
return (int)math.hash(hashCode);```
that is disgusting
I guess it works. I would get a pointer to the header byte then cast to a uint4x4 then hashwide a for loop of 512/4/16 (=8).
C:\dots2\Packages\com.unity.netcode\Runtime\SourceGenerators\Source~\NetCodeSourceGenerator\Generators\NetCodeSourceGenerator.cs(95,1): error NetCode: GHOST_IMPORTS is not a valid fragment for the given template at Unity.NetCode.Generators.GhostCodeGen.GetFragmentTemplate(String fragment)
i don't even have GHOST_IMPORTS in my template
oh
i guess i need it
hey file is down to 32KB
a nice 559 lines
share for the class?
well, both is good
very nice
let's see if it actually worrks
my originally implementation just used a byte dynamic buffer but obviously that's not great
hence it was just a quick first pass and i'm trying to properly implement it now
hmmmm
does not work
Failed to decode ghost 473 of type NetworkPacket(4), got 4185 bits, expected 4231 bits
what'd i do
What line did that error come from?
cant tell
only getting the sink
either going to be 1173 or 1178 ghostreceivesystem
wait no thats fine
it seems to serialize and deserialize fine
What's the max size of packets again? 4kb might be pushing it. Or there could be plenty of room
1636 or something like that for unfragmented
16kb for fragmented
i had no issue pushing this via a 512 length buffer
and on my testing i could push up to about 9kb entities
before it broke down
(it breaks down in transport not in netcode)
512 was meant to be way below the limit
it is failing though on the writing part though