#archived-dots

1 messages · Page 131 of 1

bright sentinel
#

Because that's not really a structural change

#

At least conceptually

stone osprey
#

Are IComponentData structs allowed to have Properties ?

#

Or methods ?

opaque ledge
#

yes

stone osprey
#

NICEEE, this information just saved my day 🙂

mint iron
#

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)

safe lintel
#

weird, with hybrid v2 when you select a companion light in the debugger it gets disabled automatically 🤔

wide fiber
#

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?

safe lintel
#

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

wide fiber
#

Ok ty

mint iron
vagrant surge
#

total size? 👀

#

variable chunks then?

stone osprey
#

Lets say i need a system which executes a action once and not every update... how could i achieve this ? Is there something buildin ?

opaque ledge
#

@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

stone osprey
#

@opaque ledge Thats great ! 😄 So basically events but instead of a event handler we simply use a component

opaque ledge
#

yes 🙂

#

kinda boring workflow tbh, but yeah

stone osprey
#

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 ?

opaque ledge
#

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

stone osprey
#

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

opaque ledge
#

yeah possible, never tried tho, i am a peasant

#

why cant you just do it in peasant's way xD

stone osprey
#

Well me too ^^ im trying to determine all of my possibilities before i actually implement this 🙂

warped trail
#

you can make your system update only when specific entity exist

wide fiber
warped trail
#

update collection package

#

or maybe some other package 😅

wide fiber
#

All my packages are updated

warped trail
#

i guarantee that some of your package is downgraded

#

just check them

#

oh wait

#

this is dots editor

wide fiber
#

Yeah

warped trail
#

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😂

wide fiber
mint iron
#

didnt' somebody mention earlier com.unity.dots.editor shouldn't be used?

fast grotto
#

Hey, where is the Transforms package?

wide fiber
#

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 ☹️

warped trail
#

no checkboxes for now 😅

wide fiber
#

Hey, where is the Transforms package?
@fast grotto ?

#

Ok @warped trail :(

fast grotto
#

I can't find it in the package manager

warped trail
#

because it is part of Entities package

fast grotto
#

Ok

solemn ice
#

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)

dull copper
#

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

warped trail
#

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 😅

dull copper
#

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

low tangle
#

I mean isn't that really just showing that it isn't a fully parallelable problem or solution?

warped trail
#

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?🤔

low tangle
#

more cores mean more parallel work not really more of the same faster

dull copper
#

yeah, I guess I need find the max cores where there's still benefits

low tangle
dull copper
#

instead of letting the job system to decide

low tangle
#

32 cores, 50% parallel only shows a 2x factor of speedup

dull copper
#

but in that case it still is showing speedup 😅

low tangle
#

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)

vagrant surge
#

on my xp, stacking parallel fors will only reach about 70% scalability

#

to reach 90%+, you need to overlap everything a lot

low tangle
#

yep

#

you need work that doesn't depend on each other

vagrant surge
#

so maybe streamed parallel fors (start next parallel for before the last one is truly finished), and overlapping 2 streams of jobs

low tangle
#

and maxes out vector instructions

#

incase you were wondering where the chart was from

mystic mountain
#

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?

mint iron
#

unless somethings changed recently they ensure all sytem jobs are completed each frame.

bright sentinel
#

Yeah, all jobs you schedule in a frame are completed before that frame is over

mystic mountain
#

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.

bright sentinel
#

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

hollow sorrel
#

i think it only calls previousjob.complete right before running onupdate in the next frame tho so dunno about before that frame is over

warped trail
#

are you sure that all jobs are completed?🤔

bright sentinel
#

@hollow sorrel Isn't the sync point in the ECBs supposed to do that?

hollow sorrel
#

ah yea cuz of syncpoints i guess so

warped trail
#

AddJobHandleForProducer will complete your job yes, but what about other cases?

mystic mountain
#

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.

mint iron
#
    private void BeforeOnUpdate() // Unity.Entities.SystemBase
    {
        BeforeUpdateVersioning();
        _JobHandle.Complete();
        _GetDependencyFromSafetyManager = true;
    }
fast grotto
#

Hey, how does input work in ECS?

opaque ledge
#

hi, you check for Input in OnUpdate method, then schedule a job if true, do nothing if not etc.

fast grotto
#

Ok, maybe I should have been expecific. How can I get input with the new input system in ECS

opaque ledge
#

basically same with MBs, except you initalize your inputs in OnCreate(override) method, then do your logic in OnUpdate

fallow mason
fast grotto
#

This is outdated, there is no InputAction in UnityEngine.InputSystem

zenith wyvern
#

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

opaque ledge
#

@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

fast grotto
#

What is GamePlayerInput?

naive parrot
#

probably generated class

safe lintel
#

InputActions it the automatically created class from the new inputsystem

opaque ledge
#

Yes, its genetated class from new input system

safe lintel
#

UnityPhysicsSamples/Assets/Common/InputActions.cs
// GENERATED AUTOMATICALLY FROM 'Assets/Common/InputActions.inputactions'

naive parrot
#

@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

opaque ledge
#

You should check out how new input system works if you never worked before like Sark said

sonic oyster
#

Was NativeQueue<T>.Concurrent removed?

safe lintel
#

AsParallelWriter @sonic oyster

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

safe lintel
#

dequeue should still be the same

sonic oyster
#

I can only Enqueue

safe lintel
#

how are you using this?

sonic oyster
#
{
    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

safe lintel
#

were you able to do that with concurrent?

sonic oyster
#

no idea

#

never had my hands on concurrent nativequeue, that's why i asked

#

since google pretty much yields that on my face

safe lintel
#

not sure if you can? if theres another way im not familiar with it

zenith wyvern
#

You can only write in parallel. If you need to read/write in parallel you can use a NativeStream

sonic oyster
#

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!

dull copper
#

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?

warped trail
#
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?😅

dull copper
#

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

warped trail
#

does physics's step solver iteration and thread count make any difference?

dull copper
#

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

mint iron
#

you talking more about physics or rendering too?

dull copper
#

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

mint iron
#

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.

dull copper
#

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

mint iron
#

right, its the easy option for sure. but at what cost.

dull copper
#

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)

mint iron
#

are you using subscenes?

dull copper
#

none

#

should it help on this?

#

these things I'm using are not really compatible with dots subsenes at all

mint iron
#

no probably, i mention it because the scene loading systems add quite a bit of extra time.

dull copper
#

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

mint iron
#

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. 😢

fast grotto
#

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()

safe lintel
#

outside of the ForEach var dir = direction; and then just plug dir into the translation

fast grotto
#

I can't do that, I am setting direction equal to the result of the inputsystem action

safe lintel
#

eh this is what I mean

  protected override void OnUpdate(){
      float3 dir = direction;
      Entities.WithAll<Translation>().ForEach((ref Translation translation) => {
          translation.Value = dir;
    }).Run();
  }
fallow mason
#

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?

lusty otter
#

Any quick way to reset NativeArray to all 0?

zenith wyvern
#

UnsafeUtility.MemClear

toxic mural
#

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?

gusty comet
#

Is anyone using dots networking for a game?

hollow sorrel
#

@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?

toxic mural
#

@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)

hollow sorrel
#

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

toxic mural
#

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

hollow sorrel
#

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

toxic mural
#

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

hollow sorrel
#

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

toxic mural
#

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?

hollow sorrel
#

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¿

toxic mural
#

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

hollow sorrel
#

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

toxic mural
#

riiight I know that feelerino

hollow sorrel
#

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

toxic mural
#

Yeah good point, later

opaque ledge
#

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 ?

bright sentinel
#

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.

wide fiber
#

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

warped trail
#

@fallow mason Look at DebugStream

opaque ledge
#

@wide fiber Thats the question of the century 😄

#

but for ECS sake, go for add/remove components

warped trail
#

@wide fiber btw, code for fixed step i link you before is not working correctly😅

wide fiber
#

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?

warped trail
#

when you press play, it will update a lot of times, before it starts to work correctly 😅

wide fiber
#

Ah... Well I could make an IF to check if Time.elapsedTime is greater than 0.1s for example

warped trail
#

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😅

wide fiber
#

Ok

#

But elapsed time starts increasing on first update or when the application starts?

warped trail
#

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 😅

wide fiber
#

Ok.. on my machine it's working correctly

warped trail
#

and Unity's default Maximum Allowed Timestep takes care of this problem sometimes🤔

wide fiber
#

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"

wide fiber
#

Thanks

stone osprey
#

Is it possible to get a entity query outside a system ?

fallow mason
#

@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.

stone osprey
#

Any quick tipp how i can run a entity query outside a system ( Monobehaviour for example ) ?

bright sentinel
#

I think you have to use systems to access entities

stone osprey
#

Its for my UI... i basically need to find the local player for displaying his stats

bright sentinel
#

You have to do it the other way

#

Have a system that queries for the entities, and then sets some data on a MB

stone osprey
#

Damn... is this the only way ?

bright sentinel
#

Well why is that such a big problem?

stone osprey
#

Systems are able to communicate with mb's but not the other way around ?

bright sentinel
#

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?

stone osprey
#

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.

bright sentinel
#

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

warped trail
#

you can create query via EntityManager

bright sentinel
#

But can you actually access the components?

stone osprey
#

@warped trail The only query i saw in the entity manager is the universalquery... that query returns all entities... or did i missed something ?

warped trail
#
var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(Translation));```
stone osprey
#

@warped trail Thanks ! That solved this problem 🙂

warped trail
#

but i don't think this is a good idea 😅

bright sentinel
#

Where do systems run in the context of MBs?

#

Rather, when?

warped trail
#

i know that lateupdate is between simulation and presentation groups

bright sentinel
#

Well, I could always just use the ED and show the full player loop lol

warped trail
#

yes

bright sentinel
#

Interesting that FixedUpdate is there 🤔

warped trail
#

this is default unity's update loop😅

#

and ecs systems just hooked to it by default

bright sentinel
#

Yeah

#

I guess it makes sense

#

Considering this is using the UnityEngine runtime

#

And not the DOTS Runtime

#

Which will be vastly different

warped trail
#

i wonder how much years will pass before DOTS Runtime for regular unity 🤔

bright sentinel
#

Well Tiny already works

warped trail
#

but Tiny is like another engine🤔

bright sentinel
#

Exactly

warped trail
#

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?🤔

bright sentinel
#

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

warped trail
#

so we will have URP HDRP, Tiny URP, Tiny HDRP ? 😅

bright sentinel
#

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

warped trail
#

what everyone mean by DOTS renderer?🤔

stone osprey
#

HybridRenderer

bright sentinel
#

Right now the renderer isn't running on systems

#

It's not jobified either

#

At least I don't think it is

warped trail
#

so by pure DOTS renderer you mean that there will be something new in engine?

stone osprey
#

Oh btw... do we need unity 2020 to use HybridRenderer v2 or is there a trick to obtain that version on Unity 2019 ?

bright sentinel
#

Nah you need 2020.1

warped trail
#

2020.1.b3+ only

stone osprey
#

Thats a pitty., thanks :/

warped trail
#

it is basically not working, so no pitty 😅

opaque ledge
#

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

#

Like.. it only show gameobject's inital position, it doesnt update it

#

except when i rotate...

#

sigh

stone osprey
#

Im sorry... i have no clue, i just started like 3 days ago with unity dots

opaque ledge
#

dw 😄 probably no one knows whats going around

stone osprey
#

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 ? 😮

opaque ledge
#

You can add a buffer instead of a component

stone osprey
#

Thanks ! So i guess i need one component as a dynamic buffer and a other component as a buffer element ?

opaque ledge
#

no, buffers means IBufferElementData but when you query for it you do DynamicBuffer<YourBufferElement>

dull copper
#

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

mint iron
#

huh, i was wondering the same thing, i copied entities to /packages/ and it didnt show up in vs

dull copper
#

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

mint iron
#

odd, my external tools doesnt look like that

dull copper
#

are you on 2020.1.0b5?

mint iron
#

yep

dull copper
#

weird

mint iron
dull copper
#

it probably doesn't help you either when I say this seems to work splendidly now 😄

#

oh I know what it is

mint iron
#

haha

dull copper
#

go to package manager, update your visual studio package there

#

I updated that yesterday, so it must be it

mint iron
#

they dont have a changelog entry for the latest version 😅

dull copper
#

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

mint iron
#

nice, thanks!

dull copper
#

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

mint iron
#

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)

dull copper
#

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)

warped trail
#

@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

dull copper
#

yeah, I've seen that

mint iron
warped trail
#
{
  UpdateAllSystems();
}```
dull copper
#

@warped trail if EnableFixedRateSimple works like that, it's not named properly at all

#

what's the point of it even?

warped trail
#

EnableFixedRateSimple is not named properly and other one is bugged 👍

#

and you have to take into account Maximum Allowed Timestep

dull copper
#

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

stone osprey
#

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 ?

dull copper
#

@warped trail yeah, that's what I was getting into, it doesn't seem like it's taken into account now?

warped trail
#

@dull copper no it won't starve

#

Unity's default Maximum Allowed Timestep will kick in

fallow mason
#

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.

dull copper
#

where do they have this check?

warped trail
#

@dull copper somewhere in unity's internal systems 😅

#

your world is in default player loop

dull copper
#

but this doesn't actually use the fixedupdate loop

warped trail
#

but i guess it is not guaranteed to kick in 😅

dull copper
#

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

warped trail
#

it will take big delta time, update a lot of times

dull copper
#

basically it will look that callback as many times before it's done all fixed timesteps

warped trail
#

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

dull copper
#

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

warped trail
#

you can check it yourself😅

dull copper
#

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

opaque ledge
#

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

dull copper
#

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

warped trail
dull copper
#

yeah, you should have max timestep somewhere in the equation

#

feels super shortsighted that they didn't do it

warped trail
#

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😅

dull copper
#

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

warped trail
#

this is what happens in unity right now btw 😅

dull copper
#

of course this will throttle on low end cpu

warped trail
#

there is small spike at the begining

#

and your fixed system is like Holy shit i have to catch up 😅

dull copper
#

but if it's really starving, it'll just never get past the cumulative counter and it'll appear like regular hard cut

warped trail
#

and than unity is like, holy shit delta time is big, lets cap it

dull copper
#

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

warped trail
#

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 😂

mint iron
#

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.

warped trail
#

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 😕

dull copper
#

it's such a basic thing to need

#

and proper implementation has been missing for one year now

mint iron
#

@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.

dull copper
#

I just checked them all 😅

#

haven't noticed anything being broken by that

mint iron
#

you have the magic touch, everything works

formal scaffold
#

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?

dull copper
#

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)

formal scaffold
#

Oh, thanks I was looking at Entities being the problem how'd you find out it's Platforms?

naive parrot
#

can someone post entities 0.9 changelog

dull copper
#

@formal scaffold it's in it's dependencies

#

if you haven't installed platforms manually, it'll pick the right one automatically

#

they haven't updated the online docs yet

stone osprey
#

Is there any huge difference between a componentsystem and a jobcomponentsystem ? I thought every component system is based on jobs

dull copper
#

@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

stone osprey
#

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 🙂

dull copper
#

you can't access managed things directly on jobs

#

you need to run them on mainthread

#

also without burst

stone osprey
#

Damn... so no way for job movement till i dump gameobjects for displaying my entitys and instead go with mesh renderers ?

dull copper
#

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

stone osprey
#

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 :

dull copper
#

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

stone osprey
#

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

dull copper
#

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)

warped trail
#

v2 does a minimal support for urp😏

naive parrot
#

@dull copper thanks for the log.

formal scaffold
#

Thanks for the Tip with the dependencies @dull copper , makes it much easier to track down problems

stone osprey
#

@warped trail Minimal ? 😮 uhmm

warped trail
#

half of your faces will be pitch-black😅

stiff skiff
#

Question, is it possible to merge 1 entity into another?

warped trail
#

what do you mean by merge?

stiff skiff
#

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

dull copper
#

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

stiff skiff
#

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

mint iron
#

@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.

dull copper
#

no matter how much I edit these, the errors remain

#

these systems do function do

mint iron
#

@stiff skiff i dont think there is an API method that does that.

stiff skiff
#

Yeah I figured, I'll have to do some digging and build something

#

Probably some archetype creation and entity remapping

dull copper
#

wiping ScriptAssemblies from library folder did make those go away

#

fun stuff

#

@mint iron thanks for the headsup

willow creek
mint iron
#

looks really cool, mind if i ask what CheckWriteAndBumpSecondaryVersion does (what does the secondary version do)?

formal scaffold
#

Should I use Havok or normal Physics for DOTS? Been using Unity Physics so far but I just read that Havok is faster

dull copper
#

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

willow creek
#

@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 😉

dull copper
#

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)

willow creek
#

@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

formal scaffold
#

I guess so but I'm too inexperienced atm to really tell so I will stick to Unity.Physics until I know more

dull copper
#

Unity Physics is safer bet atm

willow creek
#

plus 1 to that 🙂

dull copper
#

neither of these are production ready tho

willow creek
#

unity physics is in good state though

dull copper
#

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)

formal scaffold
#

You have to code quite alot yourself but thats fine by me

solar ridge
#

been a while since I have tried using it, but I believe stacking in unity physics is still odd 😉

dull copper
#

they improved it a bit

solar ridge
#

Since it it stateless stacked dynamic objects ... dance

dull copper
#

but it's not going to give you buildings talls stacks of boxes

solar ridge
#

It is just 2 boxes

#

I' try again soon.

dull copper
#

2-4 boxes should work now

#

of course it'll be more "alive" still due to lack of sleeping

#

things can drift with time

formal scaffold
#

By not sleeping you mean that the Physics Engine keeps updating the Velocity of my character even when standing still yes?

zenith wyvern
#

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

dull copper
#

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

mint iron
#

@willow creek do you have a license for that code?

willow creek
#

I forgot to add MIT, will do now

dull copper
#

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

willow creek
#

thanks for asking 🙂

dull copper
#

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

willow creek
#

@mint iron done

dull copper
#

and while it's a state, it's just an integer that is easy to set if you need to rewind things etc

warped trail
#

2-4 boxes should work now this is not true at all 😅

dull copper
#

really?

zenith wyvern
#

If you need reliable stacking then your only option is Havok I would think

solar ridge
#

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

warped trail
#

havok is cool😏

dull copper
#

ah, yes, it will drift along time

solar ridge
#

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)

dull copper
#

I thought you meant like things dancing on top if stacked

solar ridge
#

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

dull copper
#

yeah, that will still happen

zenith wyvern
#

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

solar ridge
#

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

stone osprey
#

Is it normal that my playerloop uses about 10 ms of performance ? I actually dont even use that playerloop

#

Its the default one

solar ridge
#

In some cases yes

#

If you are in the editor, it is not unheard of

stone osprey
#

Is there a way to disable that playerloop ? ^^

#

Or is it required to run along the other ecs parts ?

solar ridge
#

You have an image of your profiler?

#

The time graph

formal scaffold
#

But if I understand correctly, I can just remove the Unity Physics package and import Havok without changing code is that correct?

solar ridge
#

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.

dull copper
#

we need breakable joints to fix the stacks from drifting 😅

stone osprey
#

Thats a pic from a profiler spike... the playerloop spiked

dull copper
#

looks like GC spikes

formal scaffold
#

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?

solar ridge
#

Most of that is still the editor

warped trail
#

dark theme😂

solar ridge
#

Dark theme is the more noticeable one

#

However

#

You also get unity support much faster

dull copper
#

@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

formal scaffold
#

I do like dark theme 👀

dull copper
#

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

warped trail
#

or if you are a cool hacker 😏

solar ridge
#

@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

dull copper
#

well, hex editing unity binaries violates the EULA

#

so wouldn't recommend

formal scaffold
#

Still got time to get pro then will at least be another year

dull copper
#

or TOS or whatever they call their terms

zenith wyvern
#

Probably don't bring it up in here at the very least

dull copper
stone osprey
#

@solar ridge Thanks ! Guess its fine than 🙂 Just wasnt sure... never heard of that playerloop

warped trail
#

from totally beginner point of view this engines will look almost identical🤔

opaque ledge
#

how can i make authoring scripts to create the entity for a custom world ?

solar ridge
#

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 :\

opaque ledge
#

@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 ?

dull copper
opaque ledge
#

i cant see any methods related to subscenes in World

dull copper
#

that's unity physics "stacking"

naive parrot
#

is DynamicBuffer.Clear ( ) a structural change ? causes Sync point ?

#

i doubt it, but if someone can confirm..

opaque ledge
#

no its not

#

structral change is.. adding/removing components/buffers, creating/destroying entities

naive parrot
#

and when iterating in Entitie.ForEach , for write access is ref valid qualifier or it has write access by default ?

#

for DynamicBuffer i mean

opaque ledge
#

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

naive parrot
#

alright thanks

stiff skiff
#

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

stiff skiff
#

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

solar ridge
#

That is what Instantiate is for?

stiff skiff
#

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)

solar ridge
#

Oh oh. You want to do a pool like system?

stiff skiff
#

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

solar ridge
#

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

stiff skiff
#

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

zenith wyvern
warped trail
#

joints? 😅

mint iron
#

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.

dull copper
#

@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

opaque escarp
#

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

worldly pulsar
#

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.
opaque ledge
#

nope, you have to make another job

opaque escarp
#

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

worldly pulsar
#

There is no universal answer to that

opaque escarp
#

I'll just benchmark it then

opaque escarp
#

How can I get a job to run after a certain EntityCommandBuffer is run?

opaque ledge
#

custom entity command buffer or default ?

bright sentinel
#

Just run it after the EntityCommandBufferSystem

opaque ledge
#

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

bright sentinel
#

E.g. [UpdateAfter(typeof(EndSimulationCommandBufferSystem))]

opaque escarp
#

all right ty

mint iron
gusty comet
#

is there any way to check if an entity exists wihout EntityManager.Exists()?

#

so i can use burst

toxic mural
#

would if(myEntity == Entity.Null) work?

#

oh actually probably not, because it might have been deleted

gusty comet
#

yes, its just a copy

#

i often need to know if the entity still exists, there has to be a better way

toxic mural
#

I would imagine if you use an ECB it would check automarically for you

mint iron
#

it can be done

gusty comet
#

the ecb throws an error if the entity does not exist anymore

toxic mural
#

oh.

gusty comet
#

@mint iron how?^^

mint iron
#

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.

gusty comet
#

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

toxic mural
#

Dont suppose you can just put the buffs on the player entity?

gusty comet
#

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

toxic mural
#

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)

naive parrot
#

@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

zenith wyvern
#

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

gusty comet
#

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.

zenith wyvern
#

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?

gusty comet
#

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

toxic mural
#

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

mint iron
#

it would be easy if they exposed some more of the internal stuff.

gusty comet
#

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

naive parrot
#

@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

zenith wyvern
#

@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

mint iron
#

topher doesnt want to see my solution im sure 😄

#

ill pm

gusty comet
#

@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

naive parrot
#

makes sense

zenith wyvern
#

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

toxic mural
#

oh hey how about ComponentDataFromEntity<T>().Exists ?

zenith wyvern
#

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

toxic mural
#

ARe you sure?

zenith wyvern
#

Oh damn

#

I guess that would work then

toxic mural
#

I mean you have to provide the <T> type but for OP it sounds like they know it'll have a PlayerComponent or something

zenith wyvern
#

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

gusty comet
#

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

zenith wyvern
#

Keep in mind in SystemBase you can just use HasComponent directly and it's functionally equivalent

toxic mural
#

less verbose

gusty comet
#

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

zenith wyvern
#

I've never used it for that purpose but based on the docs it sounds like that's the intent

toxic mural
#

I dunno man checking if an entity exists.. seems not very ECS

gusty comet
#

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

toxic mural
#

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

naive parrot
#

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

gusty comet
#

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

naive parrot
#

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?

gusty comet
#

@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

naive parrot
#

i would just add the same buffs in a single component

gusty comet
#

@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

naive parrot
#

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

gusty comet
#

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 😄

zenith wyvern
#

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

toxic mural
#

I think entity per buff is right, keep cooldown as separate component, not integrated into buff component itself

gusty comet
#

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

low tangle
#

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

gusty comet
#

and i am not saying that it is impossible, i just wondered that it is so complex to get the cleanup right

low tangle
#

it isn't

willow creek
#

@mint iron hey awesome you played around with the native octree, seems like it worked for you?

zenith wyvern
#

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

low tangle
#

yep

#

the more separated your 'players' get the more you need this

#

my players are roughly 60 entities wide now

gusty comet
#

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)

low tangle
#

why remove the buffer? just clear it and leave it

gusty comet
#

if i have 4 buffs linked to the player, then i only want to remove the one which expired

toxic mural
#

mm is it allowed that LInkedEntityGroup buffer contains pointers to deleted entities?

zenith wyvern
#

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

toxic mural
#

Oh I assumed calling destroy on an entity with a LinkedEntityGroup would automatically destroy the thing pointed to by each buffer element

zenith wyvern
#

Unfortunately not

gusty comet
#

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

zenith wyvern
#

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?

gusty comet
#

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 🙂

toxic mural
#

nothing wrong with a bunch of programmers talking about their hobby on a saturday night

low tangle
#

aye

#

working on the side chick project

gusty comet
#

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

toxic mural
#

surely once I port the game over to THIS new way of doing things, it'll only take a few months..!

naive parrot
#

too real for me. stop

toxic mural
#

oh noice you don't have to dispose ComponentDataFromEntity

#

or it doesn't have a .Dispose() method, anyway

naive parrot
#

whats the difference between ECB AddBuffer & SetBuffer?

gusty comet
#

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

naive parrot
#

i see

gusty comet
#

there is a CopyFrom method in the DynamicBuffer

wide fiber
opaque ledge
#

TriggerData is a class, Burst only works with structs, it cant work with managed types such as a class

#

@wide fiber

wide fiber
#

Ok thanks, I am stupid

wide fiber
#

I want to access the children of an entity and disable the one that I want.. is this possible?

opaque ledge
#

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

wide fiber
#

Ok I've changed it, but it isn't working. Probably the entity command buffer is the problem

wide fiber
#

Thanks @opaque ledge

The problem was that adding the Disable component to an entity doesn't disable the hybrid components of the entity -.-

opaque ledge
#

ah yeah

#

handling hybrid components can be bothersome 😄 but its also pretty rewarding, as thats the only way to bridge between entity and mb

bright sentinel
#

Well not the only way

#

Systems can also access MBs

#

Like GameObject.Find

opaque ledge
#

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

vivid copper
#

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?

opaque ledge
#

You can just generate your scene at runtime thru a MB

#

You shouldn't use Systems for that

vivid copper
vagrant surge
#

@low tangle 60 entities per player? holy shit

#

can you explain how that works? what kind of divisions

opaque ledge
#

@vivid copper instead of doing "using BlobAssetStore" you should dispose it on OnDestroy method

vivid copper
#

yeah that worked! hmm I thoght I tried this before but doesn't look like thank you.

junior fjord
#

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?

opaque ledge
#

you used to just pass null as settings but its changed, you have to pass proper blob asset store 😄

#

its decided on InternalBufferCapacity attribute

naive parrot
#

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 ?

bright sentinel
#

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

opaque ledge
#
  • 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
formal scaffold
#

How can I get the Right vector of my rotation? math.forward(rotation) helps with Forward, but there is no function for right

opaque ledge
#

i think LocalToWorld component has it

#

i think mul(rotation.Value, float3(1,0,0)) can also give the right vector 🤔

naive parrot
#

@bright sentinel thanks for the clarification!

vivid copper
#

is there a way to change the scales(xyz independent) of an entity as it is for GOs?

opaque ledge
#

Yeah, Scale or UniformScale component, they live in Unity.Transforms namespace i think

bright sentinel
#

I know that Tiny is actually changing their initial scale to 1.0001 so they don't have to manage it themselves

warped trail
#

1.0001 ?🤔

bright sentinel
#

Yeah, so they get the Scale added by conversion

warped trail
#

oh😅

wide fiber
#

Can I disable the Auto OnUpdate of a system? I don't want to disable his Auto Creation, only the Auto Update

mint iron
#

@wide fiber .Enabled = false

naive parrot
#

whats the different between World Time and normal Unity Time ? why are unscaled time values not available in a system ?

fallow mason
#

Seems like .9999 scale would make more sense 🤔

bright sentinel
#

Why?

wide fiber
#

@mint iron ok, if it's disabled how can I manually update the system?

#

System.Update()? It doesn't work

mint iron
#

get the system from world then call .Update() on it

junior fjord
#

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)

wide fiber
#

@mint iron
I have put the system in a list of structs, if I use listOfSystems[i].System.Update() It doesn't work

junior fjord
#

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?

mint iron
#

@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).

junior fjord
#

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

mint iron
#

yeah its in 0.9, hot of the press.

wide fiber
#

@mint iron no error, but nothing happens (there is a Debug.Log in the OnUpdate but it isn't shown)

mint iron
#

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
vivid copper
#

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 )

fallow mason
#

@bright sentinel because it would be tinier 😏

bright sentinel
#

lol

opaque ledge
#

@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

vivid copper
#

Thank you. It works

bright sentinel
#

@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

pliant pike
#

is there a good way for GUI stuff in dots yet or is it just through monobehaivours?

opaque ledge
#

There is a DOTS UI project in forums but its not maintaned for a long time

#

but i myself am using mb

pliant pike
#

yeah figured, thanks

wide fiber
#

@mint iron ok thanks :D

dull copper
#

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

naive parrot
#

whats WithDeallocateOnJobCompletion for ?

opaque ledge
#

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)

gusty comet
#

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

opaque ledge
#

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
#

@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 )

gusty comet
#

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!

naive parrot
#

is there way to create tons of entity all at once ?

#

other than iterating in a loop , creating 1 per iteration i mean

vivid copper
#

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 😉

naive parrot
#

great , that will work.

#

can we use dynamic buffer for creating archetypes ?

opaque ledge
#

how do you mean exactly ?

#

you mean having a dynamic buffer in your archetype ?

naive parrot
#

yeah

#

when defining the archetype

opaque ledge
#

i believe so

#

typeof(buffer)

#

you can put to pastebin or hatebin if your code is big 😄

naive parrot
#

like the other 2 normal components

#

so you are saying normally adding with typeof should work

opaque ledge
#

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 🙂

gusty comet
#

Wait, doesn't the garbage collector dispose of native arrays?

#

-- if allocated with Temp

#

I always get an error doing it myself.

opaque ledge
#

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

dull copper
#

^

opaque ledge
#

you dont need to dispose Temp, it disposed automatically

gusty comet
#

Phew. Scared me for a second

dull copper
#
* 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.
naive parrot
#

@opaque ledge that worked. passed buffer with typeof in archetype and got added on instantiation, sweet!

gusty comet
#

If you miss a free() in C, it'll yell at you. Haven't tried the Persistent allocator to see if that follows through

dull copper
#

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

opaque ledge
#

it will yell when you are out of play mode 🙂

gusty comet
#

That makes sense

opaque ledge
#

@dull copper have you actually did any tests on that ?

dull copper
#

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

opaque ledge
#

i remember plenty of questions about this, so i was wondering as well

dull copper
#

I guess it always "depends"

#

but on some naive brute force task, it was cheaper to keep it always there

naive parrot
#

^ 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

dull copper
#

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)

naive parrot
#

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.

mint iron
#

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.?

naive parrot
#

is there way to batch set same component data on all the entities ?

mint iron
#

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

dull copper
#

Technically it is not wrong but can give people false impressions

opaque ledge
#

i think JackDunstan had a research about these allocations but it was semi-technical for me

mint iron
#

@naive parrot if they're always the same you could use a chunk component

gusty comet
#

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.

vagrant surge
#

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

vivid copper
#

what is best practice to update camera position relative to player in dots?

gusty comet
#

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)

opaque ledge
#

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

gusty comet
#

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.

zenith wyvern
#

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

gusty comet
#

It really is though. I'll post a pastebin. 1 sec

#

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.

safe lintel
#

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

gusty comet
#

Oh, neat. So, in the system. I was trying in the bootstrapper. brb

#

Wait. Should I be setting components in the system too?

safe lintel
#

i was only expecting to see that stuff in the system, not that it cant be done from the monobehaviour

gusty comet
#

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.

safe lintel
#

you can just use EntityManager without world.blah in systembase

gusty comet
#

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

safe lintel
#

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

gusty comet
#

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.

bright sentinel
#

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

gusty comet
#

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"

bright sentinel
#

Yes, the same rendermesh. It sounds like you want to change the rendermesh then

gusty comet
#

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.

zenith wyvern
#

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

gusty comet
#

If RenderMesh were not a shared component, it would solve everything

bright sentinel
#

You can still have RenderMeshes with different settings

zenith wyvern
#

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

gusty comet
#

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.

zenith wyvern
#

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

bright sentinel
#

"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

gusty comet
#

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

bright sentinel
#

Highly likely that it's you doing something wrong