#archived-dots
1 messages · Page 131 of 1
yes
NICEEE, this information just saved my day 🙂
Does SetComponentData also need ECB? only if you need to wait for an ECB to create the entity. Else you can just use SystemBase.SetComponent(Entity)
weird, with hybrid v2 when you select a companion light in the debugger it gets disabled automatically 🤔
Is there a guide on Burst? Some systems give me the error that I can't use the Burst, what should I avoid to use it?
cant use it with managed types, ie gameobjects or anything derriving from monobehaviours/unity objects
burst package docs(all packages have their own docs) probably worth checking out, pinned messages here has links or you can view it inside the package manager
Ok ty
Entities Offsets 0.8 >> 0.9 https://www.diffchecker.com/wCYn5iP9
Lets say i need a system which executes a action once and not every update... how could i achieve this ? Is there something buildin ?
@stone osprey there is a term called "tag" which is Component without any data in it, you query for this component, and after you are done with your action remove that component
its very useful for UI and such since you have to instantiate and destroy them
@opaque ledge Thats great ! 😄 So basically events but instead of a event handler we simply use a component
Just for my little ecs knowledge... would it also be possible to use a eventhandler for this ( System registers as listener, switches bool, executes action, switches bool back ? Or isnt this possible due to multithreading ?
hmm, i mean if you are doing this for per entity, and you are instantiating/destroying them on runtime then that wouldnt work
im not entirely expert tho, there are plenty of people who is more experienced
I mean something like this... server sends a "spawn" event... eventhandler posts this event... system listens and executes its update method once 🙂
Thats a more system relevant event instead of a entity event
yeah possible, never tried tho, i am a peasant
why cant you just do it in peasant's way xD
Well me too ^^ im trying to determine all of my possibilities before i actually implement this 🙂
you can make your system update only when specific entity exist
I have updated some packages (Collections, Hybrid Renderer and Entities) to the latest version and this error appears: https://pastebin.com/BMc1Dzgn
All my packages are updated
i guarantee that some of your package is downgraded
just check them
oh wait
this is dots editor
Yeah
i recall that there is some compatibility problems with this package right now 😅
and it is kinda useless and you don't really need it, so just delete it😂
Sorry for the bad quality, they release updates for packages that are not compatible with each other?
didnt' somebody mention earlier com.unity.dots.editor shouldn't be used?
Hey, where is the Transforms package?
and it is kinda useless and you don't really need it, so just delete it😂
@warped trail I have the checkbox to easily convert a Gameobject to an Entity ☹️
no checkboxes for now 😅
I can't find it in the package manager
because it is part of Entities package
Ok
Anybody get null references when they call EntityQuery.GetSingleton<T>()
NullReferenceException: Object reference not set to an instance of an object
Unity.Entities.EntityQuery.GetFirstArchetypeIndexWithEntity (System.Int32& entityCount) (at Library/PackageCache/com.unity.entities@0.9.0-preview.6/Unity.Entities/Iterators/EntityQuery.cs:868)
In the last update (0.9.0)
doing some naive perf testing here with hybrid renderer v2 + dots physics
what's funny is that if I force worker count to 2 on my 12 core cpu, I get way better perf, can actually utilize most of the gpu
with default 23 workers the gpu sits around 60%
with less workers my frametime is 2.2ms and unlimited is 4.1ms
can't install any burst package higher than "1.3.0-preview.7"😕
have you tried to choke you cpu?🤔
with some insane amount of dynamic objects and joints 😅
running physics with 333Hz atm
and 30 vehicles (meaning 140 prismatic joints in this case)
and 150 rb's
I guess the physics callbacks don't help either :p
but yeah, I was wondering why it ran almost as fast on my old 4 core with weaker gpu
I mean isn't that really just showing that it isn't a fully parallelable problem or solution?
just out of curiosity, are you using a lot of joints with small amount of constraints, or less amount of joints, but with a a lot of constraints in each?🤔
more cores mean more parallel work not really more of the same faster
yeah, I guess I need find the max cores where there's still benefits
instead of letting the job system to decide
32 cores, 50% parallel only shows a 2x factor of speedup
but in that case it still is showing speedup 😅
the max cores is going to be variable always as your workload of parallel work changes, thats the whole point of a job system
the solution should be to bring more work to the job system so the scheduler does better work with the load it needs to distribute (which all have dependencies)
on my xp, stacking parallel fors will only reach about 70% scalability
to reach 90%+, you need to overlap everything a lot
so maybe streamed parallel fors (start next parallel for before the last one is truly finished), and overlapping 2 streams of jobs
and maxes out vector instructions
incase you were wondering where the chart was from
So came across a thought, when you're scheduling new jobs with SystemBase etc, have the previous frames job been completed for that system when you're running it's OnUpdate, or could they still be running by worker threads as you're scheduling next frames jobs?
unless somethings changed recently they ensure all sytem jobs are completed each frame.
Yeah, all jobs you schedule in a frame are completed before that frame is over
Hmm, ok so you're ok to clear e.g. NativeHashMaps from main thread, and don't have to run a job to do it.
That's fine
I think I heard a bird say something about .Clear(JobHandle) coming, so you can schedule a Clear to be done after a jobhandle
i think it only calls previousjob.complete right before running onupdate in the next frame tho so dunno about before that frame is over
are you sure that all jobs are completed?🤔
@hollow sorrel Isn't the sync point in the ECBs supposed to do that?
ah yea cuz of syncpoints i guess so
AddJobHandleForProducer will complete your job yes, but what about other cases?
I think I read somewhere that systems will save the previous frames output dependency and use it for input, but not sure if it calls complete on it as well.
private void BeforeOnUpdate() // Unity.Entities.SystemBase
{
BeforeUpdateVersioning();
_JobHandle.Complete();
_GetDependencyFromSafetyManager = true;
}
Hey, how does input work in ECS?
hi, you check for Input in OnUpdate method, then schedule a job if true, do nothing if not etc.
Ok, maybe I should have been expecific. How can I get input with the new input system in ECS
basically same with MBs, except you initalize your inputs in OnCreate(override) method, then do your logic in OnUpdate
This is outdated, there is no InputAction in UnityEngine.InputSystem
The point is the Input System is not directly integrated with ECS. You have to get your input on the main thread then go from there, like Curly said
If you want to learn how to use the Input system you should google it or ask in another channel
@fast grotto
protected override void OnCreate()
{
//Init Input
InitializeInput();
}
private void InitializeInput()
{
var inputActions = new GamePlayerInput();
inputActions.gameplay.Click.Enable();
inputActions.gameplay.Click.started += ClickPerformed;
inputActions.gameplay.Position.Enable();
inputActions.gameplay.Position.performed += (x) => pointerPos = x.ReadValue<UnityEngine.Vector2>();
}
protected override void OnUpdate()
{
var localClicked = clicked;
Entities.WithAll<CampaignPlayerTag>().ForEach((Entity entity) =>
{
if (!localClicked) return;
}
}
Basically
The reason i do localClicked instead of doing If statement right in OnUpdate is because Editor doesnt 'build' that ForEach lambda, so when first time hit a click it 'builds' which takes 5 seconds or smth, which kinda becomes annoying everytime i press play mode, but in build it doesnt matter
What is GamePlayerInput?
probably generated class
InputActions it the automatically created class from the new inputsystem
Yes, its genetated class from new input system
UnityPhysicsSamples/Assets/Common/InputActions.cs
// GENERATED AUTOMATICALLY FROM 'Assets/Common/InputActions.inputactions'
@fast grotto if you have not used InputSystem before , better to just use it first in mono/go setup and then get going from there in ECS
You should check out how new input system works if you never worked before like Sark said
Was NativeQueue<T>.Concurrent removed?
AsParallelWriter @sonic oyster
i'm getting error the type name Concurrent does not exists in the type NativeQueue
@safe lintel what if i want to use .Dequeue?
i need both read and write
dequeue should still be the same
how are you using this?
{
QueuedBlock block = blocks.Dequeue();
chunk[block.Position] = block.Data;
}
i need to have both read and write at the same time, reading in job, writing out of it
were you able to do that with concurrent?
no idea
never had my hands on concurrent nativequeue, that's why i asked
since google pretty much yields that on my face
not sure if you can? if theres another way im not familiar with it
You can only write in parallel. If you need to read/write in parallel you can use a NativeStream
heh, i guess i'll just change NativeQueue to Queue and copy it to NativeArray + Clear everytime i want to read it
OOoooh, okay!
thanks!
after fixing one physics script from physics samples (it used componentsystem so no burst), I'm now at cpu cost of 2.1ms with 1 worker thread and 2.7ms with 23 worker threads 😄
at least it's not twice worse with more workers like initially 😄
I tested this to gradually going worse the more workers I allow
1-2 workers well somewhat the same, after that it declines in perf
at least I can simulate again in the editor now, with the earlier version, this amount of physics objects made the editor crawl
what I do wonder is why is this here even when I don't have physics debug visualization script on the scene:
they do that in editor always?
if (m_DrawComponent == null)
{
GameObject drawObject = new GameObject();
m_DrawComponent = drawObject.AddComponent<DrawComponent>();
m_DrawComponent.name = "DebugStream.DrawComponent";
m_DrawComponent.DebugDraw = this;
}```
maybe it is in the build too?😅
I just put return to it's OnUpdate to get bit further here
I dunno, I mainly have physics world build and steps being the biggest costs here now
it just parallises this work like sh*t
it literally works best on 1-2 workers
all further threads just make it slower
same happens on hybrid renderer v2 as well btw
does physics's step solver iteration and thread count make any difference?
there is one thing to note and it's that my cpu does give higher clocks for workloads that only load few cores
if it loads all cores, base clock drops a bit
but it's not by huge margin
we are talking about 4.2 Ghz on few cores dropping to 4.1 GHz on all cores
oh, I totally forgot it had that thread count hint
I'll play with it 🙂
thread count hint doesn't seem to have much impact either way
(at least when I'm running this with all workers enabled)
it feels totally the same regardless what I put there, same framerate in the editor always
tweaking solver iterations doesnt change anything either (other than making the workflow lighter or heavier)
it's still performing the best with as few workers as possible
it does puzzle me that same happens with hybrid rendering as well as physics
I'm guessing with so few objects in the scene, you just pay for the overhead of having more workers
I still would have expected to get some parallel gains though
there's also a lot of sync points here that can't be avoided
you talking more about physics or rendering too?
same thing happens on both unity physics and hybrid rendering v1 and v2
both perform the best with 1 worker than anything more
I currently have like 500 physics objects on the scene and it still goes like that
there's some huge fixed costs that are really quite nasty
i was looking at their bvh a while back, and i dont get why they don't make it dynamic instead of rebuilding it every single frame. just put a guy on for a month or two.
I'll see how this goes after I keep adding more of my own systems to this, right now it's pretty much built on stock physics components + one system which I already converted to systembase + burst
pretty sure the rebuilding is because they want it to be stateless and always built the same way
that doesn't necessarily mean there couldn't be ways to update it in deterministic way using other approaches tho
one thing that physics engines can do to parallelize work is to run these sims in split islands
right, its the easy option for sure. but at what cost.
but I dunno if that's a no no for the determinism as well
do note that this test level is mainly filled with dynamic objects, only few static objects here (which is not how game levels are usually at all)
are you using subscenes?
none
should it help on this?
these things I'm using are not really compatible with dots subsenes at all
no probably, i mention it because the scene loading systems add quite a bit of extra time.
also found out that there's a small cost of simply having Havok Physics package installed, even if it's not enabled from the Physics Step script 😄
pretty sure that cost was bigger in past
ive been struggling to figure out why my AssetDatabase.Refresh on 2020.1 is so damn slow
i have to wait like 2-5 minutes sometimes. 😢
I have no idea why this doesn't work:
public class InputSystem : SystemBase {
Vector2 direction;
protected override void OnCreate(){
Inputs inputs = new Inputs();
inputs.Controls.Move.Enable();
inputs.Controls.Move.performed += context => direction = context.ReadValue<Vector2>();
}
protected override void OnUpdate(){
Entities.WithAll<Translation>().ForEach((ref Translation translation) => {
translation.Value = (Vector3)direction;
}).Run();
}
}
I get this error:
Entities.ForEach Lambda expression uses field 'direction'. Either assign the field to a local outside of the lambda expression and use that instead, or use .WithoutBurst() and .Run()
outside of the ForEach var dir = direction; and then just plug dir into the translation
I can't do that, I am setting direction equal to the result of the inputsystem action
eh this is what I mean
protected override void OnUpdate(){
float3 dir = direction;
Entities.WithAll<Translation>().ForEach((ref Translation translation) => {
translation.Value = dir;
}).Run();
}
so let's say I'm trying an event system concept where a system can register a struct as an event (with a central EventSystem that maintains a NativeStream) and receive a nativestream.writer back. It writes its event struct to the stream using the writer. How can I convey Type information so that the EventSystem knows how to Read<T>() it?
Any quick way to reset NativeArray to all 0?
UnsafeUtility.MemClear
Im just now learning about different compilers, it turns out I'm stuck with Mono, will DOTS suffer much? Does Burst work with Mono? Or only il2cpp? Am I talking nonsense?
Is anyone using dots networking for a game?
@toxic mural yea burst should work even if your build is mono
but burst compiler has nearly same requirements as il2cpp so usually if you can do one you can do the other
why are you stuck with mono?
@hollow sorrel ty for the response, compilers, llvm, il2cpp, its all beyond me. I just want to make sure I"m not gimping performance by not checking the right option. I'm bound to Mono because my modding asset (UMod) requires it (I think because of reflection)
ah in that case yea mono+burst should be fine
burst code gets compiled seperately and would still be supafast
only your burst compiled jobs would get the gainz tho
thought i'd mention that just in case
yeah like as I'm learning more about jobs/parallelism I think I'm going to go full DOTS, force modders that want to mod my game to have to learn ECS
doing my part to evangelize The New Way
sounds great but just note that if you're talking about code mods, modders won't be able to utilize burst since it only compiles in unity editor
that said if it's mods you prob don't need burst performance in there and ECS code in mods should work fine
did a small test with creating+importing dll's at runtime with systems+components and seemed to work at least
Thats cool. It took me months to find all the gotchas and figure out workarounds to be able to load ECS types at runtime. My main pain point was some unity Editor scripts that called TypeManger.Initialize() super early, so things were solidified in place, before the assemblies were able to be loaded
But it was also a good learning experience
ya i can imagine that
prob doesn't help that there's a million assemblies to keep track of too
entities, transforms, math, physics, collections etc
and their .hybrid version
The assemblies werent so bad, I mean I understand if something is in an assembly, code needs to be able to see it somehow in order to call it. Mainly for me it was trying to figure out by looking at the Entities source, like what is this "codegen" thing? Why is TypeManager being called? And half the time it would freeze instead of hitting my breakpoint
What are you doing with DOTS?
ah yea
i don't remember having to use typemanager but i forgot there's no codegen at runtime either
gotta write everything out
feelsbadman
i'm just making a metroidvania platformer but the runtime loading ECS dll's was a seperate thing just to see if it was possible
you¿
lol, every third person in the gamedev forum I hang out in is making a metroidvania.. no offense, its just funny to see the tradition is going strong even outside agdg
Im trying to make a hacking sim but its taking me forever
a metroidvania or some kind of waifu simulator
lol yea i get whatchu mean
when i started it was just meant to be a small platformer thinking i'd be done fast but that was 2016 so
riiight I know that feelerino
but ya i don't wanna clog up this channel with non-dots talk so lemme add you and i'll ask more bout your game later, gonna go sleep for now
Yeah good point, later
Do you guys think its better to split the archetype into multiple entities ? lets say i have a spaceship, i have 3 'sets' of archetype, first set is about movement, so 2 components for where to go data and speed data, second set is about AI, around 3-4 components for that, 3rd set is about defense/offense modules, so ships stats basically, i also have 3-4 components for that, they are all in the ship entity, so i was wondering if i should split them up.
Does it really matter ? are there any advantages/disadvantages to split big archetypes ?
I think this would be a question of chunk optimization vs codeability
By splitting them up, you'll have to think more about how you organize your ships etc. It might also be harder to query a ship if you want data from multiple of those parts that are on different entities.
For example I have a Collided component that is added to an entity when it collides with something. Should I add the component or should I put the component on the entity by default and when it collides I change the value of a bool variable inside the component?
Adding a component to an entity changes is archetype, so maybe it's slow
(Sorry for my bad English)
Add/Remove component Vs change bool variable
@fallow mason Look at DebugStream
@wide fiber Thats the question of the century 😄
but for ECS sake, go for add/remove components
@wide fiber btw, code for fixed step i link you before is not working correctly😅
It's working
I have made a debug.log where I display the "delta time" between calls (I store the last time the function is called) and it's correctly displaying the value
What's the problem?
when you press play, it will update a lot of times, before it starts to work correctly 😅
Ah... Well I could make an IF to check if Time.elapsedTime is greater than 0.1s for example
there is considerably big gap between application start and first update
system thinks that there is BIG delta time and updated a lot of times😅
Ok
But elapsed time starts increasing on first update or when the application starts?
at least on my machine and project first elapsed time is 0 and next is 0.02
and then 0.2 😅
just take this into account 😅
Ok.. on my machine it's working correctly
and Unity's default Maximum Allowed Timestep takes care of this problem sometimes🤔
How can I get OnTriggerEnter/... events from UnityPhysics (ECS)?
I have read near all the documentation but I can't understand how to "get physics events"
Thanks
Is it possible to get a entity query outside a system ?
@warped trail ah, thanks for the resource. I was trying to do something where EventSystem maintained a List<Type>, because I would like it to be dynamic. But was having a hard time passing in the Type to Read. Looks like the list of types might need to be fully defined at runtime.
Any quick tipp how i can run a entity query outside a system ( Monobehaviour for example ) ?
I think you have to use systems to access entities
Its for my UI... i basically need to find the local player for displaying his stats
You have to do it the other way
Have a system that queries for the entities, and then sets some data on a MB
Damn... is this the only way ?
Well why is that such a big problem?
Systems are able to communicate with mb's but not the other way around ?
Well
MBs can communicate with systems
But not entities
Maybe you could do it through a job
But then I'd just keep stuff in a system anyways
Why is it such a big problem?
Because i generate some screens at runtime... ( leaderboards e.g. )... every leaderboard screen its a own instance and hooks itself into my selfwritten UI - Management for screens... and im not into code generation for c# to generate systems for each of those runtime generated leaderboards... so it would be a lot easier if i could simply run a query for each of those screens to find the player stats.
Why does it matter which way the data comes from?
The leaderboard can just read the data from any list on a MB
And your system can set that list as well
you can create query via EntityManager
But can you actually access the components?
@warped trail The only query i saw in the entity manager is the universalquery... that query returns all entities... or did i missed something ?
var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(Translation));```
@warped trail Thanks ! That solved this problem 🙂
but i don't think this is a good idea 😅
i know that lateupdate is between simulation and presentation groups
Well, I could always just use the ED and show the full player loop lol
yes
Yeah
I guess it makes sense
Considering this is using the UnityEngine runtime
And not the DOTS Runtime
Which will be vastly different
i wonder how much years will pass before DOTS Runtime for regular unity 🤔
Well Tiny already works
but Tiny is like another engine🤔
Exactly
so what is the plan, will they change engine to integrate DOTS Runtime, or will they slowly develop DOTS Runtime and port everything from unity?🤔
My speculation is that they will offer both within the editor they have
They might need to rebuild the editor though
For now, they're full on with the whole "GameObject authoring, DOTS Runtime" approach
so we will have URP HDRP, Tiny URP, Tiny HDRP ? 😅
Probably not
I think they'll move more resources to DOTS
But over time
So yes, for now we will have URP and HDRP
But the DOTS renderer will come at some point
And then URP and HDRP will be only maintained for DOTS
But that's faaaaaar off
what everyone mean by DOTS renderer?🤔
HybridRenderer
Right now the renderer isn't running on systems
It's not jobified either
At least I don't think it is
so by pure DOTS renderer you mean that there will be something new in engine?
Oh btw... do we need unity 2020 to use HybridRenderer v2 or is there a trick to obtain that version on Unity 2019 ?
Nah you need 2020.1
2020.1.b3+ only
Thats a pitty., thanks :/
it is basically not working, so no pitty 😅
Has anyone had a trouble with working with cameras, because of a some weird reason the gameobject that i injected transform's working properly when i see it on inspector, but doesnt actually work when i do Debug.Log on OnUpdate for camera gameobject's position
and i have CopyToGameobject component as well
http://prntscr.com/rx9ip3 This on inspector
http://prntscr.com/rx9iud This on console
Like.. it only show gameobject's inital position, it doesnt update it
except when i rotate...
sigh
Im sorry... i have no clue, i just started like 3 days ago with unity dots
dw 😄 probably no one knows whats going around
Soo im not allowed to use NativeArray or NativeHashmap in a IComponentData, right ? What else i could do to store item-id's in my inventory component ? 😮
You can add a buffer instead of a component
Thanks ! So i guess i need one component as a dynamic buffer and a other component as a buffer element ?
no, buffers means IBufferElementData but when you query for it you do DynamicBuffer<YourBufferElement>
oh wow
I was wondering why I can't get packages anymore included on my vs solution despite I've moved even main dots packages under packages folder
turned out they revamped the system for this on 2020.1 (probably on b5 since I don't remember this failing on b4):
they just disabled everything out of the box
I hope I can now generate the projects for solution even without the "move from packagecache to packages" hack
huh, i was wondering the same thing, i copied entities to /packages/ and it didnt show up in vs
yeah, you need to go enable those again
but hopefully it actually now works from package cache 😄
I only need to modify unity physics package, rest I can keep on regular library cache just fine
odd, my external tools doesnt look like that
are you on 2020.1.0b5?
yep
weird
it probably doesn't help you either when I say this seems to work splendidly now 😄
oh I know what it is
haha
go to package manager, update your visual studio package there
I updated that yesterday, so it must be it
they dont have a changelog entry for the latest version 😅
hold my beer
## [2.0.1] - 2020-03-19
When Visual Studio installation is compatible with C# 8.0, setup the language version to not prompt the user with unsupported constructs. (So far Unity only supports C# 7.3).
Use Unity's TypeCache to improve project generation speed.
Properly check for a managed assembly before displaying a warning regarding legacy PDB usage.
Add support for selective project generation (embedded, local, registry, git, builtin, player).```
this is rather old still
but it's not there by default
I had 2.0.0 installed on my end
nice, thanks!
hmmm, the changelog says 03-19
package manager says the packge is from 1st April
so yeah, it's this: Add support for selective project generation (embedded, local, registry, git, builtin, player).
best part is that it has that regenerate button
no more project restarts and praying it finds these 😄
can just keep smashing that button
now I can navigate to packages easier again, yay
didn't immediately give me solution to thing I was wondering about
I'm currently using FixedRateUtils to update physics at fixed rate
there's EnableFixedRateWithCatchUp and EnableFixedRateSimple
I just wanted to know what the catchup does here in practise but the <summary> is same for both of these entries
so it will mean the docs have same description for both too
I'll just compare the implementations then
yeah its been such a hassle dealing with finding the right source i've ended up relying on ILSpy with a VS plugin that lets you get to the decompiled source from context menu (i guess resharper/rider would do the same)
most of the sources are there for dots packages tho
and now that it's easier than even to include them on solution, can just navigate through without hitting metadata (unless you go to engine side dlls)
@dull copper EnableFixedRateSimple just makes your Time.DeltaTime fixed, systemgroup updates as always every frame. FixedRateWithCatchUp makes your group update in fixed steps, group updates every fixedStep and if delta time is big your group will update multiple time
but FixedRateWithCatchUp is bugged, you will probably get infinite loop if you make your group FixedRateWithCatchUp from very start of your application
yeah, I've seen that
@fallow mason if you want to look at a simple events system that does a list(/queue) thing like your idea check this out for some ideas https://github.com/tertle/com.bovinelabs.entities
{
UpdateAllSystems();
}```
@warped trail if EnableFixedRateSimple works like that, it's not named properly at all
what's the point of it even?
EnableFixedRateSimple is not named properly and other one is bugged 👍
and you have to take into account Maximum Allowed Timestep
they don't seem to have any failsafe in this either
unless I'm missing something
meaning if you run this on low end system that can't keep up, it'll starve the cpu to point where it'll just crash
How do i set a buffer element with specific values ? Do i really need to call "entityManager.addBuffer<>(entity);" and than finding my added element in the list for modification ?
@warped trail yeah, that's what I was getting into, it doesn't seem like it's taken into account now?
@dull copper no it won't starve
Unity's default Maximum Allowed Timestep will kick in
Thanks, @mint iron . I've see tertles repository, but didn't look too deep into it because it seemed he was using Icomponentdata on event entities and I'm trying to do it via native containers. I'll take another look.
where do they have this check?
but you will get interesting results with this type of thing in the beggining of your game https://pastebin.com/af7tRkat
@dull copper somewhere in unity's internal systems 😅
your world is in default player loop
but this doesn't actually use the fixedupdate loop
but i guess it is not guaranteed to kick in 😅
all I see is this on ComponentSystemGroup.cs cs protected override void OnUpdate() { if (UpdateCallback == null) { UpdateAllSystems(); } else { while (UpdateCallback(this)) { UpdateAllSystems(); } } }
so if it really uses that while until all fixed updates are done, it can starve
not sure if I'm looking at the right place tho
it will take big delta time, update a lot of times
basically it will look that callback as many times before it's done all fixed timesteps
then unity will see that your frame time is too big and make it to Maximum Allowed Timestep
in next update your group will take Maximum Allowed Timestep as delta time
if you have a weak system that takes more cpu time to runt he update all systems than what your fixed timestep is set to, it'll starve
Maximum Allowed Timestep only applies to fixedupdate loop
which isn't used here
you can check it yourself😅
yeah, I can
one sec 😄
I'm pretty sure it doesn't work tho as I've been at like 1fps in the editor and it's totally unresponsive when trying to find a limit
hmmm, it does do something
not what I'd expect tho
setting max allowed timestep to 0.01 still renders 12fps in the editor (with 10kHz fixed update rate), it should cap it to 100fps
Okay so... about that camera thingie
i have this functions on my game state singleton:
private unsafe void Update()
{
Debug.Log(campaignCamera.transform.position);
}
public Ray RequestRay(Vector2 vector2)
{
Debug.Log(campaignCamera.transform.position);
return campaignCamera.ScreenPointToRay(vector2);
}
RequestRay is called from my movement raycast System.. and guess what ? those debug.logs shows different, Update Debug.Log always shows corrent but Debug.Log in RequestRay only shows initial value of the camera and doesnt update when camera moves
I have no idea what this is
setting max allowed to 0.1 (so it should cap the update to 10fps) and it just starved the cpu and whole editor is unresponsive
and I cant revive this now 😄
need to kill the process
so the value clearly affects something but it's not doing what one would expect
this is my naïve fix https://pastebin.com/QEiHyESJ
yeah, you should have max timestep somewhere in the equation
feels super shortsighted that they didn't do it
i added it just so i don't have to set UnityEngine.Time.maximumDeltaTime to fixed delta time🤔
setting UnityEngine.Time.maximumDeltaTime fixed my problems😅
I've done a system in past where you can temporarily go past the max time, basically made a system that lets you exceed the threshold for set amount of times that cumulate if you keep going past it, when it comes to max then it hard cuts it, also when it starts to catch up, it lowers the counter on this cumulative buffer
I did this on unreal where I found that sometimes on spawns etc, you got a small spike on deltatime and it could miss some fixedupdates
this broke the determinism on my test level
so letting it temporarily exceed the max time helped there
this is what happens in unity right now btw 😅
of course this will throttle on low end cpu
there is small spike at the begining
and your fixed system is like Holy shit i have to catch up 😅
but if it's really starving, it'll just never get past the cumulative counter and it'll appear like regular hard cut
and than unity is like, holy shit delta time is big, lets cap it
yeah, that's pretty much what happened on unreal too
I guess the right way to prevent that specifically would be to just start the fixedupdate updates bit later
like, don't update any physics until everything else is loaded
and me be like, why the hell it spawns object 8 times, when it supposed to spawn only 1😅
i was doing debugging with paper and pen half of the night 😂
i might have to address this soon, i have some gravity like effects, and it looks rediculous when things are falling too fast or slow.
and i hate that opened subscene and closed one are not behaving the same way😕
one day i was playing with collision and trigger events and was getting more events than expected, that day i found out that opened subscene is messing with update loop 😕
it's such a basic thing to need
and proper implementation has been missing for one year now
@dull copper if i enable the first three checkboxes it generates all the projects with that new VS package but it breaks all my references for in project files (and debugging attach is broken also). Is that the same for you? Only way i could get it to work is generate the projects, then take them out of the solution by going back to just the first two checkboxes. And manually add the projects i want back in to the solution.
you have the magic touch, everything works
Hmm, updated to Entities 0.9 and getting erros about BuildStep being obsolete. Should I just manually fix them in code or what can I do?
you have the magic touch, everything works
you've read my rants here, you know that's not true 😁
@formal scaffold use 0.2.2 platforms package ?
0.3.0 doesn't work
nor does 0.2.1
(with entities 0.9)
Oh, thanks I was looking at Entities being the problem how'd you find out it's Platforms?
can someone post entities 0.9 changelog
@formal scaffold it's in it's dependencies
if you haven't installed platforms manually, it'll pick the right one automatically
can someone post entities 0.9 changelog
@naive parrot https://discordapp.com/channels/489222168727519232/497874303463850004/697862838190080031
they haven't updated the online docs yet
Is there any huge difference between a componentsystem and a jobcomponentsystem ? I thought every component system is based on jobs
@stone osprey you shouldn't use either anymore
use SystemBase
from docs: Implement a ComponentSystem subclass for systems that perform their work on the main thread or that use Jobs not specifically optimized for ECS.
(for the componentsystem)
but you really should just use systembase now
Thanks ! SharedComponents foreachs run on the main thread right ? Is there any way to multithread movement with a reference to gameobjects ? Thats basically what i use that shared component for 🙂
you can't access managed things directly on jobs
you need to run them on mainthread
also without burst
Damn... so no way for job movement till i dump gameobjects for displaying my entitys and instead go with mesh renderers ?
just don't access managed components on the jobified system, there is a small exception and it's that you can update transforms of the gameobject objects from jobs, there's a special type of job for that even
the job gains aren't often substantial tho
you need to really brute force things to get more out of it
Alright, thanks ! Well i already tried that jobForTransforms or however it was called... but i noticed that it has the same "speed" or performance as what im already doing for updating the visuals of my entities :
if you only update limited amount of things, doing it from mainthread will be faster usually
because then you don't pay for the job scheduling overhead
Thanks 🙂 guess i need to use hybrid renderer v2 instead of gameobjects... heard that one does support urp, than the multi threaded movement should also start working
same thing applies for things like Burst, if it's super trivial thing like summing up few variables, you may pay more for the interop call on burst than what you gain for it
but as soon as you add any more complex math to it, burst gains can be substantial
you need job structure to easily run things on burst (also no managed objects allowed) but you don't have to schedule these to workers (can just use systembase with .Run() so it runs on mainthread)
v2 does a minimal support for urp😏
@dull copper thanks for the log.
Thanks for the Tip with the dependencies @dull copper , makes it much easier to track down problems
@warped trail Minimal ? 😮 uhmm
half of your faces will be pitch-black😅
Question, is it possible to merge 1 entity into another?
what do you mean by merge?
With the current API that is (I can probably think of something otherwise)
Lets say I have an entity 1 with components ABC, and an entity 2 with component DE, Can I "merge" 1 into 2, by making entity 2 ABCDE and contain the data in DE from entity 1
basically getting the Archetype of the combined entity's components, updating the target entity to this archetype, then copying over the component data from the source
hmmm, I'm now getting tons of "Exception: This method should have been replaced by codegen"
the warnings all point to my own systems Entities.ForEach
The merging would be useful for "instantiating" a converted prefab entity, but on top of an existing entity
Or at least, that is my use for it
@dull copper i was getting that a lot with changing tests, i'd have to switch back to VS, add a space to the end of some random line and save to get it to trigger a recompile.
@stiff skiff i dont think there is an API method that does that.
Yeah I figured, I'll have to do some digging and build something
Probably some archetype creation and entity remapping
wiping ScriptAssemblies from library folder did make those go away
fun stuff
@mint iron thanks for the headsup
hey, I made an Octree out of my earlier Quadtree implementation: https://github.com/marijnz/NativeOctree
looks really cool, mind if i ask what CheckWriteAndBumpSecondaryVersion does (what does the secondary version do)?
Should I use Havok or normal Physics for DOTS? Been using Unity Physics so far but I just read that Havok is faster
havok can be faster on some cases but it doesn't ship with full source code + it has extra licensing cost if you use Unity Pro
@mint iron tbh I added those checks quite quickly by just looking at what checked Unity did with their containers. As for CheckWrite, it's ensuring safety in read/writes. I'm pretty sure my checks are not 100% correct though 😉
havok also doesn't give you crossplatform determinism (but nor does Unity Physics today, it's more of a thing for upcoming years)
also stateless design will be easier on netcode if you go for determinism
(havok has cache)
@formal scaffold to add to what @dull copper says, it just really depends on your project
for the project I work on at my job, we use Unity Physics
I guess so but I'm too inexperienced atm to really tell so I will stick to Unity.Physics until I know more
Unity Physics is safer bet atm
plus 1 to that 🙂
neither of these are production ready tho
unity physics is in good state though
like, the solvers in them are solid, it's just all the tooling and some systems are still lacking (like that fixed timestepping stuff we talked here earlier)
You have to code quite alot yourself but thats fine by me
been a while since I have tried using it, but I believe stacking in unity physics is still odd 😉
they improved it a bit
Since it it stateless stacked dynamic objects ... dance
but it's not going to give you buildings talls stacks of boxes
2-4 boxes should work now
of course it'll be more "alive" still due to lack of sleeping
things can drift with time
By not sleeping you mean that the Physics Engine keeps updating the Velocity of my character even when standing still yes?
Pretty much yeah, it has no concept of what happened in the previous frame
So there's a lot of implications from that, including the inability to sleep
I haven't checked what early outs the unity physics solvers have, but in general, all dynamic objects are evaluated each time you step physics
@willow creek do you have a license for that code?
I forgot to add MIT, will do now
you could implement naive sleep based on some simple counter that would count how many physics steps it's been under some velocity threshold and then omit it from velocity updates unless there's some forces / collisions to it
thanks for asking 🙂
but in general, this will not save perf as this part of the solver is super cheap to run anyway
it could help a bit on stacking tho
@mint iron done
and while it's a state, it's just an integer that is easy to set if you need to rewind things etc
2-4 boxes should work now this is not true at all 😅
really?
If you need reliable stacking then your only option is Havok I would think
Last time I tried it havok was the only solution outside of adding your own
otherwise 2 boxes would tango
Even if the boxes were to be perfectly aligned
the top one would eventually slide off
which makes things like a jenga tower (even a mercifully stacked one) non viable at the moment
Unless Havok
havok is cool😏
ah, yes, it will drift along time
It is neat, but I don't think they should do this split paradigm and then have one be feature set complete the other just a pet project (obviously not their intent)
I thought you meant like things dancing on top if stacked
It is rather speedy in its drifting
Very noticeable to the player
and not physics intuitive
It should not gain momentum if it is on a flat surface
yeah, that will still happen
Not all games need stacking. But yeah I think they definitely overstated it in some of their presentations by saying stateless physics covers the "vast majority" of games
And that statement may be true, but they may have missed that states are stored in a many games even in stateless physics
To avoid issues such as stacking
Regardless, physics is far from done as they kinda need a stable and set entities first
Which we are theoretically getting closer to
Is it normal that my playerloop uses about 10 ms of performance ? I actually dont even use that playerloop
Its the default one
Is there a way to disable that playerloop ? ^^
Or is it required to run along the other ecs parts ?
But if I understand correctly, I can just remove the Unity Physics package and import Havok without changing code is that correct?
You just change a drop down to havok
BUT
You need to ensure licensing is ok
Example: If you have Unity Pro you can not just use it.
we need breakable joints to fix the stacks from drifting 😅
looks like GC spikes
I'm still in the learning process, this is my third month, so I'm still using a free license. What are the benefits of PRO anyways?
Most of that is still the editor
dark theme😂
Dark theme is the more noticeable one
However
You also get unity support much faster
@formal scaffold Unity Plus gives practically same benefits as Unity Pro but you HAVE to use Unity Pro if your entity/you make more than 200k in revenues / year
I do like dark theme 👀
you can get free dark theme if you are a student
Unity is still stubborn about not giving it to all users for free tho
or if you are a cool hacker 😏
@stone osprey most of the wait time seems to be the editor, so somethign may be selected or debugging in view. The other portion is vsync
Still got time to get pro then will at least be another year
or TOS or whatever they call their terms
Probably don't bring it up in here at the very least
I love how Unigine free put this on the list 😄 https://cdn.discordapp.com/attachments/497872447542919179/698283454508564610/unknown.png
@solar ridge Thanks ! Guess its fine than 🙂 Just wasnt sure... never heard of that playerloop
from totally beginner point of view this engines will look almost identical🤔
how can i make authoring scripts to create the entity for a custom world ?
Mmmmmm a first thought would to make the entity as normal, but move it after conversion... but that may not be ideal nor the correct way
Im not sure how to have an authoring behavior target a world :\
@digital scarab sorry to ping you, but is there a way to make authoring component work against a specific world(custom world instead of default world) ? I am asking because you are in the conversion team 👀
but probably there is not a way, i will depend on runtime conversion probably
yeah without Subscenes
how it would work with subscenes ?
if you don't at first succeed, just fake it all
i cant see any methods related to subscenes in World
is DynamicBuffer.Clear ( ) a structural change ? causes Sync point ?
i doubt it, but if someone can confirm..
no its not
structral change is.. adding/removing components/buffers, creating/destroying entities
and when iterating in Entitie.ForEach , for write access is ref valid qualifier or it has write access by default ?
for DynamicBuffer i mean
yeah, do ref if writing/reading, do in if only reading
you used to do nothing i think in 0.5, but better to do ref
alright thanks
Is there a good place to ask for additional API's?
I'd love a EntityArchetype CreateArchetype(params ComponentType[] types) that takes a NativeArray instead. As that is what EntityManager.GetComponentTypes returns.
Its a bit odd that I need to have an allocation to have an dynamically generated archetype
Yes
I'm trying to "spawn" an entity from a converted prefab
but instead of making a new entity, I want to reuse an existing entity
That is what Instantiate is for?
Though while going through it, it seems I'll have a hard time getting this to play nicely due the the required remapping
Instantiate will make a new entity (or more if you have a linked entity group)
Oh oh. You want to do a pool like system?
Not exactly, I already have an entity here with some components
However at spawn of this entity, I don't know what prefab to use for it yet
and thus I want to "update" the entity to this prefab later
Ah so you want to mutate an entity. Got it
Realistically just using the Entity Command Buffer would get you close to what you want if I understood correctly
Both sides are bursted now. playback and queueing commands
Sadly the ECB will still create all the archetypes in between when adding components
I'm hoping to instantiate the "prefab" entity from the conversion flow, copy the root components to my existing entity, and update the links with it's child entities to now use the existing entity
Copying the components I'd like to do in 1 step (by setting the archetype to a combination of old and prefab archetype)
As the ECS does not "garbage collect" Archetypes without any entities
I hope that makes sense
@dull copper Did you do that the way you described earlier, by manually keeping track of previous velocities? https://discordapp.com/channels/489222168727519232/497874303463850004/698555129808289833
joints? 😅
i was reluctant to mention it, but if you really want to do that @stiff skiff you could with some hackery, directly change the archetype on chunks or a batch of entities, and then bulk copy the component data you need. for the new components. pm me.
@zenith wyvern @warped trail it was just a quick hack using joints, like seen on the follow up video 😄
if we had breakable joints, that could be used as workaround tho
would just need to tune the break threshold super low + redo joint when velocity slows standstill again
not a general purpose solution but could be used in some vr games etc
If I have a System that adds all numbers in a DynamicBuffer and stores the result in some ComponentData, and I want to use that same system but use a different DynamicBuffer type and result ComponentData type, is that possible
these are on the same entity, so using the exact same stuff doesn't work out
What you'd need is sth like
void DoStuff<T>() where T : IHasValue
{
Entities.ForEach((DynamicBuffer<T> buf, ref OtherComponent comp) => {
for(int i = 0; i < buf.Lenght; i++) comp.value += buf[i].GetValue();
}
}```
However the ForEach code generator doesn't support passing generic arguments as lambda args, so atm this won't work (don't know if they plan on supporting this use case in the future).
I'm fairly sure you can do this with explicit chunk iteration, but that is way more code than that.
nope, you have to make another job
well at the moment the relevant job is an IJobChunk
but yeah having to make a new job is what I suspected
a little more generic support with jobs would be amazing, though I can imagine the amount of shenanigans it could cause
thank you
Different question, do you think it'd be better to have a job run on all elements and check a bool if it should do something or not, or add a component and querying, then remove it when done, if it would be done on average once every second or so
There is no universal answer to that
I'll just benchmark it then
How can I get a job to run after a certain EntityCommandBuffer is run?
custom entity command buffer or default ?
Just run it after the EntityCommandBufferSystem
anyway 😄 for EndSim, EndInt, EndPre command buffers you cant, they are designed to be run last on their group, but for custom and Begin default command buffers you can use UpdateAfter attribute on your system class
E.g. [UpdateAfter(typeof(EndSimulationCommandBufferSystem))]
all right ty
had a play with @willow creek's octree.
is there any way to check if an entity exists wihout EntityManager.Exists()?
so i can use burst
would if(myEntity == Entity.Null) work?
oh actually probably not, because it might have been deleted
yes, its just a copy
i often need to know if the entity still exists, there has to be a better way
I would imagine if you use an ECB it would check automarically for you
it can be done
the ecb throws an error if the entity does not exist anymore
oh.
@mint iron how?^^
yeah, i had to do it becuse if you use GetComponent in Entities.Foreach right now in burst on Entity.Null it just crashes the editor. Sec, ill make some code.
i am really struggling with clearing up all my entities in the correct order:
For examle if you have something like:
- Player which can die
- Buffs are Entities and linked to the player
- Buffs have a duration and so are destroyed after some time
- Player can also be destroyed and buffs have to be destroyed with player
I am doing the destroy process with linked entity groups but the handling seems pretty complex
Dont suppose you can just put the buffs on the player entity?
sorry for the late anwer
each buff has a set of unique components, so this is not really possible
i am just wondering because in oop this is really easy to do and with dots relations between entities seem pretty hard to handle
I guess just when the buff target is destroyed, enforce that all buffs that point to that entity are also destroyed, before the buff system updates (and breaks)
@gusty comet why cant you add the unique buff component directly to player?
from what it reads , These unqiue behavior components define a 'buff'
just a thought
In cases where entities need to reference eachother (should be pretty common I would think) it would make complete sense to be able to check if the referenced entity still exists. If you can't do that in burst that seems like a real oversight
So in my game i have different Buffs (which are all separete entities)
for example:
Buff which increases speed has following components: CooldownComponent, SpeedComponent, BuffOwnerComponent etc
Buff which does damage to an entity: CooldownComponent, DamageComponent, BuffOwnerComponent etc.
Huh...from the source code for EntityManager.Exists:
// @TODO Point to documentation for multithreaded way to check Entity validity.
I don't even know what that means. Does such a way exist?
I don't even know what that means. Does such a way exist?
@zenith wyvern did not found any. There are a lot of methods to check if an component on an entity exists
That does sound weirdly worded, like there is documentation, they just havent referenced it? I think they are just assuming there is a way, or someone would know
it would be easy if they exposed some more of the internal stuff.
So just to be clear: the buff <-> player relation is working with linkedEntityGroup and some systemState Components
I am just saying that it looks REALLY complex to set up and clear the relation
@gusty comet i feel that cooldown can surely be packed with actual behavior component i.e speed , damage etc. eg SpeedBuffComponent { float maxDuration , float currentDuration , float speedMultiplier } and then they can just be put on player entity. sorry for proposing more design level changes rather than out of the box solutions. am still exploring full depth unit's ecs api myself atm
@digital scarab Any chance you could give any insight on how to check if an entity exists from inside burst/a job - IE without EntityManager?
It seems like a pretty common problem
@fleet hemlock i had this at start but then i can not iterate over all cooldowns and reduce the time.
i also have some more components like who triggered buff, can it be dispelled etc
makes sense
It looks like the call from EntityManager eventually leads to EntityComponentStore.Exists which is what actually does the check
I don't know if you can somehow access that from inside a job
oh hey how about ComponentDataFromEntity<T>().Exists ?
That only tells you if a component exists, I imagine it would not be happy if you tried to use it on an entity that has been destroyed
I mean you have to provide the <T> type but for OP it sounds like they know it'll have a PlayerComponent or something
Yeah I'm not sure there's many scenarios where an Entity is useful without a component on it that you're trying to access
I mean you have to provide the <T> type but for OP it sounds like they know it'll have a PlayerComponent or something
@toxic mural i did not know that. Maybe that does the trick, too
As long as you know a component on the entity
Keep in mind in SystemBase you can just use HasComponent directly and it's functionally equivalent
less verbose
Ok so if i want to check if the entity exists and know that a component of type TestComponent is always on the entity. I can just use HasComponent<TestComponent>(entity) and know if the entity still exists
I've never used it for that purpose but based on the docs it sounds like that's the intent
I dunno man checking if an entity exists.. seems not very ECS
i try to avoid it where i can, but for me it seems it is the easiest solution if you have an entity reference in a component
I would flip it around, instead of looking at buffs and checking if their references are still valid, I'd look at buff targets and iterate over the buffs to see which ones point to it
also i would avoid any structural changes in general. easier said than done i know. but you said its all on player. so are you straight up destroying the player when he dies hence the need to phase out all the associated entities ? i mean that would be the case in pure ECS i think but is it?
i also have a hybrid ecs setup for my action shooter. for enemies and player alike , i just keep all the associated entities alive and reset them on respawn
of course it goes hand in hand with conventional gameobject pooling
my problem is that you can have several buffs of the same type etc. so it is really hard to setup all possibilities at start
I would flip it around, instead of looking at buffs and checking if their references are still valid, I'd look at buff targets and iterate over the buffs to see which ones point to it
@toxic mural enum flags for target id i was thinking.
@gusty comet like 2 speed boost on same player?
@toxic mural also thought about that, but my enemies also have buffs and debuffs. so you iterate through alot of things which aren't event related to the player
i would just add the same buffs in a single component
@fleet hemlock yes like this or 2 shield buffs on the same target
but they both elapse at different times, so i can't but them together
umm , so they are 2 different shield buffs ?
i was thinking more like stacking
if they are identical in behavior any incoming buff of same type should just add to current counters of an ongoing buff. like for 2 second shiefl buff , you have elapsed 1 sec now u stack another with 3sec , you just add to 1 ... am i missing something?
if you can have 2 of same buffs in parallel , and they both have identical components , there gotta be atleast 1 unique attribute by design that makes them distinct enough to be in parallel right ( design wise parallel not cores )
also probably look into DynamicBuffers for lots-of-identical component kind of scenario
i think you can do it that way, too. I thought it would be easier to create a buff per entity and reuse components to configurate each buff instead of putting everything on one entity.
but maybe i have to rethink 😄
I think having one entity reference another through an actual entity reference can make sense in some cases. You probably don't want the player to change which chunk it's in just because it's buffs change
And especially if the buffs themselves might have it's own set of components, it makes sense to be able to just delete the buff entity when it expires
I think entity per buff is right, keep cooldown as separate component, not integrated into buff component itself
And especially if the buffs themselves might have it's own set of components, it makes sense to be able to just delete the buff entity when it expires
@zenith wyvern that was my thought, too
easiest solution I find is just when you do your structural change, deleting the player, you do the linked entities right then and there. with ecs you want to make your changes atomic / transactional like a db, instead of having a indeterminate state inbetween. to make this easier, you can also build a system for auto cleanup of child entity arrays and mark the head for deletion instead of direct deletion
and i am not saying that it is impossible, i just wondered that it is so complex to get the cleanup right
it isn't
@mint iron hey awesome you played around with the native octree, seems like it worked for you?
I guess yeah if you just treat it as - All linked entities will be destroyed when this is destroyed. Avoid any special cases or exceptions, and it should be pretty straightforward
If something can't be destroyed with the entity then it shouldn't be linked to it
yep
the more separated your 'players' get the more you need this
my players are roughly 60 entities wide now
easiest solution I find is just when you do your structural change, deleting the player, you do the linked entities right then and there. with ecs you want to make your changes atomic / transactional like a db, instead of having a indeterminate state inbetween. to make this easier, you can also build a system for auto cleanup of child entity arrays and mark the head for deletion instead of direct deletion
@low tangle right know i add the buff entities to the linkedEntitygroup of the player when i create the buff. But i also have to remove the linkedEntities on the player again when a buff gets destroyed (in another system)
why remove the buffer? just clear it and leave it
if i have 4 buffs linked to the player, then i only want to remove the one which expired
mm is it allowed that LInkedEntityGroup buffer contains pointers to deleted entities?
It is but then you're back to the problem of checking if it's valid when you're trying to destroy all linked entities. And in that case you wouldn't have a specific type linked to those entities
Oh I assumed calling destroy on an entity with a LinkedEntityGroup would automatically destroy the thing pointed to by each buffer element
Unfortunately not
Oh I assumed calling destroy on an entity with a LinkedEntityGroup would automatically destroy the thing pointed to by each buffer element
@toxic mural this is working for me
It does work? Hmm, but then isn't there a possibility that the entity you didn't explicitly remove from the buffer might be recycled before you destroy the player?
it might happen, but there is no error thrown if the entity does not exist anymore in the linkedentitygroup
my question with the check if an entity exists was for entities referenced in components
i hope i did not create a lot of confusion 🙂
nothing wrong with a bunch of programmers talking about their hobby on a saturday night
sometimes the side chick ain’t even a side chick
It’s a game you’ve been working on for 5 years but never have finished
surely once I port the game over to THIS new way of doing things, it'll only take a few months..!
too real for me. stop
oh noice you don't have to dispose ComponentDataFromEntity
or it doesn't have a .Dispose() method, anyway
whats the difference between ECB AddBuffer & SetBuffer?
i think its similar to SetComponent and AddComponent. So you can only SetBuffer if the buffer already was added.
Afaik both methods return a new EMPTY buffer. If you want to add something with an ECB to a buffer which has already some elements-> you have to copy all values into the new buffer
i see
there is a CopyFrom method in the DynamicBuffer
I can't understand why I can't use the burst compiler: https://pastebin.com/yj6sD30r
TriggerData is a class, Burst only works with structs, it cant work with managed types such as a class
@wide fiber
Ok thanks, I am stupid
I want to access the children of an entity and disable the one that I want.. is this possible?
I am creating an inventory system, I want to be able to select a thing in the inventory and disable the others. This is the code that I am using but it doesn't work, nothing happens: https://pastebin.com/ThEY9LZF
removing a non-existant component wont give you an error as well.
@wide fiber
oh you are not actually both adding and removing Disabled Component to same entity, unless both index selected and index to select is same entity, but you have to iterate child buffer anyway
Ok I've changed it, but it isn't working. Probably the entity command buffer is the problem
Thanks @opaque ledge
The problem was that adding the Disable component to an entity doesn't disable the hybrid components of the entity -.-
ah yeah
handling hybrid components can be bothersome 😄 but its also pretty rewarding, as thats the only way to bridge between entity and mb
You cant associate a MB with an entity like that tho
unless that system is very specifically tied to an entity such as player or camera
Hallo everybody!
I try to generate my scene at runtime whithin a system in the oncreate method. I have some GO-Prefabs which I convert to entities and than try to instantiate but I always get 2 errors:
1 : System.InvalidOperationException: The BlobAssetReference is not valid. Likely it has already been unloaded or released.
Thrown from job: Unity.Physics.Broadphase.PrepareStaticBodyDataJob
2: System.IndexOutOfRangeException: Index {0} is out of range of '{1}' Length.
Thrown from job: Unity.Physics.BoundingVolumeHierarchy.BuildBranchesJob
Here's my code: https://hatebin.com/ocelwcvzmh
Has anybody a suggestion how to fix this?
You can just generate your scene at runtime thru a MB
You shouldn't use Systems for that
Okay I changed it to MB but the errors staying : https://hatebin.com/nwtnyqszbl
@low tangle 60 entities per player? holy shit
can you explain how that works? what kind of divisions
@vivid copper instead of doing "using BlobAssetStore" you should dispose it on OnDestroy method
yeah that worked! hmm I thoght I tried this before but doesn't look like thank you.
does anyone know with which initil capacity a buffer is added when I just add it to the entity through AddBufer or because it is part of the archetype? 0 or InternalBufferCapacity?
you used to just pass null as settings but its changed, you have to pass proper blob asset store 😄
its decided on InternalBufferCapacity attribute
is an ecb auto scheduled , played and disposed when using from inside ForEach or a Job? are they played in bursted jobs ? what if you retrieve an ecb on main thread and queue commands ? how does it change the bursted job behavior ? what about the auto playback behavior ?
is an ecb auto scheduled , played and disposed when using from inside ForEach or a Job?
ECBs run in the system that they are made from. The system decides when the ECB plays back. When you schedule something in a job with an ECB, it will play that back when the system for that ECB runs.
are they played in bursted jobs
Yes
what if you retrieve an ecb on main thread and queue commands ? how does it change the bursted job behavior ? what about the auto playback behavior ?
No, it shouldn't make a difference
@naive parrot
- You should also note that when you playback ecb its a structral change so you are creating a sync point this is why its generally adviced to use defaul command buffers
How can I get the Right vector of my rotation? math.forward(rotation) helps with Forward, but there is no function for right
i think LocalToWorld component has it
i think mul(rotation.Value, float3(1,0,0)) can also give the right vector 🤔
@bright sentinel thanks for the clarification!
is there a way to change the scales(xyz independent) of an entity as it is for GOs?
Yeah, Scale or UniformScale component, they live in Unity.Transforms namespace i think
I know that Tiny is actually changing their initial scale to 1.0001 so they don't have to manage it themselves
1.0001 ?🤔
Yeah, so they get the Scale added by conversion
oh😅
Can I disable the Auto OnUpdate of a system? I don't want to disable his Auto Creation, only the Auto Update
@wide fiber .Enabled = false
whats the different between World Time and normal Unity Time ? why are unscaled time values not available in a system ?
Seems like .9999 scale would make more sense 🤔
Why?
@mint iron ok, if it's disabled how can I manually update the system?
System.Update()? It doesn't work
get the system from world then call .Update() on it
is there a recommendation on if I should use entityManager or ecb in case I am doing something where I could also use the entitymanager (a system only creating entities pretty rarely, which could also use .Run)
@mint iron
I have put the system in a list of structs, if I use listOfSystems[i].System.Update() It doesn't work
and also if I have different simulations that should run in different time steps, should I just create the systems myself and tick them or how do I do that?
@wide fiber what error do you get when you call update
@junior fjord i think for the first question, its more of a sync point consideration, if you use ECB then you can just have it wherever in your Simulation group without worrying about it. If you use EntityManager then you'd want to try and keep it somewhere explicitly intended for sync point code. I havent' tested the new bursted ECB playback but in the past in some situations it would be faster to use EntityManager (since ECB was just using EntityManger later on).
is the bursted ecb in 0.9 or is something around for some time? Ah and can I find the 0.9 changelog without updating the package myself? 😄
and thanks for the answer
yeah its in 0.9, hot of the press.
@mint iron no error, but nothing happens (there is a Debug.Log in the OnUpdate but it isn't shown)
looks like i was wrong. looking at the source (SystemBase), Update() is still subject to the checks on Enabled. So... you could either enable/disable around calling Update(), or expose your own public method to update and make sure to do the processing that is normally done for you automatically by the base system if you need that functionality (calling Complete() on Dependency etc)
@junior fjord https://discordapp.com/channels/489222168727519232/497874303463850004/697862838190080031
@naive parrot thanks
I'm unable to change the scale of my entity.
this.EntityManager.SetComponentData(obstacle, new Scale { Value = random.NextFloat(0.5f, 5) });
OR:
this.EntityManager.SetComponentData(obstacles[z], new NonUniformScale { Value = random.NextFloat3(new float3(0.5f, 0.75f, 0.5f), new float3(6, 5, 3)) });
both results in the same error ArgumentException: A component with type:Scale has not been added to the entity. Are these not native structs of entities? how can I add these than ( the nonuniformscaleproxy does not work for me and its deprecated also )
@bright sentinel because it would be tinier 😏
lol
@vivid copper Do AddComponentData
When gameobjects are converted to entities if their scale is 1,1,1 then no scale component will be added when converted
Thank you. It works
@vivid copper As I also just stated above (which I don't blame you for not reading), Tiny has one scale axis of their gameobjects (which are going to be converted) set to 1.0001, so that the conversion automatically adds the NonUniformScale component
That way you can safely use SetComponent anywhere
is there a good way for GUI stuff in dots yet or is it just through monobehaivours?
There is a DOTS UI project in forums but its not maintaned for a long time
but i myself am using mb
yeah figured, thanks
@mint iron ok thanks :D
hmmm, seem like Unity Physics StepImmediate is totally undocumented
there's one pool example that uses it on Unity Physics samples though
it's not the greatest example for that as it practically simulates the whole world still
whats WithDeallocateOnJobCompletion for ?
When you create a native container to pass data between jobs you have to dispose them when you are done using them, therefore you want to dispose them when jobs finish, thats what that method does, however only native array is supported iirc, for others you have to do .Dispose(jobHandle)
Quick ?.. Hybrid Renderer has vanished from the Package Manager in a new project. It's just flat out not there.
(facepalm) Thank you
After beating my head against built-in with DOTS, starting fresh with HDRP. It's been a little while since I started a project lmao
Hmm, i dont think built-in is going to be supported, you either have to use URP or HDRP
old renderer supports it but not new renderer
@vivid copper As I also just stated above (which I don't blame you for not reading), Tiny has one scale axis of their gameobjects (which are going to be converted) set to 1.0001, so that the conversion automatically adds the NonUniformScale component
@bright sentinel
ah sorry I didn't recognized this as an answer to me I thought you were answering to someone above ^^, I'm quite new to all this stuff,(eg. it took me some time to get mb as monobehaviour XD )
Yeah, as I learned the hard way. But on the bright side, I ran through about a hundred different ways to script the same thing while trying to do the impossible, so I can say DOTS is robust in Unity!
is there way to create tons of entity all at once ?
other than iterating in a loop , creating 1 per iteration i mean
you can make a native array and instnatiate it
var grounds = new NativeArray<Entity>(numberOfFloors, Allocator.Temp);
this.EntityManager.Instantiate(entity, grounds);
dont forget to dispose 😉
i believe so
typeof(buffer)
you can put to pastebin or hatebin if your code is big 😄
would like this buffer to be part of my archetype
like the other 2 normal components
so you are saying normally adding with typeof should work
hmm, that should be possible, it doesnt work when you add it with typeof ?
i dont work with archetypes, but it should be possible, just try it 🙂
Wait, doesn't the garbage collector dispose of native arrays?
-- if allocated with Temp
I always get an error doing it myself.
native containers are.. native they dont live in managed space, so garbage collector cant do anything about it, you have to manually dispose of them
^
you dont need to dispose Temp, it disposed automatically
Phew. Scared me for a second
* Allocator.Temp has the fastest allocation. It is for allocations with a lifespan of one frame or fewer. You should not pass NativeContainer allocations using Temp to jobs. You also need to call the Dispose method before you return from the method call (such as MonoBehaviour.Update, or any other callback from native to managed code).
* Allocator.TempJob is a slower allocation than Temp but is faster than Persistent. It is for allocations within a lifespan of four frames and is thread-safe. If you don’t Dispose of it within four frames, the console prints a warning, generated from the native code. Most small jobs use this NativeContainer allocation type.
* Allocator.Persistent is the slowest allocation but can last as long as you need it to, and if necessary, throughout the application’s lifetime. It is a wrapper for a direct call to malloc. Longer jobs can use this NativeContainer allocation type. You should not use Persistent where performance is essential.
@opaque ledge that worked. passed buffer with typeof in archetype and got added on instantiation, sweet!
If you miss a free() in C, it'll yell at you. Haven't tried the Persistent allocator to see if that follows through
I don't fully agree with that comment on persistent tho, if you really use same array throughout the game each frame and can use same persistent allocated nativearray, it'll be faster than any alternative
it will yell when you are out of play mode 🙂
That makes sense
@dull copper have you actually did any tests on that ?
I'm guessing that text really talks about allocation speed
and nothing else
in past, yes
allocating new nativearray each frame can be substantially slower
i remember plenty of questions about this, so i was wondering as well
I guess it always "depends"
but on some naive brute force task, it was cheaper to keep it always there
^ this. i have some personal experience with this. with pure jobs stuff , i usually have predefine fixed size native containers and only dispose them at application termination
Temp allocation also generate unforeseen warnings at times
I'm guessing that the reason for tempjobs is that you keep the memory footprint small + it's faster to allocate than persistent
(unless you really need it constantly)
for me its about predictable behavior. i can be certain about lifecycle and validity of my containers instead of playing guessing games at times , generally speaking.
the fastest allocation is no allocation i would assume, unless there's some locality/cache effects of using a specific area of memory versus another that im not aware of... its a pointer deref either way.?
is there way to batch set same component data on all the entities ?
so its misleading for them to say persistent is the slowest allocation, then you've got people using TempJob allocaiton instead of re-using a persistent that was allocated in create
Technically it is not wrong but can give people false impressions
i think JackDunstan had a research about these allocations but it was semi-technical for me
@naive parrot if they're always the same you could use a chunk component
Hmm. The hybrid renderer seems to be doing something backwards. Seen it on two rendering pipelines now.
If I have an array of entities, they have the same components, and they each get a new rendermesh with its own mesh and material, then they should render like separate objects, right?
But they stay in the same chunk and only entity 0 renders.
Same happens if you try to use submeshes.
So, not only do entities with the same sharedcomponent instance get thrown in the same chunk, but in fact, all entities of the same archetype are forced into the same chunk, with the same properties, whether you want them there or not? Or so it seems.
i dont think you should worry that much about allocations if they are only a couple of them per system
thats already several orders of magnitude better than what unity normally did on monobehaviors
what is best practice to update camera position relative to player in dots?
Add camera as a shared component, and implement the IEquatable<camComponent> interface.
public struct camComponent : ISharedComponentData, IEquatable<camComponent>
{
public Camera cam;
...
public bool Equals(camComponent other) ...
public override int GetHashCode() ...
}
Then access the camera like any other shared component in your system. (pardon the edits; I multitask poorly sometimes)
I do it with 2 system, 1 system reads from input and writes to "FollowPlayerDistance" that has float3, so basically this system does, zooming and rotating around the player, and 1 system that sets camera's position and rotation according to FollowPlayerDistance data
Is it possible to move an entity to a new chunk in a programmatic way without having to manually create a new unique struct to serve as a component? I have several entities that are intended to be different things, but which happen to have similar components. I'm going nuts trying to figure out how to get Unity to stop putting them all in the same chunk, on the same rendermesh.
Problem is, when it does that, either I render all of them exactly as the first one made, or I only render the first one made. That's so restrictive that it basically turns ECS into a glorified particle emitter.
Sometimes I might want to have one of a thing visible now, but reserve the option to have many more of the thing. But that doesn't mean that one thing is every thing that happens to have the same data types involved. ie, a zombie isn't a unicorn, but they can both involve the same quad mesh and different materials. An "OK" button isn't a toolbar button. But they can have exactly the same data types. ECS seems to make us choose between zombies and unicorns; to have only one kind of button, ever. That can't be right.
I've tried adding chunk data components. They don't move to new chunks like the documentation says they should. I've tried changing rendermesh settings. They stay in the same chunk. I've tried putting separate rendermeshes in an array in attempt to maintain state. No dice. In ECSLand, everything with at least one corner is the same rectangle. It's maddening.
If two entities have two different components they won't be in the same chunk
Or I should say, two entities will only be in the same chunks if they have the exact same set of components
@gusty comet So to answer your question if you want to change an entity's chunk you add or remove one of it's components, or set one of it's SharedComponentDatas to a new value
Based on what you're saying though it doesn't sound like your issue is actually specifically about two entities being in the same chunk
It really is though. I'll post a pastebin. 1 sec
Bootstrap: https://pastebin.com/RCmHMBXn
System: https://pastebin.com/z87tHikh
Quads are shifted just so it's easy to see at a glance if they're all rendering.
That's the QuadSprite component -- just a tag I put in place as my absolute first ECS design choice ever
1 sec while I remind myself the state I left the bootstrapper in. It started much simpler, and has grown more and more convoluted as I've tried everything I can think of to render these quads with different materials (even if they're not in the same chunk).
Okay, in that state, you'll get one quad rendered (HDRP). The material just has an unlit transparency shadergraph
In the rendermesh SetSharedComponent, use material = materials[0]. Viola! They all render.
Remove the QuadSprite component from just one. All still in the same chunk.
Remove it from the archetype, and add it back to one. All still in the same chunk.
Change the rendermesh in any way, shape, or form, all still in the same chunk. All that changes is either one quad renders or that one quad is instanced several times.
I've been beating my head on this for two days.
I've even tried moving to the 2020 beta, back to 2019.3, changed render pipelines, everything I can think of
I just flat can't get it to work the way the documentation (and you) say it should.
where in the system are you trying to change the components?
also entitymanager is already a property of every system, no need to cache it again
Oh, neat. So, in the system. I was trying in the bootstrapper. brb
Wait. Should I be setting components in the system too?
i was only expecting to see that stuff in the system, not that it cant be done from the monobehaviour
eMan is cached just to avoid typing out World.DefaultGameObjectInjectionWorld.EntityManager while experimenting
In that case, if it can be done in the monobehavior, you don't see it done there because I had just cleared that experiment.
you can just use EntityManager without world.blah in systembase
Oh, neat!
Before I opened Discord back up, I had just deleted QuadSprite from the archetype, and tried adding it back to erray[1] only, at the bottom of the bootstrap. Everything was still in the same chunk, so maybe that must be done from the system?
Just after each experiment, I've backtracked to near my last working state that rendered everything, so I don't add bugs on top of fails lmao
honestly not really seeing why its all the same chunk but arrays of procedural meshes are not really my strength so i might be overlooking something too
Just as it is, I should see 128 quads spread like cards, each a different color from black in front to white in back
Seeing as every single entity has different RenderMesh settings, it seems they should each be in their own chunk
I know that kind of defeats the purpose of ECS, but it comes down to, I'll need several different quads and I don't know how many of each. So, I need to be able to move them in and out of chunks as I go.
That's the thing though, only the component types determine what chunk an entity goes into
The data in the components shouldn't matter which archetype the entity belongs to
The systems just does the same procedure on the data no matter what it is
From the documentation: RenderMesh is a shared component, which means all entities of the same Archetype and same RenderMesh settings are stored together in the same chunks of memory.
"And"
Yes, the same rendermesh. It sounds like you want to change the rendermesh then
I don't mind changing data types though, if I can get it to work. I just don't want to have to manually create a file for each of 1000 different kinds of sprite.
I have an array of rendermeshes. I'd like to start with each having their own.
Maybe one becomes dropdown menu buttons. In a month I may know I need 50. One maybe becomes wall faces. In two months I may know 2000 is a good number. For now, I know none of that.
You keep talking about chunks and it's kinda confusing your issue I think. It sounds like the only thing you're dealing with is how Shared Components work
If RenderMesh were not a shared component, it would solve everything
You can still have RenderMeshes with different settings
But it is, and for that reason it's my opinion that Hybrid Renderer is just not a good fit for procedural geometry right now
Different settings, like different materials and meshes? But I'm doing that and everything is still in the same chunk.
You're probably right about that Sark.
Just having entity specific materials would be a game changer.
I've seen some Unity devs say some really promising stuff about changes they are going to be making that will make Hybrid Renderer work better for procedural geometry, like automatically combining different meshes that all share the same material. But as it is right now you probably will get much better performance from using builtin/SRP
At least that's been my experience
"When you add a shared component to an entity, the EntityManager places all entities with the same shared data values into the same chunk."
So either you're just not setting the values differently, or there's a bug
If it's in an archetype, isn't it added when the entity is created?
There may be a bug. Or I'm doing something wrong.
brb. Going to try setting it up so they all render, and then running another loop to change materials. Just in case it's not added until it's set
Highly likely that it's you doing something wrong