#archived-dots

1 messages ยท Page 228 of 1

remote crater
#

The second means maybe scaling a gameobject to make a new game object in assets.

cerulean pulsar
#

I think the physics shape conversion system adds a CompositeScale component to the target entity

#

As far as normalizing a gameobject's scale, I dunno. If I ever needed that it was only in terms of the mesh, so then I went into Blender and scaled it and exported it so it would be the size I wanted in Unity with a scale of 1,1,1. If you want the apply the scale to more than that then I'd need to know more details

remote crater
#

I know about Blender, but its a super hassle.

#

Should be a single button in Unity

#

Ty for the composite scale. I'll look

earnest hill
#

Is there an IJob type with TransformAccess that will execute on a worker thread in the order the transforms are added to the TransformAccessArray? I want to get some transform update logic off the main thread but the transforms are in a hierarchy and need to be updated in a specific order.

devout prairie
forest quest
#

actually, looks like there's a Child dynamic buffer component too... not sure what the difference is, but it seems likely that this is what you actually want. It's inside the Unity.Transforms namespace, Parent.cs.

devout prairie
#

Yeah i think those are accessible the only issue is it's really difficult to know which entity is which when you have children of children etc.. I've ended up using Timboc's suggestion:

#

So basically i add an ICD to the root of the prefab with a public Entity myTargetObject field

#

drag my child gameobject onto that and it becomes referenceable at runtime

forest quest
#

oh nice!

remote crater
#

Turned out it was because I was setting the velocity directly of drones instead of adding a force aka acceleration. I am able to use: ApplyLinearImpulse in a Systembase, but cannot figure out how to use it in monoBehavior. My monoBehavior for setting PhysicsVelocity just uses SetComponentData.

#

Anyone know how to add acceleration to an entity via monobehavior script?

#

Maybe I am trying to get too eloquent. I'll just slap an ECS component on it.

devout prairie
remote crater
#

Well I know its funny

#

But...

#

The proper design pattern is to never reuse a function

#

So when everyone has their old player controlers in their game they've worked on for years.

#

And they want DOTS levels

#

The best way is to have all the enemies enviro be dots

#

and the player to still be controlled by same script, with a few if statements to see what mode you in

#

It's pretty awesome, high level design pattern stuff, not sure others know about this.

#

I'm not above making a hacking system along side it, I know the devs are doing what they can, but I'm going to do an extensive tutorial when I'm done with my game(very soon!) on how everyone can use DOTS/ECS easy and even in their existing games.

#

If you make two playerController scripts... It is bad:

#

then every time you update one, you update the other, cumbersome and bug ridden. I want to teach everyone how to do this the best and most eloquent way possible.

remote crater
#

This is kinda cool now that I have force based thrust, collisions handle better, but more needs to be done: https://youtu.be/tJ30xXE43Aw

Would you like to know more? http://www.youtube.com/c/goodnewsjim

You can also come to like the only positive zone of the Internet I know: www.twitch.tv/VGMCrazyJim The Bro Zone Layer. (temp)

The #1 video gamer who ever lived with proof! I just missed tourneys due to life problems(college for Starcraft thinking my email invite to Korea was a ...

โ–ถ Play video
remote crater
#

How do you get System.DateTime.UtcNow in burst? I tried a singleton in a monobehavior that stores it every update. When I access that in .burst, super slowdown.

#

If you slerp a rotation to lookat, that's fine,but you want 4 seconds after a collision for it to tumble, so you need time

remote crater
#

I'm probably missing a core concept of accessibility of variable scope. I've known about multithreads since the 90s, and know of race/memory corruption if done wrong... I know why you'd want to protect variables. I just ain't sure exactly some of the finer points of UNITY's implementation.

craggy orbit
#

DateTime appears to be a struct with only blittable members, so that's likely not the issue. it could be an issue based on how you access it. if you're trying to retrieve it from the singleton while inside the job, that's an issue. you should be passing it into the job when creating + scheduling it

#

i'd still try to pass in just the values that you need though, to eliminate any possible issues with DateTime

remote crater
#

Ty Ryan!

#

That's what I figured

#

Also accessing SIngleton Monobahavior statics from outside the job is bad for performance too right?

remote crater
#

Whoa, found and fixed bug was weird... Was giving an Error of System.DateTime, and I assumed it was in the Jobs and SystemBases I was editing, nah in code I wrote weeks ago in an IComponentData I was reading in. No line numbers or file names on error message: https://youtu.be/DsUxuHb-fL0

It was complaining about System.DateTime, which I assumed was in my Jobs ObsticleHitSystem, no, it was some very old IComponentData I was reading in a SystemBase. No line numbers on error means headache. But we got through it!

Would you like to know more? http://www.youtube.com/c/goodnewsjim

You can also come to like the only positive zone ...

โ–ถ Play video
#

I'm still not able to change an IComponentData in a Jobs Execute tho. I need to set the time that the collision happened. I do not know how.

remote crater
#

Oh!

#

I probably need an EntityCommandBuffer

acoustic spire
craggy orbit
#

oh wait

#

i misread

#

accessing monobehaviour statics outside of the job should be fine

tall pasture
#

Little question, How would I convert Vector3 array to float3 array, and Colors array into float4 ? Ofc i could write for loop, but is there some dedicated method ?

frosty siren
tall pasture
#
positions = new NativeArray<float3>(mf.mesh.vertices.Length,Allocator.Persistent);
colors = new NativeArray<float4>(mf.mesh.colors.Length,Allocator.Persistent);

positions.Reinterpret<Vector3>().CopyFrom(mf.mesh.vertices);
colors.Reinterpret<Color>().CopyFrom(mf.mesh.colors);
#

It works, thanks

devout prairie
#

Is there an easy/shortcut way to take the float3 position from a LocalToWorld 4x4 matrix?

#

current way is:

float4 pos4 = GetComponent<LocalToWorld>(myEntity).Value.c3;
float3 pos = new float3(pos4[0],pos4[1],pos4[2]);
#

my target object is a child, so Translation isn't helpful as it only seems to reflect local position

devout prairie
amber flicker
#

Careful relying on ltw.Position & ltw.Rotation - if you have any scaling, they're likely to be not what you expect/wrong

devout prairie
#

Ah ok i'll bear that in mind thanks

vital sandal
#

Hey guys I'm just starting with the job system (with regular code for now no dots yet) and i keep getting this error InvalidOperationException: M7.EntityData used in NativeArray<M7.EntityData> must be unmanaged (contain no managed types) and cannot itself be a native container type. I know it has to do with the types used in my EntityData struct... are Vector3 and Quaternion managed types?

karmic basin
#

Try with float3 and quaternion instead

#

will be Burst compatible ๐Ÿ™‚

#

Do you have a NativeArray inside a NativeArray ?

vital sandal
#

@karmic basin Mmm... not inside EntityData for sure

#

I'm a bit confused, I changed my vector3 to float3 and it still doesnt work

#

Are arrays allowed?

karmic basin
#

Any native container

vital sandal
#

ok thanks

coarse turtle
#

otherwise yeah use native containers

devout prairie
#

What's the best approach to look at or measure how long jobs are taking etc, performance measurements etc?

karmic basin
#

Using the Profiler

devout prairie
#

currently i can see the ms times of systems in the Systems tab

devout prairie
karmic basin
#

If you scrolla little down you should see the worker threads

amber flicker
#

Yup Timeline view is your friend!

devout prairie
#

i thought there'd be an ECS specific way maybe hehe

karmic basin
#

going to bed, see ya

devout prairie
#

okay, yeah i'm quite familiar with Profiler for non ecs stuff - thanks!

devout prairie
#

Unity keeps crashing when i try to play with Deep Profile enabled in Profiler - does this happen with anyone else?

#

I don't think jobs are visible without Deep Profile

#

Ah i do see the systems in Hierarchy view.. i was expecting to see jobs in the modules/graph windows

remote crater
#

Can you change an Entity's name?

#

Forums are saying you can't. So how do you search for an Entity who's data has changed in Entity console debugger?

#

I'll try and only ask one more question today after this.

#

I have hundreds or thousands of entities with same name. When a rare random event happens, I want to see the data change to see if my code works. It would be trivial to change it's name, then search in ENTITY_CONSOLE_DEBUGGER by name, then see Inspector data.

devout prairie
#

I think if you search for a Component in the Entity list view it will show entities that have that component.. so maybe add a component only on the case of that rare event, even just for debug

remote crater
#

A worekaround, I thought about that butw anted to make sure I wasn';t missing a way to change entityy Yah... or... having a global dummy entity you can change too

#

That way you never have to search non stop, just stay in the global dummy entity to see changes

#

It wouldn't be the first time someone said,"Unity made strange design choices on DOTS.", but were thankful there is anything at all.

#

I think they did a great job on making multithreaded sane

#

Whats funny is that I actually asked on /r/unity3d forums if there is a multi threaded library or if I had to write my own.

#

Cuz I was 100% going to sit down and write something.

#

I was right again on predicting big tech, like always, but to get it right on the same years, that even surprises me. Most of my ideas for big tech is like 5-20 yrs in future.

#

Last question for next 6 hours: How do I get component data from a job assuming I have an Enity reference like Entity entityA?

#

On the forums, everyone is asking this question with no answers, lol

#

I was able to set component data with an EntityCommandBuffer

#

But That is useless unless I have old data to modify

#

I can get components from Systembase and Monobehavior
I guess Jobs is the last frontier.

#

Sark says it is slow... hmmm

#

Maybe I want an actual component for almost every variable

#

Then I won';t have to read it in...

#

That'd be more in line with the deisgn

#

I'm just gonna trust that UNITY did proper memory arrays and hash tables n stuff that when I add dozens of components, no slowdown happens.

pliant pike
#

like this LocalToWorld targetTransform = GetComponent<LocalToWorld>(target.entity);

remote crater
#

tyty

#

Severity Code Description Project File Line Suppression State
Error CS0103 The name 'GetComponent' does not exist in the current context Assembly-CSharp D:\unity\projectfiles\StarfighterGeneralOnSteam\Assets\Scripts\DOTS3\ObsticleHitSystem.cs 61 Active

#

Says Getcomponent doesn't exist in the current context

#

I don't need that question answered, I think it is better for DOTS to not grab it

pliant pike
#

what version of entities are you using?

remote crater
#

Question I'd rather have answered, how do I get System.Date in a Job Execute?

#

I can't grab it directly

#

so I could set it in the Job globals, a singleton, etc

#

But I don't know how to break into any of those

#

.17.0-preview.42 Entities version

pliant pike
#

any data whether it's date, month, name, integer anything has to be made local in the Onupdate of where the job is

remote crater
#

I do that...

#

How do I access that tho

pliant pike
#

like you would any other variable ๐Ÿ˜•

remote crater
#

Like the system is outside the class

pliant pike
#

JobComponentSystem is old I don't mess with them anymore

remote crater
#

I want a variable from onUpdate to be accessed by Execute. Not sure how.

#

In the above code, I'm trying to link long rightNow; [ Millseconds since 1970 epoc], from Update() to Execute()[when a job collision occurs]

remote crater
#

Ok, I need both variables to be static

#

And it works

#

I hate monkeying with code, but sometimes you gotta if docs n stuff are poor

karmic basin
#

Declare your variable as a public property of your Job struct. Then on update of the system, pass the variable to the Job when you Schedule

remote crater
#

I had that already

#

What I was missing is that my data variable in Job Execute Struct was not static

#

where my global for class was

#

So when I made em both static, it was ok

#

Ty Mr. K tho, all you guys super helping

#

I ain't lying when I say if I make it big, which is a decent chance, and you track me down, I hook you up in person with the manilla.

karmic basin
#

Uhm shouldn't have to make it a static

Here ```cs
inputDeps = new CollisionJob()
{
soldierComponentData = GetComponentDataFromEntity<MovementDataEntity>(true),
ed= GetComponentDataFromEntity<EntityData>(true),
//obstacleComponentData = GetComponentDataFromEntity<ObstacleTag>(true),
commandBuffer = _endSimEntityCommandBufferSystem.CreateCommandBuffer(),

// Here you miss a line like this:
rightNow = rightNow2

    }.Schedule(_stepPhysicsWorldSystem.Simulation, ref _buildPhysicsWorldSystem.PhysicsWorld, inputDeps);
#

Based on your rightNow and rightNow2 variables

remote crater
#

I said I solved it bro

#

I was thanking you for chiming in

karmic basin
#

oh good then ๐Ÿ‘

remote crater
#

And I am not in game making for money, just to help people and make em happy, so like if you guys ever track me down, I manilla all you helpers.

karmic basin
#

I lagged behind, time to read all the stuff ๐Ÿ˜›

remote crater
#

Please do not come at me weaponized ๐Ÿ˜‰

#

I got you man

#

You're too busy helping. You don't have time to read! Mr. Jesse Ventura K.

karmic basin
#

Totally true I should get back to work

remote crater
#

ya, amen

#

The worst is the hate bots, when they twist what you say. Normal social media is dead

#

You can't get the voice out, it gets twisted, and censored.

#

Its alot like preinternet days now

#

Lets work

#

God bless. May God help all you guys make cool games.

honest dirge
honest dirge
#

No more input deps though? So that's just all done from the underlying job scheduling?

pliant pike
#

you can do it manually if you want but yeah its auto handled mostly

honest dirge
#

Good to know. Thanks! How does one even keep up with all these changes? Is there somewhere they document the new expected uses? Or is it just "just keep following the example git"

pliant pike
#

that link I posted you can view the changelog on there, and they update the docs sometimes

honest dirge
#

Appreciate the info.

zenith wyvern
#

Works the exact same way except you assign to Dependency instead of returning inputdeps

devout prairie
#

I think probs the easiest way to keep up is inside package manager, when you click on a package theres links to docs and changelogs for each package version

#

Some fairly obvious high level stuff I feel still needs docs or explanations, such as when you create a GetEntityQuery and use it to fill an array like with ToComponentDataArray, when does that query get filled is it a job that's run internally or what.. some things are a little confusing

karmic basin
honest dirge
vital sandal
#

I've got one of those new guy questions your afraid to ask...: With the job system, when passing data to a new job, should I pass it multiple NativeArrays for eanch value (ie.: pos, rot, scale, etc) or should I pass in a native array of a Struct containing multiple values? i.e. : public struct MyStruct{ Vector3 pos; Vector3 rot; Vector3 scale; }

#

?

coarse turtle
#

You can do that, or just pass in a float3x3 matrix

vital sandal
#

FYI I just use the job system no DOTS

#

Man you are awesome, that was my next question hahaha

#

So there is no performance difference between the two? The whole data still gets cached by the cpu?

coarse turtle
#

Depends, the CPU cache isn't exclusively used by your game, it's a shared resource. So if it can attempt to utilize your CPU cache, then sure your data will be copied into your L1/L2/L3 cache depending on available size

vital sandal
#

And if I may ask another easy one: When I pass a NativeArray to the job (when creating it) does it "copy" the data in the the job's internal native array?

#

I remember reading something about a poointer but im not 100%

coarse turtle
#

No native arrays are structs that point to a block of memory

#

so you just copy the address, not a deep copy of the data

vital sandal
#

Oh ok so its kinda like a ref but to a memory address?

coarse turtle
#

yea pretty much like a ref

vital sandal
#

ok so there is no perf lost feeding in values to or taking values from the job

#

thats great... you have no idea how lost I was hahaha

#

Thank you so much!

raw shadow
#

Yo is dots cross platform deterministic or no?

vital sandal
#

Or rather, does that help?

raw shadow
#

Yep

north bay
#

Did anyone here try the latest 2020.3 version out yet?

#

I remember seeing a DOTS forum post about something being broken in 2020.3.16 but I'm not sure anymore

vital sandal
#

@north bay Google has a lot of hits on "broken 2020" but nothing specific to 2020.3.16. Usually whatever breaks if it's not in the official notes it's an edge case so my experience may not be your experience. Your best bet is always to test it on a copy of your project. I learned to do this the hard way. I do this for every major version changes, for point upgrades I don't bother, I'ts easy to revert, I use Plastic SCM.

north bay
#

Yee just wondering if something major showed up like some obvious incompatibility before I go on idle for 2 hours

vital sandal
#

FYI I had no problem with that version but I havent done much in it either.

#

If you checked the forums for something that would affect you I dont think there will be any trouble

north bay
#

I normally just look for DOTS specific stuff, all other engine issues are normally fixed quickly ๐Ÿ˜›
Thanks for the responses, I'll try to update and see what happens ๐Ÿคทโ€โ™‚๏ธ

coarse turtle
#

I honestly tried updating to 2022.1.a the other day and dots still seemed to work too. Can't vouch for Physics/Hybrid renderer, but transport layer seemed to work also

vital sandal
#

Job system question: When setting a new job's data ie.: NativeArray<Vector3>, since it's set using a memory pointer this means if I modify the array within the job, similar to a ref the value gets changed outside of the job too right? (in the NativeArray I feed it)

coarse turtle
#

Yea

#

Ideally, you want to declare NativeArrays as readonly or writeonly

vital sandal
#

Oh really?

coarse turtle
#

so if your job only cares about reading the values

#

just declare it as [ReadOnly]

vital sandal
#

And I get my data out using a [WriteOnly] nativearray as the output? I can allocate it as temp in the job but could I also create an "output" NativeArray as persistent outside the job, assign it to the internal [WriteOnly] native array when creating the job and get the data just by writting to it inside the job?

coarse turtle
#

Yea

vital sandal
#

Awesome thank you!

devout prairie
#

i saw Entities.WithName().ForEach being used somewhere but i can't find out any information on how it's used exactly..

#

assuming it should use the specified name for the job in Profiler or something?

#

or do i have this totally wrong it's actually filtering the Entities query by name

rancid geode
devout prairie
#

i have three jobs running inside a system and trying to find which one is causing slowdown

rancid geode
#

Entities.WithName("HowYouWantToCallTheGeneratedJob").ForEach( /* as usual */ ).Schedule();

devout prairie
rancid geode
#

you will want to use the Timeline view

#

it should appear there as any other job

devout prairie
#

strange i'm not seeing them at all, just seeing the system name in the Main Thread

coarse turtle
#

check the job threads

#

if it's a job

digital kestrel
#

does anyone know what the ColliderKey is in a RaycastHit is?

untold night
#

it's used to identify a specific part in a compound collider.

I'm not sure but I think it would default to zero if it's just a single collider shape.

remote crater
#

So thanks to you guys, I have drone way points in and it is cool! https://youtu.be/d7TiaferQRw My next question is: Wait what was I going to ask?

Would you like to know more? http://www.youtube.com/c/goodnewsjim

You can also come to like the only positive zone of the Internet I know: www.twitch.tv/VGMCrazyJim The Bro Zone Layer. (temp)

The #1 video gamer who ever lived with proof! I just missed tourneys due to life problems(college for Starcraft thinking my email invite to Korea was a ...

โ–ถ Play video
#

Ok, none of you could answer what question I was gonna ask? I had to google that. Google said my question was,"Can we only send up to 9 components in a for each?"

#

I need to add more data in my program

#

and I want to add a new component

#

but if I can't

#

I need to make memory management strategies to overlap data stored into less components

#

Nothing major, just need a lil guidence

#

I have my MOBA out tonight or tomorrow

#

Likely tonight

#

Then MMORPG less than a week from that!

devout prairie
remote crater
#

I made it in DOTS years ago

#

took me 2 weeks after learning rollaball tutorial

#

10v10 MOBA, but couldn't find testers, so I kept making different things to attrract userbase

#

now I am finishing a MMORPG

#

But realized the MOBA would be one of many space dungeons

#

and i need that tech to make MMORPG engine

#

So Moba today, MMORPG tomorrow

#

I got another fun video in a few sec afteryoutube proceesceeds it

#

Would you like to know more? http://www.youtube.com/c/goodnewsjim

You can also come to like the only positive zone of the Internet I know: www.twitch.tv/VGMCrazyJim The Bro Zone Layer. (temp)

The #1 video gamer who ever lived with proof! I just missed tourneys due to life problems(college for Starcraft thinking my email invite to Korea was a ...

โ–ถ Play video
#

Now with new networking, it is infinite vs infinite players same zone

#

Good thing dots came along to help with more things on screen

#

That video isn't just fun to look at, I actually make some jokes, so I'm not sure if it is better or worse.

#

Anyway, I bring entertainment in hopes someone answers my .foreach question: We limited to 9 components? Can we get more components some other way? Or do we need to stuff components with data that belong in multiple components?

karmic basin
#

Come back in January :P

remote crater
#

Great, my game should be out by then

#

no changes is good changes

#

snow?

karmic basin
#

Dunno but they said compatibility with editor versions past 2020.3 will last to at least end of the year

#

My sentence makes no sense but you get it

#

I'm on the phone

#

Anyway I expect everything to stay stalled at least 'till january

#

But who knows ๐Ÿคทโ€โ™‚๏ธ only Unity employees

remote crater
#

JohnOT, what you need to remember is this cutting edge technology only works on older versions of UNITY

#

lol

#

hold still, this week I unlock the key to enlightenment in DOTS ECS on youtube

#

even take your old game and say,"Game, B ECS"

#

and Game will be like,"I don't want to, but okay." Then later game will be like,"Hey, this is great. Glad I thought of it."

#

Check my youtube by this friday

karmic basin
#

They told many times they want to streamline the workflow, so we're sure they're concerned about it. But man it sure take a looong time

#

I'm off, see ya guys ๐Ÿ‘‹

remote crater
#

JohnOT it is simple

#

but you gotta be in the know

#

I am gonna make a tutorial this week, you'll LOOOOOVE It

#

I already helped a dude weeks back and he loved it. I have a download if you want to try raw

#

Well that was a year ago

#

I'm a forerunner now man

#

I have 150,000 hours gaming,coding, design

#

I'm like beyond a rockstar for general programming

#

Just cuz you ask questions, even very easy questions, doesn't mean you're a nub. Hell, Einstein didn't even know how many feet were in a mile.

#

Anyway I wrote that 4wumbla for a guy months ago who requested personal help. Its a raw and basic project

#

I didn't come to boast, but to say I'm not a noob that could help you, but I do have signed cards, where do I mail em? ๐Ÿ™‚

#

Been #1 world every online video game I played, just missed tourneys, lol

#

I got proof if you come to stream, Soul gamer since 1980.

#

But if you don't want my help, you know, you can figure it out right?

#

And I didn't make myself great, it was the God of Love who binds the universe together so we can achieve peace through Jesus.

#

I don't boast of myself, but my Creator.

brisk trail
#

Hello everyone, I'm trying to get advantage of Jobs system, but seems like I'm missing some key parts, is there anybody experienced in that?

#

It's clear that only struct are valid for jobs, but what if I have tree data structure, where each node has an array of it's children?

coarse turtle
#

or any other feasible NativeContainer

brisk trail
#

Struct can't contain pointer (unless it's unsafe code)

coarse turtle
#

if you're comfy with writing unsafe code, yea you can pass it into a job

brisk trail
#

Do you think it worth it? Maybe there is a more elegant solution?

coarse turtle
#

you can try to transform your tree structure into another data structure that's supported out of the box

brisk trail
#

So.. Like flat list of elements and another one map with index => array of children indexes ?

coarse turtle
#

sure, whichever works for how you want to set up your tree

#

You can also take a look at FixedList in the collections package if you can utilize that

brisk trail
#

Alright, I'm going to test right on, thanks a lot!

devout prairie
#

Anybody any idea what EntityCommandBufferManagedComponentExtensions is

karmic basin
#

Based on the naming, a bunch of methods so ECB's can work with managed components

#

๐Ÿ˜›

devout prairie
#

Hehe yeah, just trying to figure stuff out

devout prairie
#

so i guess it's used internally when using for example ecb.AddComponent to add a managed IComponentData to an entity

karmic basin
#

Yep

empty cloud
#

Hello, quick question about design. I'm making a factory game where each building is an entity. I need to make a storage container which has a set number of item slots, let's say 64. Each slot of the container is represented by a 16 bit integer for the item ID and an 16 bit integer for the number of items in the stack. That's a total of 256 bytes. From what I understand, this is rather large for a component and could result in worse performance. Is there another approach I can take that avoids using large components?

rotund token
#

I assume you're putting this in a dynamic buffer?

#

If you're concerned about archetype size you can just add a [InternalBufferCapacity(0)] to the IBufferElementData struct to make the buffer live outside the chunk

#

Alternatively if you want to live in the chunk for performance, you should optimize it with [InternalBufferCapacity(64)] as you know the exact size the buffer needs to be

frosty siren
#

<@&502884371011731486> seems like message above is advertising of financial fraud

glacial bolt
#

!ban 380690564036689920 Scam

past palmBOT
#

dynoSuccess Baianoloko#2692 was banned

devout prairie
# empty cloud Hello, quick question about design. I'm making a factory game where each buildin...

Not sure if it's relevant to your case and i haven't looked at or tried this myself but i saw this method of using blob assets for data storage:
https://www.youtube.com/watch?v=PeTcIzoaTEA

๐Ÿ“Œ Download the full project files: https://tmg.dev/BlobAssets ๐Ÿ“Œ
๐Ÿ‘จโ€๐Ÿ’ป Code/Scripts from this video: https://tmg.dev/BlobAssets-Code ๐Ÿ‘จโ€๐Ÿ’ป
๐Ÿ’ฌ Come chat with other DOTS/ECS devs: https://tmg.dev/Discord ๐Ÿ’ฌ

๐Ÿšง Resources Mentioned ๐Ÿšง

โ–ถ Play video
#

I guess not actually as this is generally for data that does not change or update throughout your game.

devout prairie
#

I just noticed that the player.log for my built project is not showing full GPU vram whereas editor.log is showing the correct amount:

#

Anybody noticed this?

hollow sorrel
devout prairie
hollow sorrel
#

depends on graphics api and how unity implemented it but i guess not

twin raven
#

I'm trying to wrap my head around hybrid approach. I am using Convert and Inject Game Object conversion since I am using standard rendering and some monobehaviours for visuals. Will I be able to avoid runtime conversion If I save it as a subscene (Subscene = Entity Prefab?) and instantiate from code?

karmic basin
#

What is standard rendering ? Built-in pipeline ?
Using subscenes will save you the conversion at runtime. It will do the conversion at editor time (when you close the subscene). What it does is serializing your entities to disk, this way the loading into memory will be faster

#

With subscenes you don't need the Convert&Stuff anymore, nor to instantiate

devout prairie
#

I've noticed that some of the code in Unity samples creates entities with empty component array like this:

Entity entity = entityManager.CreateEntity(new ComponentType[] {});

Does this avoid some default component creation or something?

coarse turtle
#

no, just creates an entity without any components

devout prairie
coarse turtle
#

sure

devout prairie
#

so no difference to just Entity entity = entityManager.CreateEntity();

#

or perhaps that would throw some error, i've never actually tried, was just curious tbh

karmic basin
#

Supposed to work without parameters, I don't know why they do the line you shared ๐Ÿคทโ€โ™‚๏ธ

devout prairie
#

Another stupid question but i rarely ever see this and have no idea what these curly braces do:

#

I guess it encapsulates the scope of the work being done..?

coarse turtle
#

it's pretty much an explicit constructor

#
var vec = new Vector3 {
 x = 0,
 y = 1,
 z = 2
}
devout prairie
#

yeah i use that convention often but this threw me off as Entity head; ends with the semicolon

coarse turtle
#

oh

#

after Entity head; the curly braces introduce a local scope

#

similar to nesting functions

devout prairie
#

fair enough i guess

#

i guess if nothing else at least it can be collapsed in a code editor

#

i guess also it's actually useful for creating local variables and discarding them

#

like the CollisionFilter filter = is created/used within the braces for the head entity, but then it's created and used again for the torso entity a few lines down..

#

so it avoids having to track variables you've already declared previously

unreal wraith
#

how would i go about implementing jobs into something that uses classes

rotund token
#

rewrite your classes to be unmanaged structs

dense oriole
#

hi -- can you programatically spawn a prefab with authoring scripts inside a subscene (at runtime)? I have a problem with that

slim nebula
twilit coral
#

is there a way not to check for Physics while doing RaycastCommands, I know it could have old version of the world, but I am mainly targeting static geometry

unreal wraith
#

@rotund token whats the difference between a struct and a unmanaged struct

rotund token
#

just a struct with no managed components - the requirement for burst
by default structs can have managed fields, like List<T> etc but burst can't use this

twilit coral
#

Is there a reason why float3 result is empty when job is finished? debugging results[0] after the job is done gets me actual value.

#

Writing to NativeArray<float3> of size 1 does the job, but is it as fast as using just float3?

zenith wyvern
#

The only way to retrieve data from a job is via a native container. You can use NativeReference instead of nativearray for single values

twilit coral
#

thanks, will look into that

shell berry
stiff skiff
#

It's because the struct is a value type

remote crater
#

How do I copy a rotation of an entity to a gameobject? I see: CopyTransformToGameObjectSystem , but I see no example code online.

#

I can do it in mono, jobs, or systembase, doesn't matter. If there is a way to just change rotation, that is fine too.

karmic basin
#

TransformAcces is a special component meant for doing a lot of tasks in parallel. If you want to do it for one object only I would write another system I guess.

#

The idea is to retrieve the rotation from the LTW and give it to the transform.rotation

#

of the gameobject

remote crater
#

My question is a little more basic syntactically. I have an Entity and a GameObject reference How do I call it? I have not called Transform before in entities. To get a reference to a transform, is it like: transforms = GetComponentDataFromEntity<LocalToWorld>();

#

I think i'm getting it

#

The meat is:

#

bot deletes two lines of code

#

transform.position = value.Position;

#

transform.rotation = new quaternion(value.Value);

#

There, just need to post them dif lines

#

Thank you again Mr. K.

#

I was grabbing translation which also seems to have rot and pos

#

Instead of transform

devout prairie
#

Are there any docs for the Animation package i'm struggling to find anything

#

like anything, even a basic api reference with what's in the package

karmic basin
#

I',m not even sure they have a graph based authoring tool ? Last time I checked it looked like it was only a coding API. Some people here (like thelebaron, don't want to tag him) might have fresher news

#

I'd look on the forums, or blog posts if you're lucky ๐Ÿ™‚

devout prairie
#

There is an Animation Graph under Window>Animation>Animation Graph but it only has access to two nodes, Animation Clip and Mixer..

#

I know there is also an NMixer node and possibly a bunch of others in the package but they don't seem to be exposed to the visual graph

#

I saw thelebarons posts about ragdolls i have to say i'm curious how he did that

#

i currently have skinned ECS characters animated using blended clips via unity.animation thanks to PhilSA's nice work on his Rival dots character controller package

#

i also have a basic dots ragdoll setup working

#

but i'm investigating how to possibly connect the two somehow

#

currently my ragdoll is literally just a collider/body setup and is not driving a skinned character at all

karmic basin
#

Oh didnt even see that

safe lintel
#

most of the nodes you need to make use of stuff are missing last I checked with the animation graph ui

#

to modify the skinning buffer you need to write to the AnimatedLocalToRoot buffer, by using the SkinnedMeshToRigIndexMapping

#

@devout prairie

devout prairie
#

I'll have a look through this shortly, looks really useful

#

Hmm this is very cool.. i'm wondering if it'd be possible to do something similar but feed the ragdoll translations into an animation graph and do the work there

#

bear in mind this is very abstract high level thinking at this point with very little frame of reference for whether such a thing is even remotely possible ๐Ÿ˜›

#

from what i understand, the animation clip and mixer nodes use a data stream called AnimationData

#

i wonder if it's possible in some way to feed translation data into this

rugged grove
#

what is required to convert a skinned mesh? I'm making a ragdoll, I attached physics bodies with colliders to bones in a subscene. The bones move, but the mesh is not deforming at all

devout prairie
rugged grove
#

thanks. I'm also looking at the skinned mesh samples by Unity

safe lintel
#

pretty sure you could do it that way too, just get the buffer and read it and do the work in a node. personally easier for me to make sense of things in systems and jobs though

rugged grove
safe lintel
#

but for simple stuff like timing, ie make a character instantiate a bullet at a specified frame, there's nothing to handle animation events, and the cognitive load to continue to do everything in nodes is just too much. i think its probably better to wait for the next release which i assume will have a working visual graph that will greatly simplify things

#

@rugged grove set the AnimatedLocalToWorld(its a buffer of all the skinned joints that correspond to deforming a skinned entity) like I did in the gist

#

also have to remember unity physics either will merge a collider if static or unparent and disconnect everything if its dynamic and you have to manually manage the connections and disabling/enabling a kinematic or dynamic state or even disabled depending on how you want to do things

#

id ultimately say wait for the next version though as painful as waiting may be

devout prairie
rugged grove
#

I guess I'll just declare skinnedMesh as hybrid and just copy physics positions to the game object bones

#

thanks for the info

safe lintel
#

definitely complain on the forums though, try to get a response from the devs ๐Ÿ™‚

remote crater
#

What is the best way to destroy an Entity after a set amount of milliseconds?

#

Google drawing a blank. Dots/ECS forums UNITy style drawing a blank

#

I see people with these atrocious update functions checking against the time every update

#

When a better solution would be to have one systemBase that hashes the destruction time

#

That way you have one check per cycle instead of hundreds or thousands.

#

Does Unity already have such a systembase already in? Probably not. I'll start system architecting it. Let me know if anyone knows if UNITY devs did it right already

remote crater
#

So I want to start with one of those bad solutions... Except when I send simply one destroy message to an Entity Commnd Buffer, it starts giving errors: https://pastebin.com/DRcF3M75 in code: https://pastebin.com/5yj8vuGE. I think one of two things is going on: Either my .ForEach((Entity e, ref DOTS_DESTROY_AFTER_TIME dat) isn't getting a reference to the Entity e, or maybe I am not closing down my CommandBuffer correctly and it keeps getting called. I ecb.DestroyEntity(e) only one time, but errors keep happening, about the time to destruction and doubling their rate each time.

rotund token
#

i'd benchmark it before spending a lot of time on something else

devout prairie
#

afaik because it's a .Run, it'll execute the ECB on the main thread anyway

#

but i think that's maybe a separate issue

#

kinda hard to say what's going on with your timer code as it's a liiiitle bit hard to follow but for that stuff i generally try and simplify as much as possible

#

so for example set one float on your DESTROY component, called say 'remainingTime'

#

and decrement that each time

#

or even 'startTime' and init it to Time.Elapsed time

#

then just do a read on it, and if Time.ElapsedTime - startTime is greater than your countdown, kill the entity

#

atm you have john, timeSpawn, lifeTimeMS, destroyedOnce

#

i think i follow what you're doing but i'd simplify it

remote crater
#

Oh, the destroy gets called

#

I threw in the boolean so it only gets called once, and I have hundreds of objects that would be calling it

#

yet despite only one destroy being called, it triggers infinite error messages, spaced 1 for the time of despawn, 2 for the next time, 3 for next, etc

#

destroyedOnce is just a debug variable to isolate it to only one time a destroy ever gets allocated into the EntityCommandBuffer

#

It will be removed later.

#

long john; is just what I call my ms elapsed since epoc 1970

#

and timespawn is when the entity is spawned, individual to each entity

#

and lifeTimeMs is set earlier for how long

#

that part is all a red herring

devout prairie
#

hehe john is a good name for that

remote crater
#

If you make it memorable it is searchable through all filesable.

#

The only part that matters is: How do I destroy an entity properly?

#

I tried doing it without Entity Command Buffer and I think it was mad too.

#

It is definitely reading entity data from timespawn and lifeTimeMS, so it is a valid entity

#

Does .forEach(Entity e, ref whatever), give the entity of the whatever ref? or is there a chance it is null?

devout prairie
#

maybe your system needs to be in the Init group, as your buffer is set to fire on EndInitializationEntityCommandBufferSystem

remote crater
#

Let me look into that, thank you.

remote crater
#

That was not the case.

#

A separate issue... I can't seem to get arrays working in IcomponentData, this one, when I access ts.pointx, it is the same value for all entities with DroneDataEntity. https://pastebin.com/NZacepGN I thought I'd have my MOBA launched today, but some very minor details hung me out, and 25 crashes of UNITY held me back. I have them on video if any devs want to see, but won't publish to youtube cuz I want to promote Unity not showcase its flaws. In fact after I launch this MOBA, I'll do a BOSS youtube on how to use ECS very easily.

remote crater
#

Solution: I tried IComponentData off the codemonkey tutorial, but it was throwing errors. https://www.youtube.com/watch?v=XC84bc95heI

Revisiting it, Yeah, that fixed it! The problem I had was my .foreach had 9 elements and I needed more... But you are limited to 9 which isn't fun. I ditched one I didn't use anymore, and put it in. My last attempt, I was trying to nest a buffer inside an icomponentdata which is a nono.

โœ… Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=XC84bc95heI
Let's learn about Dynamic Buffers so we can store multiple values inside our Unity DOTS ECS Components. (Array, List)

Unity DOTS ECS Playlist
https://www.youtube.com/playlist?list=PLzDRvYVwl53s40yP5RQXitbT--IRcHqba

If you have any questions post them i...

โ–ถ Play video
shell berry
# remote crater Solution: I tried IComponentData off the codemonkey tutorial, but it was throwi...

If you're reaching those limits, maybe you should try chunk iteration. https://coffeebraingames.wordpress.com/2018/11/25/unity-ecs-basic-chunk-iteration/

earnest hill
#

What is the proper way to use float4x4.LookAt as a replacement for Transform.LookAt in a IJobParallellForTransform job struct?

halcyon plume
#

Hi. how to use unity dots + mlapi?

stone osprey
#

Any tipps on how we could deal with conditions in ecs ?

Lets say i have an mob entity. That mob should be invisible once a certain condition is true... like when it reached a spot, when it has some certain item in inventory and stuff like that... how would that look like ? I cant imagine this in ecs yet :/

safe lintel
#

afaik theres no special compatibility for mlapi and dots, you will need to treat it like regular a hybrid workflow @halcyon plume

left oak
stone osprey
#

Or any example on how this would look like applied on an entity ?

left oak
#

Ah, sorry, yeah, this is more like the academic theory behind how you might do this. It's not a great practical example as it's written in c++, but it describes how to clearly handle conditional processing using database entries instead of if-statements and booleans - essentially what we do in ecs

stone osprey
# left oak Ah, sorry, yeah, this is more like the academic theory behind how you might do t...

Ah i see ^^ The example however is a bit odd... well i can understand how it helps to reduce iterations in this particular case.
But lets say we want entities to hide/stop being rendered in different situations. How would the entity structure look like ?

I had something like this Entity{ Renderer, InvisibleWhenOnSpot{ pos }, InvisibleWhenItemInInventory{ itemType }} in mind with a system iterating and disabling the renderer when one of them is "true"... or probably even Entity{ Renderer, InvisibleWhen{ enum[] conditions }} or Entity{ Renderer, InvisibleWhen{ ICondition[] }}...

Based on a short insight of that paper i would assume that the first variant is the best ?

left oak
#

In abstract, there's an even better chapter on that specific problem ("what to show") - https://www.dataorienteddesign.com/dodbook/node6.html - however, in your specific example, I would personally use tags to trigger such a thing, but there's no real consensus as to whether it's better to use tags or components with booleans to control behavior at this time. In the future, we might be able to add/remove tags as bit-flags without changing an entity's archetype, but at the moment it is a structural change

stone osprey
# left oak In abstract, there's an even better chapter on that specific problem ("what to s...

Thanks ! So you mean this ? Entity{ Renderer, InvisibleWhenOnSpot{ isTrue, pos }, InvisibleWhenItemInInventory{ isTrue, itemType }} and then two seperate systems processing WhenOnSpot and WhenItemInInventory to set the bool state and one other system to render that entity based on those bools ?

I think tags are no option here becasue i want to add data to the conditions which may change ^^

left oak
#

I understand wanting to do that. However, without tags, you wind up checking every entity every frame for the conditional values. You can by all means have component data that determines the transitions, but I recommend using tags to control the conditional processing. For example, an entity that's disabled only needs to check if it should be re-enabled

twin raven
#

I need a simple trigger for dots physics and found TriggerGravityFactorAuthoring.cs from dots samples. Seems like a lot of boilerplate, so I want to make sure that this is the current way of doing this?

stone osprey
# left oak I understand wanting to do that. However, without tags, you wind up checking eve...

Ahhhh thanks ! ๐Ÿ˜„ I assume you mean a component that marks an entity with "trigger" ?
Then our archetype would kinda look like this : Entity{ Renderer, InvisibleWhenOnSpot{ pos }, InvisibleWhenItemInInventory{ itemType } and two systems iterate over WhenOnSpot and WhenItemInInventory to add a Invisible component to the entity to symbolize the condition... then we just have a InvisibleSystem which basically iterates over the invisible triggers/tags/markers - Components ? ^^

remote crater
#

Anyone know how to solve the error: "All entities passed to EntityManager must exist". One of the entities has already been destroyed or was never created. [Hint, it happens when destroying Entities in EntityCommandBuffer. Hint #2: Things worked before back in my old project so maybe it is a ComponentSystemGroup order thing]

left oak
#

@stone osprey, a tag is just a componentdata that has no member fields. There's no reason you can't use components with data as if they were tags (to query them as the conditions for running a system). I think of this as almost a kind of state machine with the component tags as representing transitional states. For the moment, let's imagine our archetype is just Entity {Position, Inventory} and assume it's in a chunk with rendering shared component data. If I were simply enabling and disabling renderers, I would have at least two systems - a DisablingSystem and an EnablingSystem. The DisablingSystem would only run on entities without the Disabled component (which is what Unity uses to hide renderers). In turn, the EnablingSystem would only run on entities with the Disabled component. In each of these systems, we can check the Position and Inventory of each entity. If the Disabling System finds an entity that meets the criteria to become invisible, it can add the Disabled tag to that entity. If the EnablingSystem finds an entity that meets the criteria to become visible again, we can remove the Disabled tag. This is a simplified example, but it would accomplish this one task at least.

remote crater
#

I think I need that web page that says Burst Compiler Order of Operations. What I think is happening is an Entity is slated for delete, but another Job or SystemBase tries to reference it.

left oak
remote crater
#

Thank you Draveler

#

I was looking at pages similar to this, but not this one.

#

Deletion happens in: [UpdateInGroup(typeof(InitializationSystemGroup))] &BeginInitializationEntityCommandBufferSystem ERROR thrown in: [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] & EndInitializationEntityCommandBufferSystem

north bay
#

I'm personally a big fan of tagging entities that should be destroyed and only have one system around that is responsible for deleting entities tagged with that component
That way you don't have to get a headache thinking about EntityCommandBuffer order when your code base starts growing

#

And all AddComponent/RemoveComponent/SetComponent whatever calls you do through the EntityCommandBuffer are guaranteed to be safe

remote crater
#

Yes Script, I literally have a single system to delete entities

#

But when I do, it throws an error

#

In fact places in other systems that used to delete fine

#

Now they can also not delete

#

Ie, I found this script a while ago: ObsticleHitSystem.cs

#

It had destroys in it and it was cool.

#

I removed em tho.

#

Then I went back after I couldn't destroy to see that old ObsticleHitSystem and why it worked...

#

Turns out it throws errors too

#

Well I have DOTS_DRONE_AI in this error, maybe I can gut it.

unborn totem
#

Hello all. Is there a way to convert a single Monobehaviour component into an Entity component? Or do I have to create a GameObject, attach that Monobehaviour component, and then Destroy/Convert it into an Entity?

#

I am trying to take this and turn it into an Entity component.

karmic basin
remote crater
unborn totem
#

Physics Shape is (in the code) named PhysicsShapeAuthoring

#

it is a Monobehaviour script

karmic basin
#

You're looking at the authoring component (monobehaviour)

unborn totem
#

I am wondering if there is a way to cause that authoring component to convert itself to an Entity component without spawning a gameobject and destroying it

karmic basin
#

it will indeed put these values to a PhysicsShape component on the entity converted from this gameobject

karmic basin
#

rigidbody would be the PhysicsBody or whatever it is called

unborn totem
#

@karmic basin say I don't want to create a gameobject and have it destroyed. Say I already have an Entity and just want to copy this Authoring component's info to that existing entity.

#

is that possible?

karmic basin
#

the Entity is pure ECS ?

unborn totem
#

yes the Entity is pure ECS

karmic basin
#

You don't author it through a gameobject ?

#

ah

unborn totem
#

it is a more complicated story than that, but the Entity is pure ECS for the sake of not going into the long story

karmic basin
#

lemme see, first thing that comes to mind is having a system grab the values from this proxy entity, apply it to the entity you're interested in, then delete the proxy

#

or you could maybe grab a reference to that entity during conversion and apply the component to it ๐Ÿค” (more hacky IMO). <--- Nah bad idea the entity doesn't exist yet

unborn totem
#

i want to avoid creating a game object with this component just to destroy it

#

i was hoping there was a method to be like "hey, convert just this component and return the result"

#

but maybe there is not

karmic basin
#

component don't exist on their own

#

they need an entity

#

if you're going pure ECS, then why not go all the way and add the component from code ? ๐Ÿ˜›

#

it's just a struct you init the values and add it to entity

safe lintel
#

there are examples to create physics colliders from code in the PhysicsSamples repo

unborn totem
#

they don't, no. but let's say I have a GameObject loaded in memory (in my case from an AssetBundle). I already have an Entity created ahead of time, and I'd like to say

"Hey, GameObject I loaded from an AssetBundle, give me that single component you have there and let me throw it on this Entity that already exists."

Otherwise, I'll have to create a copy of the GameObject from that AssetBundle just to destroy it to then copy that struct that gets generated.

#

or Create a blank gameobject, and copy the physicsshape component, and let it be destroyed

#

in any case, I am trying to avoid creating a gameobject to do this at all

unborn totem
#

because I could be doing it several thousand times every few seconds

#

in my case there is no proxy entity

#

there is an entity, and there is a GameObject with the PhysicsShapeAuthoring component

karmic basin
#

Convert the one the physicsShape is on, from your screenshot

unborn totem
#

yes, that's what I am asking about

#

is there a way to do that without putting it on a GameObject that is destroyed?

#

Or is that the only way to convert a PhysicsShapeAuthoring component?

#

Creating and destroying GameObjects is expensive

karmic basin
#

lemme re-read your questions, looks like very specific setup

safe lintel
#

if you are not using subscenes to create entities beforehand and you will need to create colliders from code by the thousands, I think that will be expensive

karmic basin
#

If data is always the same he could eventually use Blob Assets ๐Ÿค”

#

But same hassle yo uhave to write conversion code

unborn totem
#

Did my question make more sense after a re-read?

#

Basically I am asking if there is a way to convert individual components and shove the result onto an existing Entity, instead of the workflow I am familiar with, where you have components on a GameObject that gets destroyed/turned into an entity and its components turned into Entity components.

safe lintel
#

yeah he could use blobs, not sure if hes making unique colliders or not

karmic basin
#

I get that you're tied to GO's from an AssetBundle so you don't do what you want, but still, in this case going the 100% pure way makes your life harder than choosing the hybrid approach with Subscenes, and Companions and such

unborn totem
#

i can't do that because this is all runtime streaming of AssetBundles

karmic basin
#

Oh i see. Never pushed that far

#

is it a mmo ?

unborn totem
unborn totem
#

so yeah, my collision info won't change (though each assets has its own unique collision info obviously)

#

i'm worrying about that part when I cross it

karmic basin
#

yeah so the component you screenshot doesn't even exist, right ? you can go the 100% runtime route and add the component via code

unborn totem
#

it exists on the AssetBundle

safe lintel
#

ive never bothered with assetbundles but creating physics entities through code is simple enough, the ragdoll example is the one that comes to mind but simple geo is like

public PhysicsCategoryTags belongsTo;
public PhysicsCategoryTags collidesWith;

//
var filter = CollisionFilter.Default;
filter.BelongsTo    = belongsTo.Value;
filter.CollidesWith = collidesWith.Value;
var groundCheckCollider = Unity.Physics.SphereCollider.Create(new SphereGeometry
{
    Center = float3.zero,
    Radius = groundCheckSphereRadius
}, filter, Material.Default);
dstManager.AddComponentData(bodypartEntity, new PhysicsCollider { Value = groundCheckCollider });
#

and then add the other physics components according to whether static or dynamic etc

#

i dont know how optimized it is for runtime in large quantities though

unborn totem
#

thanks everyone for talking through it with me, and for the assistance

devout prairie
# unborn totem it exists on the AssetBundle

would i be wrong in thinking, you're looking for a way to convert an asset to entity via code.. so like this:
Entity prefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPefab, conversionSettings);

#

which will convert the gameobject hierarchy, including components like Rigidbody's, Colliders etc, into an Entity hierarchy

twin raven
#

It happens with any primitive gameobject. I guess it is not meant to be used with hybrid approach and unfortunately there wasn't really any documentation about this.

coarse turtle
#

If it's hybrid are you adding a companion component?

#
conversionSystem.AddHybridComponent(someGameObject.GetComponent<MeshRenderer>());

// Get the mesh filter and such
...
twin raven
#

I was just testing with primitive gameobject with ConvertToEntity component and "Convert And Inject Game Object" selected

#

Oh alright, I will try that

coarse turtle
#

Yea dunno about that

#

I thought you were trying subscene

#

Since you don't need ConvertToEntity on gameobjects in subscenes

twin raven
#

Yes I tried to place that object to subscene, but then it is not rendered. I guess the subscene conversion works differently

#

And by hybrid I meant Hybrid ecs, gameobjects for rendering and effects, and logic for rest. Didn't mean Hybrid rendering ๐Ÿ˜†

coarse turtle
#

Yea, idk much about hybrid rendering since I don't use it

twin raven
#

thanks @coarse turtle , works like charm:

class ConversionSystem : GameObjectConversionSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((MeshRenderer renderer, MeshFilter filter) =>
        {
            AddHybridComponent(renderer);
            AddHybridComponent(filter);
        });
robust scaffold
#

After a few months break, I've reinstalled unity. I see nothing has changed... which means my project is perfectly fine. The bad: DOTS is dead. The good: my project using DOTS that I put in the freezer has been defrosted after a 4 month break has 0 errors and compiles correctly. Gotta take the good with the bad.

devout prairie
amber flicker
amber flicker
# devout prairie Quick question on the forum if anybody wants to chime in.. https://forum.unity.c...

Is this referring to e.g. IJobChunk, IJobEntityBatch etc? There's mostly one very compelling reason to use them instead of ForEach (lambdas) - though there are other reasons too.
The main one is that you can check data on the chunk level and e.g. early out. For example, if you want to early out if a certain component exists. In a lambda, you need to check every entity (using HasComponent<Blah>). In a manual IJC/IJEB etc, you can just check the first entry of the chunk as you know that every chunk contains only entities of a specific archetype. That make sense?

devout prairie
amber flicker
# devout prairie Hmm yeah that makes sense.. with ForEach lambda and EntityQuery you can specify ...

Sometimes you still want to process the entities but treat them differently based on e.g. the presence of a combination of components. One way is to write many ForEach's with a lot of copy/pasta code. Another is to write it out in it's more full form. There are also other reasons to use the more full form (ForEach just compiles down to IJEB basically) but they're more subtle I'd say. Depending on your situation too, scheduling more ForEach's could well be more expensive than the work done in a single one (esp with low entity count off main thread).

devout prairie
north bay
#

For me it just comes down to compilation times
The IL weaving that makes Entities.ForEach work can become a major iteration slow down the more your project grows

devout prairie
steel vigil
#

after two days of learning about dots and how it works, I still don't know what to use it on

#

I know I'm not supposed to use it for making a full game using it

#

what could I use it on?

#

I don't see how I could use ECS for physics since, that would turn the players into entities as well-

#

in order for them to work-

#

since I'm making a multiplayer horror game with AAA graphics, I thought I could use this to somehow get more performance

#

if you have an answer please ping me

amber flicker
steel vigil
#

I'm using HDRP so the only problem I'm experiencing atm is constant high cpu times

#

like 10 - 20 ms

amber flicker
#

... due to?

steel vigil
#

I actually don't remember

#

I'm gonna check hold on

#

cause another major problem was the amount of draw calls and everything surrounding rendering because of HDRP

#

rendering is just very slow for some reason

#

nvm, I now checked again and it's mostly the editor adding a lot of overhead

#

the amount of draw calls is still ridiculous tho

#

but again, I was just asking what ECS is usually used for

#

I see that it's used for multithreading and stuff?

steel vigil
#

considering my project, should I use it?

#

as I stated above, it's a multiplayer horror game that I aim to use modern graphical features in

zenith wyvern
#

It depends what your bottleneck is. Integrating ecs into an existing project isn't trivial. Just using jobs/burst without ecs can give a huge performance boost in a lot of cases

#

And is a lot easier to integrate

steel vigil
#

how could I do that?

zenith wyvern
#

If rendering is your bottleneck, the hybrid renderer might help depending on how your objects are structured. It's great at rendering lots of entities that share the same mesh. If you have really complicated scenes with lots of different meshes and fancy lighting and effects then I'm not sure it'll be much help. Probably the opposite as the integration with urp/hdrp is not great yet from what I hear

steel vigil
#

from what I can tell

#

it's just installing the package and adding the script dependency thing

#

and it says throws a message in the console saying

#

Hybrid Rendered V2 is active

#

something along those lines

#

so, that means it works and I don't have to do anything else, right?

zenith wyvern
#

No. Whatever impression you have that this is something you can just easily drop in your project, that isn't correct. If you want to integrate ecs it's a very slow process with a lot of learning.

#

And the documentation isn't ideal in a lot of cases

steel vigil
#

I see

amber flicker
#

Fwiw in your case I'd recommend staying away from DOTS for now. Probably looking at how to reduce your draw calls etc will get you a lot more ROI.

steel vigil
#

I don't know why it's like

#

a plane, a cube and a sphere with lighting, have like 500 draw calls

#

I'm thinking of just editing the render pipeline or something

#

I have one last question about dots tho

#

would it help at all if I were to use it on items?

#

in my game you will be able to drop items on the ground for example

#

if there were a couple thousand items, could dots help in any way?

#

I saw someone using it to spawn thousands of entities at once

zenith wyvern
#

I'm not sure, that's kind of an abstract question. Objectively speaking, if you spawn thousands of gameobjects in one frame, Unity isn't going to like that. If you spawn thousands of entities, Unity won't care. But if those entities need to be rendered, it depends. Do they share the same mesh? Is there lighting? Do you need to process them every frame or something?

steel vigil
#

let's say I wanna leave glowsticks so players know where they've already been to

#

I don't have a better example

zenith wyvern
#

Also you're going to have a real headache if you try to have some parts of your game as ecs and some parts not. I really can't stress how nontrivial it is to integrate ecs into an existing large project. And even to get to the point where you can do that probably requires a few weeks of learning from examples and smaller scale ecs projects from scratch

steel vigil
#

I know that, I was just wondering if I could use it for independent stuff that won't require much adaptation of my current code to work with it

zenith wyvern
#

Assuming you don't have previous experience with ecs/dod that is

steel vigil
#

I guess I won't have a use it for now

#

I'm very interested in it, but seeing how it isn't complete, idk

#

I have just one question tho before I leave

#

can I use it for rendering only? would taking the time to implement it to work with rendering be worth it?

#

nothing else, just changing to rendering using it

zenith wyvern
#

If you're interested you should go through the manual and the dots samples repo to get an idea of how it all works.

steel vigil
#

yeah

zenith wyvern
#

It's not going to do you any favors as far as rendering goes. Like timboc said you're better off just going through the normal process of fixing rendering bottlenecks with gameobjects

steel vigil
#

Alright

#

Thanks!

devout prairie
#

From the little that I've heard HDRP is really only viable targeting quite high end hardware.. have you considered URP or just standard to begin with and switching later

safe lintel
#

theyre all so different I think you would waste a lot of time to use one and then switch later, unless you are using it only in its most simple form of just slapping textures into materials and calling it a day.

steel vigil
#

sadly

#

so I was thinking of just remaking some of the render pipeline

#

is that even possible?

#

ok, it is

#

I just found it online

robust scaffold
# steel vigil but again, I was just asking what ECS is usually used for

In my experience, ECS / DOTS is used more for simulations. Think particle based fluid mechanics or primitive neutron transport in nuclear engineering. Where an overall general trend and pattern emerges from the distribution of data and there are no "relationships" between individual entities.

steel vigil
#

wait, I could use this for water simulations?

#

like, if I wanted to add realistic water to my game?

robust scaffold
steel vigil
#

well, I meant that-

#

like, could I technically implement some more realistic water into a game, rather than the simple ones that work on your cpu

#

that kinda just look like honey

robust scaffold
#

Where in the forces are being applied to each entity based on a spacial partition of entities that are individually independent but come together to form classical fluid dynamics in a tube.

steel vigil
#

aight

robust scaffold
steel vigil
#

||that's a lot of words for a commoner like me||

robust scaffold
#

The problem with DOTS is that video games rely on relational connections between different data points / contextual array values. If a value changes on one array value, then multiple others in different arrays should change as well. And that goes against the array method and vectorized bursted calculations DOTS is optimized for.

robust scaffold
steel vigil
#

nope

robust scaffold
# steel vigil nope

Hrm okay. You want a horror multiplayer game? Dont use DOTS. It wont help.

steel vigil
#

I figured that out

#

I only wanted to like know if it helps having some objects as entities

robust scaffold
#

Nah. Entities only really help over objects if you have thousands to tens of thousands of objects of the same class but different data values.

steel vigil
#

well, that's kinda what I meant

robust scaffold
#

Like water particles. It's the same H2O with the same fundamental forces but different positional and rotational values.

steel vigil
#

like, let's say I need 1000 items on the ground with translations, rotations and a script to hold a scriptable object

robust scaffold
#

Entities are great when you have one function / method that needs to be applied to all objects universally, taking in the object's data as parameters but otherwise operating on them all universally.

steel vigil
#

ah

#

I see-

robust scaffold
#

If each object on the ground must interact differently based on a scriptable object, using DOTS wouldnt help.

#

Just using a standard Object Oriented system would do the exact same thing without the overhead of DOTS

steel vigil
#

ok

#

I see!

#

what if I need to have something like glowsticks, they all just have to get rendered and sit in a place

#

no script, just translations, rotations and rendering

#

and bounding boxes

robust scaffold
#

Rendering is far different. DOTS is more memory data-side with contextual information. What you want is a compute shader.

steel vigil
#

I guess

#

yeah

robust scaffold
#

Compute shaders are like DOTS in a way. Where pixel and vertex information replace entities. With similar downsides of high performance cost of relational data.

steel vigil
#

yeah

#

I don't need them yet

#

I'm not working on world generation at the moment

#

I'm still interested in working with Dod in the future

#

but for now, I think I should just stick to OOP

#

and make my own render pipeline

robust scaffold
#

Honestly DOTS is in a very tight squeeze between standard Object Oriented and pure Compute Shader powered GPU simulation.

#

There is a very small margin where DOTS will actually assist in improving performance over figuring out a way to shove everything through a compute shader

steel vigil
#

then what's the benefit of making a whole game with dots?

#

I know it's not recommended unless it's a certain type of game

#

but you can do that, from what you described, I see no reason to use it for games

robust scaffold
#

Terrain generation, compute shader, graphics processing, compute shader, fluid simulation, compute shader (or regular graphical shader).

#

I can see it being used for networking where rapid turnaround is required. Shifting information to and from the GPU is very expensive (relatively) and doing simple mass array operations within the CPU and memory cuts down on that.

steel vigil
#

I am using networking but uhh

#

good luck with trying to convert mirror to it lol

#

or make your own

#

so

#

for now, my biggest problem is just, hdrp having way too many draw calls

robust scaffold
#

Honestly I cant help you there. My graphics consist of a blank quad with text on it for debugging. I'm staring more at the entity debugger with float information to verify that my mathematics is working.

steel vigil
#

I don't know how it would help asking there-

robust scaffold
steel vigil
#

oh yeah!

#

lol!

steel vigil
robust scaffold
#

Shaders and render pipelines interact a lot with the overall graphics processing.

steel vigil
#

and maybe spending a couple weeks making some changes

#

to like, how bloom is calculated for example

robust scaffold
steel vigil
#

uhh-

#

yeah-

#

idk how to do that tho

#

it still says the same amount of draw calls for them

#

idk really

robust scaffold
#

Turn off unity built in bloom then apply a shader onto the material that generates bloom yourself.

steel vigil
#

oh yeah! that could work!

#

it's just that some stuff has a lot of draw calls

#

I said bloom specifically because it has 18

#

-.-

#

but yeah

#

I'll look into what I can do to optimize this!

#

thank you for the explanations!

#

๐Ÿ‘

robust scaffold
#

If you want to reduce draw calls.... you might need to start looking into manually merging mesh generation and shoving it into the render pipeline itself.

#

It took me 2 weeks to figure out how to render a 2d triangle that rotates.

#

โœ”๏ธ Works in 2020.1 โž• 2020.2 โž• 2020.3
๐Ÿฉน Fixes:
โ–บ Make sure your source mesh has read/write enabled in it's asset importer inspector.

Compute Shaders are scripts that run on the GPU! They're very powerful, allowing you to leverage the GPU's unique abilities and generate meshes to draw procedurally. There's not a lot of information on using them, ...

โ–ถ Play video
steel vigil
#

idk

#

I'll look into this

robust scaffold
#

It's a deep deep rabbit hole of linear algebra and matrix operations.

steel vigil
#

I really need to squeeze as much performance as possible-

#

hopefully-

#

I can get medium settings on 2K with like

#

155 fps

#

somehow

#

idk how

robust scaffold
#

There are entire PhD degrees built around this. So I wish you a lot of luck.

steel vigil
#

and on high like 120 or something idk

robust scaffold
#

It's good to have high ambitions. So when you miss the goal, you'd have learned a lot in the attempt to try again or formalize a more solid destination.

steel vigil
#

but your confidence also takes a hit

#

;~;

robust scaffold
#

We're all solo developers with projects that will 99% never see the light of day to the public. I've long since abandoned my confidence.

steel vigil
#

SAME

#

but now I'm working with a team

#

and we're planning to release features as we go

#

like, chapters after release

#

new features and graphics

#

more optimizations

#

so like

#

it's released

#

but we're still heavily updating it

robust scaffold
#

Ah. Well performance is usually the problem of your C# game logic code. 90% of the time at least. The 10% is graphics. I highly recommend that you and your team first dig through and refactor your logic code first. What is required to happen every frame, can it be delayed to once every other frame or more.

steel vigil
#

for me it's just

#

rendering atm

#

like, I'm at a point where I can write optimized code so that I don't have to worry about it later

#

yes, exactly

#

I've made sure to cut as many continuous updates as possible

#

the codes I have control over are not a problem

#

the only ones that are more unstable are ones like SteamManager which just initializes Steam

robust scaffold
#

Yea, this is pretty much the limit of my experience with draw call management and render pipelines. Again, ask in #archived-shaders and #archived-hdrp . The ones who frequent that will know far more.

steel vigil
#

yes

#

thanks for the help!!!

devout prairie
#

Hey.. i have the following code, creating a local MultiHashmap, passing it into a job and writing to it, then trying to pass it into a second job.. However it's throwing an error on the second job saying the hashmap has been deallocated..

NativeMultiHashMap<Entity, int> myMultiHashMap = new NativeMultiHashMap<Entity, int>(count, Allocator.TempJob);

var handle = Entities.ForEach((in MyComponent myComp) =>
{
    // add some stuff to multihashmap
}).Schedule(Dependency);

Entities.WithReadOnly(myMultiHashMap).WithDisposeOnCompletion(myMultiHashMap).ForEach((Entity e) =>
{
    // do some stuff
}).Schedule(handle);
#

How would i pass the results of the first job ( ie the hashmap ) onto the second job?

coarse turtle
#

I dont remember if WIthDisposeOnCompletion works with NativeMultiHashMaps

coarse turtle
#

Instead of DisposeOnCompletion(myMultiHashMap) you can also try Dependency = myMultiHashMap.Dispose(Dependency)

pliant pike
#

you would probably have to add Dependency.Complete if you did that though

coarse turtle
#

Well there's Dispose() and Dispose(JobHandle), iirc the one with JobHandle is a scheduled Dispose

pliant pike
#

oh really, cool

coarse turtle
#

Yea it just schedules a new job

pliant pike
#

interesting I heard another method is to just place all that stuff after your jobs in a Job.WithCode also

robust scaffold
devout prairie
robust scaffold
devout prairie
#

How then would i dispose the hashmap after job completion?

robust scaffold
#

I dont quite recall the syntax for getting the first value of a key from a NMHM so it's something along those lines.

devout prairie
#

yep i have the keyvalue logic ok

#

thanks gentlemen ( and women/others ) the help is much appreciated

#

Dispose(handle) is a nice touch

#

so you're passing a job dependency into the Dispose call so that it disposes exactly when you need it to

#

nice

#

Excellent that seems to work perfectly, thanks again

#

10/10 for logical solutions that make sense

devout prairie
#

Is there a way to check if a buffer exists on an object, similar to HasComponent

#

Currently getting an error with var childs = _entityManager.GetBuffer<Child>(rootEntity);

devout prairie
#

HasComponent<Child>(rootEntity) just seems to always return false

zenith wyvern
#

You have to use BufferFromEntity.Exists

devout prairie
#

Hmm i'm not doing it in a system it's just some setup code inside a mono

#

well i guess this works -
var childBufs = World.DefaultGameObjectInjectionWorld.GetExistingSystem<GameObjectConversionSystem>().GetBufferFromEntity<Child>();

#

tiny bit overkill ๐Ÿ˜ฎ

robust scaffold
#

EntityManager is static so it can be passed around

devout prairie
#

Yeah i'm using EntityManager but entityManager.HasComponent<Child>(myEntity) seems to always return false

#

EntityManager doesn't have GetBufferFromEntity

karmic basin
devout prairie
#

em.HasComponent<Child>(myEntity) is returning false, even where i 100% know the entity has the Child buffer

karmic basin
#

Why ? ๐Ÿ˜›

#

there's an IsCreated prop, would em.GetBuffer<T>(Entity).IsCreated suit your needs ?

devout prairie
#

basically i'm doing some setup stuff inside a mono, really i'm just testing out some ideas..

#

so i'm iterating a bunch of entities that are children of a converted prefab

#

some of them have the Child buffer, but the 'leaf' entities dont ( as they have no children )

#

so i'm iterating the Child buffers recursively, if there's a child buffer, i then iterate the children, and then the childrens children

#

i think this would not be a problem if i was doing it in a SystemBase

#

but i'm getting these weird issues trying to do it from the mono

#

currently i'm moving my code over to a SystemBase

#

i'll just apply a Setup tag to my converted prefabs and do the work in a system

#

avoid all this crap

karmic basin
#

yep don't fight it ^^

digital kestrel
#

Anyone ever make a system manually using world.GetOrCreateSystem() and it just disappears lol

#

the OnCreate function runs but i can't find it in the dots system window and the Update function doesnt run even if i use the [AlwaysUpdateSystem] attribute

zenith wyvern
vagrant lotus
#

i was setting up my new project, now im stuck with unity.collections 1.0prerelease

  1. how can i go back to 0.15 for unity.entities while unity.transport requires it?
  2. unity package manager does not show older version of unity.transport and unity.collections
karmic basin
#

Because you know which version you want to target , did you try to add them to your manifest.json file ?

vagrant lotus
#

but package manager and the error logs show otherwise

#

i had this issue a few months earlier

#

the only solution that works is to start a new project

karmic basin
#

I had a somehow similar issue when starting a new project since a long time where I didn't know some of the dots packages were now included as dependency and didn't require you to add them manually anymore. So I ended up with compatibility errors and yeah I had to uninstall every dots package before conflicts could resolve

devout prairie
#

it's tricky but it's definitely possible to fix dependency issues

#

by editing manifest etc

somber swan
#

HI Does Adreno 618 fully support Hybrid Renderer V2? Cause i get black screen with this gpu UnityChanHelp

devout prairie
#

@safe lintel I got the ragdolls working although i've spent a stupid amount of time trying to get around the flat hierarchy thing

stone osprey
#

Is there an interface which gets called once an struct component gets removed ? Something like IDisposable ?

devout prairie
#

also need to look into the bounding thing

stone osprey
#

Is there an interface which gets called once an struct component gets removed ? Something like IDisposable ?
My problem is that i wrote a system which removes a bunch of tag components after exactly one frame... it works kinda generic and some of those tag components contain unsafe/native lists which i need to deallocate when being removed.

So is there some sort of interface which gets called once a component gets removed to deallocate stuff ? Or any other techniques ? I saw for jobs there is an attribute which takes care of deallocation

#

Anyone ? ^^

forest quest
stone osprey
forest quest
#

Alternatively, you can create components that exist on a different entity for watching specific structural changes

zenith wyvern
stone osprey
# forest quest Technically, if a component has any data in it at all, itโ€™s no longer a tag.

Than its not a tag...
I have an Inventory and i need to symbolize that the inventory was updated... like something was added, removed or updated to/from/in it.

So i planned Entity{ Inventory, AddedToInventory{ List<Entity> updated ...} } to react on those updated properly. But well the dealocation isnt that nice because i wrote a "OneFrameSystem" which removes certain components at the end of the frame... great for real tags without any data inside... bad for when allocation happenend

forest quest
#

Just need to be careful about when that last version number gets set

#

Ideally itโ€™s the system that is watching for changes that is also setting the last version number.

stone osprey
#

Does anyone have a working reactive system based on those damn StateComponents ? I just want a kinda generic system which basically does this :

Entity{ TComponent } -> Entity{ TComponent, State, TAdded } -> Entity{ TComponent, State } -> ( After removal of TComponent ) Entity{ State } -> Entity{ State, TRemoved } -> Entity{}

#

So i can easily loop over TComponent, TAdded to processes added components... or TRemoved to process removed components

#

My own implementation sucks and wont work correctly... and i dont get why

stone osprey
#

If someone is interessted in my reactive system... it works now but when i remove the desired component... i kinda want to save the state into my state struct. Any example how this might work ? I could loop every frame over them to copy the state... but isnt this overkill ?

stone osprey
#

Wait... i can not use generics to iterate ?
Entities.ForEach cannot be used in system ReactiveSystem3 as Entities.ForEach in generic system types are not supported.

Is there any way to bypass this ?

left oak
#
#

And, in general, generics are not easily supported at this time

stone osprey
#
            // Copy over state 
            Entities.ForEach((ref Entity entity, ref T tc, ref State state) => {
                
                //var tc = EntityManager.GetComponentData<TComponent>(entity);
                state.component = tc;
            }).Schedule();

Is there a way to loop over entities with "T" and state without using generics ? Unity prevents me to use generics here...

left oak
#

primarily because generics are necessarily not "data-oriented" as the data is unknown

stone osprey
#

Hmmm... any other efficient way to loop over a set of components ? ๐Ÿ˜

#

That T above is my generic

left oak
#

yeah, by identifying which components you want to loop over, and doing it

#

the problem is wanting to solve for all possible combinations simultaneously

stone osprey
#

Well i know which component... T but its generic ๐Ÿ˜„

left oak
#

There's no reason for it to be generic, as I assume you'll be doing different work depending on which component you're actually working on

stone osprey
#

Yes theres a reason... to save me boilerplate code

#

And no... its not doing different work

#

It just should copy over a damn value for the state ^^

#

This is perfectly fine in my architecture... trust me

left oak
#

Is state just some kind of memento? I.e., a compressed histogram

stone osprey
#

Its a generic reactive system which works... atleast till the point of the state. Thats what i need the generic for... to copy the state. And it would work, if unitys check wouldnt prevent me from running it.

#

Currently it does not copy the state into the IStateComponent which is kinda bad... because i need to deallocate some stuff

#

In case someone is interessed

#

And it works perfectly... to the point where i need to copy over the TComponent into the state for cleaning it up later

#

So any idea how i may iterate over all entities with (TComponent, State) to copy the damn state ? ๐Ÿ˜ฎ

left oak
#

I feel like maybe you don't really get the intended purpose of ISystemStateComponentData... I'd recommend reading the article I linked above at least

#

Trying to get generics to work with ecs is somewhere between swimming upstream and bashing your head against the wall, and I don't advise pursuing that

stone osprey
#

Well i just wanna have some sort of callback once a component was added and removed. Thats all i want. Which is not possible in unitys ecs by default. Thats why im using those ISystemStateComponents to simulate this which works... it really does and its pretty performant.

I actually think i just create a Query ( which is possible with generics as far as i know because i only need the type ) and loop over a NativeList<Entity> to copy the state.

vital sandal
#

I have a flattened NativeArray<Matrix4x4> that contains data for each LOD levels for each entities [not using ECS]. I also need to pass a range from this array to DrawMeshInstancedIndirect but whatever I try to extract a range from this, either using Copy, NativeSlice, etc. I end up with a lot of garbage collection and huge GC spikes very few seconds. Does anyone have a suggestion on how I could avoid that?

coarse turtle
vital sandal
#

@coarse turtle it doesn't use memcpy? Do you know of any example. I don't know how to do this.

coarse turtle
#
T[] someArray; // T must be blittable
var gcHandle = GCHandle.Alloc(someArray, GCHandleType.Pinned);

void* ptr = gcHandle.AddrOfPinnedObject();

NativeArray<T> nativeArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(ptr, length, Allocator.None); // This is b/c you are handling this resource through GCHandle

gcHandle.Free() // Unpin the array when you're done with it
vital sandal
#

@coarse turtle NICE! Thank you for that code

coarse turtle
#

Otherwise a custom struct with a T* ptr , length would be enough as you can override the bracket operator. You might also need [NativeDisableUnsafePtrRestriction] if you go down this route

#

now you've got a basic struct wrapper that can be treated as an array

vital sandal
#

@coarse turtle that's a pay grade above me, I only half understand what you just said ๐Ÿ˜ฆ I'm going to have to google it

#

thank you!

devout prairie
#

is it possible to get a buffer from an EntityQuery?

#

like it is with components for example myQuery.ToComponentDataArray<ComponentType>();

pliant pike
hybrid portal
#

Do I need to create a new Unity.Physics.Collider for every PhysicsCollider component?

devout prairie
pliant pike
#

depending on how you are using the data it can be more performant to just put it all into a nativearray and use that, instead of using getbuffer

devout prairie
#

don't suppose it matters much i guess i figured it might be slightly quicker inside the job to go var aLTW = AnimatedLTWs[myEntity] and select from an array that's been reduced by the query, rather than ALL altw buffers

#

yeah i'm guessing there's pro's and cons to both

devout prairie
pliant pike
devout prairie
#

ah interesting, thanks

stone osprey
#

Can there be made any improvements to this here in terms of performance ?


            // Once at system creation
            copyEntities = GetEntityQuery(new EntityQueryDesc {
                All = new[] {ComponentType.ReadOnly<TComponent>(), ComponentType.ReadOnly<State>()}
            });

            // In System update
            var entities = copyEntities.ToEntityArray(Allocator.TempJob);
            for (var index = 0; index < entities.Length; index++) {

                var entity = entities[index];
                var cmp = EntityManager.GetComponentData<TComponent>(entity);
                endCommandBuffer.SetComponent(entity, new State{component = cmp});
            }
            entities.Dispose();

It takes about 1.30ms for about 1000 entities... which isnt that great. I cant use a Entity.ForEach loop here because generic code is involved.
Is there any other direct acess to the component arrays which does not require a "Query.ToEntityArray" ? Or any other ideas ?

tight blade
#

So Entities.ForEach is out, but you could use IJobChunk or IJobParallelFor, which would both be much faster. are those available to you?

#

@stone osprey

#

I haven't worked much with generic code, but I don't think there's anything stopping you from using those structures, since they're not macro magic like Entities.ForEach is

#

And also, a question of my own to anyone here:

Are there any good efficient noise function implementations in the DOTS packages I could grab?

#

oh. duh. theres a whole "math.noise" module

#

okay, I guess my question is answered.

stone osprey
tight blade
#

There should be some good examples in the samples, but if you're having trouble I can help out. I end up using that kind of thing pretty extensively in what I'm working on

#

I'd try that first

pliant pike
#

I don't understand why would IJobChunks work and not Entities.ForEach ๐Ÿ˜•

stone osprey
pliant pike
#

oh I see

tight blade
#

I'd definitely be interested to see a sample if you do get it working with generics.

#

I've been doing a bunch of copying and pasting lol

stone osprey
tight blade
#

doing heaven's work

tight blade
#

Yo. my dudes. Keep this in your back pocket:
sin(2x)+sin(PI * x)

its a proven infinite 1d noise function!

#

thats pretty much blowing my mind haha

stone osprey
tight blade
#

outstanding!

#

got a snippet?

#

(also well done, that was a quick refactor!)

devout prairie
#

oof
error DCICE007: Could not find field for local captured variable for argument of WithReadOnly. Seeing this error indicates a bug in the dots compiler. We'd appreciate a bug report (About->Report a Bug...). Thnx! :heart:

stone osprey
#

For all those interessted in an working reactive system... here you go.

Its actually pretty easy to use. Imagine you have a Inventory component and you want to do something once it was added or removed.

You simply extend that attached system like this :

[assembly: RegisterGenericComponentType(typeof(ReactiveSystem<Inventory, InventoryAdded, InventoryRemoved>.State))]

namespace Script.Client.ECS.Systems.Reactive {
    
    [BurstCompile]
    public struct InventoryAdded : IComponentData { }

    [BurstCompile]
    public struct InventoryRemoved: IComponentData { }

    /// <summary>
    ///     A reactive system informing via callbacks if a <see cref="Dirty" /> was added or removed at a <see cref="Entity" />
    /// </summary>
    public class InventoryReactiveSystem : ReactiveSystem<Inventory, InventoryAdded, InventoryRemoved> {}
}

And then you are ready to run Entities.ForEach once the Inventory was added or removed to trigger logic like a REAL reactive system.


Entities.ForEach((ref Inventory inv, ref InventoryAdded iva) => {
   // Runs once, some cool logic to trigger something
}).Schedule();

Entities.ForEach((ref Entity en, ref InventoryRemoved iva) => {
   // Runs once, great for triggering logic or cleaning up stuff.
   var state = GetComponent<InventoryReactiveSystem.State>(en);
   state.component.items.Dispose();
}).Schedule();

Well it still requires a bit of boilerplate code but much better than writing one IStateComponent-System for each damn Component you wanna listen too.

stone osprey
tight blade
#

thanks! and congrats!

stone osprey
devout prairie
#

Seems good should post it on the forum..

stone osprey
#

Actually listening for added/removed components SHOULD be one of the easiest tasks in an ecs...

Like a "EntityManager.AddListener<T>()"...

stone osprey
devout prairie
#

to listen for components that have been added, you can use Any inside an EntityQuery right.. so you could say have one system that looks for all your 'event' tags for example, and maybe has some logic that uses HasComponent to branch to different callbacks or methods.. but i guess listening for them being removed is potentially difficult right

amber flicker
stone osprey
stone osprey
amber flicker
stone osprey
#

Yeah :/ i alsp have those problem without using dots... I can remember a university project which worked fine on desktop and in the editor and was completly messed up on all other platforms.... We actually used generics quite heavy in this one.

And i havent build my code for ages... That will be fun i guess

devout prairie
devout prairie
#

Is it possible to parallel write to a NativeHashMap.ToParallelWriter() and then pass it onto another job were it is read only?

#

I'm trying to do something like this - the jobs are chained together by dependency, the first one fills the hashmap and the second reads from it.. The problem is there's no indexing or GetKey etc on a .parallelwriter but i'm unsure if there's some other way to maybe cast the hashmap back to a readable one or something.

NativeHashMap<Entity, float4x4>.parallelwriter RootMatrixMap = new NativeHashMap<Entity, float4x4>(count, Allocator.TempJob).AsParallelWriter();
var handle0 = Entities.WithAll<SourceTag>().ForEach((Entity e, in LocalToWorld ltw) =>
{
    RootMatrixMap.TryAdd(e, ltw.Value);
}).ScheduleParallel(Dependency);

var handle1 = Entities.WithReadOnly(RootMatrixMap ).ForEach((Entity e, ref Translation t) =>
{
    // read from RootMatrixMap //
}).ScheduleParallel(handle0);
tight blade
#

are there any decent debug drawing tools for DOTS?

safe lintel
#

Aline on the asset store @tight blade

#

I bought it, same guy that does astar pathfinding project, quite handy

tight blade
#

ooh, nice, I'll check that out. That must be hell, writing something for the asset store based on alpha packages

safe lintel
#

afaik its just job and burst compatible, so no specific ecs hell to support though i dont envy being a store publisher

tight blade
#

any other good dots ecosystem purchases I should consider while I'm shopping?

#

erm, @safe lintel you don't know offhand how to use that builder from Entities.ForEach, do you?

#

doing it with a job would be straightforward, and of course I always regret using the Entities.ForEach macro

zenith wyvern
hybrid portal
#

Can I make a IConvertGameObjectToEntity convert before my system's OnCreate or OnStartRunning?

vagrant lotus
karmic basin
vagrant lotus
#

ye

#

funny

#

classic unity

shell berry
low oyster
#

Hello, I have a project running Unity NetCode and I wish to extend it using Unity SubScenes. Is there somewhere an example of a proper project structure?

devout prairie
low oyster
#

@devout prairie Thank you will check it out

devout prairie
karmic basin
#

But trying to answer because no one did yet :p

#

Anyway If I remember well, IConvertGameObjectToEntity is deprecated so should be replaced by a subscene workflow at some point in the future.

stone osprey
#

Whats the difference between IJobChunk und IJobForEach ?

Which one is more performant or does it depend ?

shell berry
#

They're the same but IJobForEach is the new API as it has Schedule() and ScheduleParallel()

#

IJobChunk will be deprecated

stone osprey
gusty coyote
#

Hi, I have a team and we were wondering about making the transition from classic to dots, however, most of Unity's documentation seems from 2019 ๐Ÿค”

Is this still the future of Unity?

frosty siren
#

all we know now is that dots team are keeping silence

gusty coyote
#

Thx! I'll take a look

coarse turtle
shell berry
#

My bad, I meant IJobEntityBatch

coarse turtle
#

Ah yea - no worries

twin raven
#

I updated Entities from 0.16 to 0.17 with packages: Jobs, Entities, Collections and Burst to latest. Now I got compile error

Library\PackageCache\com.unity.entities@0.17.0-preview.42\Unity.Entities\Serialization\BinarySerialization.cs(47,81): error CS8377: The type 'T' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'NativeList<T>'

Should I not update packages to latest but rather use certain compatible versions?

karmic basin
#

Yeah some of the packages are merged now. I would uninstall every DOTS related package. Start with the HybridRenderer one if you're using this pipeline, else the Entities one. Then, still from package manager, I would check dependencies in the inspector and manually install only the missing ones

#

That's how I fixed my cmpatibility issues anyway

twin raven
#

Thanks a lot, I will try it.

#

I removed Collections and Jobs and now it works. Thanks again UnityChanwow

safe lintel
#

@gusty coyote yeah I think you're better off not considering it ๐Ÿ˜ฉ

stone osprey
#

GetComponentData<T> does it return a copy ? I think so... right ?
Is there any way to get a reference to the passed generic instead ?

shell berry
devout prairie
#

What would be the best approach to using a GetComponentDataFromEntity inside a parallel ForEach for reading and writing?

#

or rather, not using a GetComponentDataFromEntity as it doesn't support parallel writing

#

it's useful as you can access it by Entity, whereas just a nativearray of components would have to be accessed by index right

#

i have a feeling i'm going to have to start writing Jobs as opposed to ForEach, i just can't be bothered with all the boilerplate

coarse turtle
devout prairie
#

basically i need to fetch the LocalToWorld component from separate entities that are not included in the ForEach

scenic oak
devout prairie
#

man i strongly dislike command buffers ๐Ÿ˜

#

i guess they are useful but, one issue i have with this is -

#

i'm chaining more than one ForEach job together through dependency

scenic oak
#

I feel ya. But for parallelism I think that's the best practice

devout prairie
#

so really the second job relies on the first ones results etc

#

yeahp

#

there's workarounds for this, mostly involving 'writing more code', but i was just hoping there'd be a simpler way to get something like a GetComponentDataFromEntity and be able to use it in a parallel context

scenic oak
#

You can be more granular by manually storing stuff in an array and doing the updates in a second loop. But I don't think that is great either

devout prairie
#

essentially i think the answer is rewrite my system as full jobs, with all the boilerplate etc

scenic oak
#

Heavily relational/ordered stuff is where ecs paradigm struggles it seems

devout prairie
#

yeah i can see with ForEach there's some sacrifices to get the convenience and ease of use

#

coming at ECS / DOTS and being able to use ForEach is a hell of a lot simpler than the old job component system stuff

#

it's kinda like what c# is to c++

#

but i can understand why people dislike ForEach and prefer to write everything out manually

coarse turtle
#

well i think once unity moves over to .net 6

#

and source generators are fully integrated, lambdas would be bearable

devout prairie
#

fwiw i dislike lambdas in general c# as it seems a bit of a performance killer

#

long way for a shortcut

coarse turtle
#

well lambdas here are just codegen in their struct counterparts, but otherwise I don't have too much of a dislike of lambdas coming from a functional background ยฏ_(ใƒ„)_/ยฏ

devout prairie
#

ooft functional