#archived-dots

1 messages Β· Page 144 of 1

coarse turtle
#

I think it's Unity's integration since I'm mainly using omnisharp + vim

#

not really a fullblown ide

ocean tundra
#

I use Rider and its AWESOME πŸ˜›

#

but costs 😦

opaque escarp
#

yes

#

does rider have the same issue?

#

with this use case specifically

ocean tundra
#

I've never seen anything like this

#

the only issue i did have was Performance, as that ForEach has like 10k generated overloads πŸ˜› but they fixed that pretty quickly

coarse turtle
#

Hey guys.. Ideas on how to do RTS style drag select?
My options I've thought of

  1. All selectable entities are to have a "screen position" which is Camera.WorldToScreenPoint
  2. Calculate the camera frustum and figure out a Unity.Physics query somehow
    @ocean tundra You can try projecting from screen point to world point and check which positions are in the area that's been selected when doing that click drag
ocean tundra
#

@coarse turtle Screen to world.. Like raycasting?

#

As thats what im doing for normal select, but I want drag select now

coarse turtle
#

You can do something like that, or just transform the screen point to world point with some matrix math πŸ€”

ocean tundra
#

πŸ€”

#

that looks way confusing πŸ˜›

#

but im still unsure how getting a mouse world point helps, i still need to raycast or something

#

Im thinking i could get the 4 corners of the camera and raycast to the ground, then create a overlapAabb

coarse turtle
#

ah that might be an interesting idea

#

but yea that idea was just from the top of my head

#

I might be oversimplifying it πŸ€”

golden elk
#

A. Convert the "Drag" box from screen to world (which then makes a cube volume from nearclip to farclip), use this to either iterate units and check if they are in said volume or use Physics.CastBox to let physics engine to do it, or B. iterate units, convert position to screen space, and check if position lies within selection box. B is simple and straight forward. not great performance but that may not matter.

ocean tundra
#

Can a AABB be rotated?

golden elk
#

nope they are axis aligned

#

you can do some math to rotate them yourself if you want

#

but then they are not axis aligned anymore

#

I generally use AABB for early checks, and if the AABB overlaps I then do a more intensive/accurate check

ocean tundra
#

only issue with A is its a Perspective camera

#

so wont really be a box

golden elk
#

true

ocean tundra
#

I like the idea of starting with a AABB

#

and then doing B i guess

#

i could create a custom mesh collider and then cast that

#

but that seems expensive

golden elk
#

it's basically frustum culling in a way, just with a smaller frustum than the actual camera frustum

ocean tundra
#

yea exactly

#

or even do it myself

golden elk
#

yeah could try that

ocean tundra
#

how would i know if something is inside them or not?

ocean tundra
#

πŸ€¦β€β™‚οΈ

golden elk
#

I have no idea how performant any of this is

ocean tundra
#

yea im not sure if that stuff is Burstable πŸ˜›

golden elk
#

probably decent I imagine

#

yeah probably not

#

could do the math yourself

#

but again, just iterating the units, projecting to screenspace, and doing a simple rect check may be all you need for now

#

unless you plan to have 10000 units or something I guess

ocean tundra
#

πŸ˜›

#

i do plan

golden elk
#

(iterate visible ones anyway)

#

then good luck πŸ˜›

ocean tundra
#

haha thanks

#

i think AABB to find units within the Rough drag area, followed by constructing a Frustum of the mouse box and doing a burst compatible version of TestPlanes

#

i could also optmize more by filtering out already selected units

golden elk
#

what if the new selection box no longer contains them

ocean tundra
#

:/

#

didnt think of that

stiff skiff
#

You could probably re-use the components rendering uses for culling to filter for visible units, and then use the plane tests

coarse turtle
stiff skiff
#

Some of those code examples, don't actually work

golden elk
#

I love utility AI. I've been thinking about using neural nets to tune them instead of doing it manually though. I wonder how well that'd work in practice.

#

cause manually tuning them sucks

stiff skiff
#

There is a very good paper/article on GOAP used in F.E.A.R.

golden elk
#

I wish aigamedev hadn't died off

#

wonder if there are any new Game AI Pro book releases out

#

nope

#

and yeah that FEAR paper was good

#

There has to be a backup of aigamedev somewhere, that was a lot of really valuable info to just disappear

coarse turtle
#

Some of those code examples, don't actually work
@stiff skiff o good to know

stiff skiff
#

Also the example given, is NOT goap

ocean tundra
#

Oooo yess some AI stuff, I've done a really dumb Job based AI

#

but was pretty poor

ocean tundra
#

Whats the best way to do/have performance tests in the build
I'm thinking using custom command line args which can effect my main game scene in some way (spawn in some stuff)
But how should i go about capturing/exporting things like FPS? I have Graphy in which can give some nice visuals/stats, should i be attaching a profiler?

coarse turtle
#

I typically just attach a profiler

ocean tundra
#

theres a overhead with a profiler isnt there?

gusty comet
#

the overhead should be small if you attach it to the player

ocean tundra
#

also i want to setup and run my server/clients in these tests to also preformance test my networking

stiff skiff
#

I recommend separating all of these tests out into parts. For example using multiple playmode tests using the new performance test framework package.

sand prawn
#

If I'm in monobehaviour code running in the editor, how do I get the client world (and entitymanager) of the client who is currently presenting?

ocean tundra
#

is that with NetCode?

#

if not you can probably just use World.DefaultInjectionsWorld or something like that

#

theres also World.All

sand prawn
#

@ocean tundra I'm trying to eventually send an RPC with netcode, yes. World.DefaultInjectionsWorld is giving me DefaultWorld0

#

not one of the client worlds I probably want, I think?

#

I could walk the list of worlds, I suppose, but how do I programmatically know which is the right one?

#

In the editor, I might have multiple clientworlds

ocean tundra
#

yea i've seen that feature

#

its really cool

sand prawn
#

It IS quite cool

#

I just don't know how to work with it πŸ™‚

ocean tundra
#

im probably going to implement something like that in my net code

#

there must be a variable somewhere saying which world is active

#

worst case you can loop over every world and find the one that has presentation group active

sand prawn
#

"has presentation group active"?

ocean tundra
#

@sand prawn you can do world.GetExistingSystem<PresentationGroup> or something like that

#

and check to see if it exists and if so if it is Enabled

bright sentinel
#

@sand prawn @ocean tundra You kinda have to loop through all the worlds and check if their systems are active. Here's a snippet taken from the docs: https://docs.unity3d.com/Packages/com.unity.netcode@0.1/manual/getting-started.html

    {
        // Destroy singleton to prevent system from running again
        EntityManager.DestroyEntity(GetSingletonEntity<InitGameComponent>());
        foreach (var world in World.AllWorlds)
        {
            var network = world.GetExistingSystem<NetworkStreamReceiveSystem>();
            if (world.GetExistingSystem<ClientSimulationSystemGroup>() != null)
            {
                // Client worlds automatically connect to localhost
                NetworkEndPoint ep = NetworkEndPoint.LoopbackIpv4;
                ep.Port = 7979;
                network.Connect(ep);
            }
            #if UNITY_EDITOR
            else if (world.GetExistingSystem<ServerSimulationSystemGroup>() != null)
            {
                // Server world automatically listens for connections from any host
                NetworkEndPoint ep = NetworkEndPoint.AnyIpv4;
                ep.Port = 7979;
                network.Listen(ep);
            }
            #endif
        }
    }
leaden hatch
#

I'm trying to create a grid map of my entities' positions

I'm trying to use entities.foreach to grab position data from entities and update a multi hash map like this:

JobHandle spawnJobHandle = Entities
            .ForEach((Entity entity, int entityInQueryIndex, in Translation translation) =>
            {
                int hashMapKey = GetPositionHashMapKey(translation.Value);
                sectorsMultiHashMap.Add(hashMapKey, new SectorData
                {
                    entity = entity,
                    position = translation.Value
                });
            })
            .Schedule(inputDeps);

However my sectorsMultiHashMap is a static variable, because I want to access it in other systems. I know I can't use static variables with Entities.ForEach, so I'm not sure what to do. is there a way to update the static variable? Or should I find another way to share the sectorsMultiHashMap with other systems?

storm ravine
#

Store map in local variable outside ForEach. Despite that all native containers is a struct and copied by value, they all under hood use pointers to used memory thus every value copy (just pointer and allocator label) will point to the same memory and changing values of that map, stored in a local variable, will change your map in a static field.

leaden hatch
#

wait so how do I access the local variable from other systems then? do I just set the static variable to the local variable afterwards like this?

NativeMultiHashMap<int, SectorData> localMap = sectorsMultiHashMap;
        JobHandle spawnJobHandle = Entities
            .ForEach((Entity entity, int entityInQueryIndex, in Translation translation) =>
            {
                int hashMapKey = GetPositionHashMapKey(translation.Value);
                localMap.Add(hashMapKey, new SectorData
                {
                    entity = entity,
                    position = translation.Value
                });
            })
            .Schedule(inputDeps);
storm ravine
#

This local variable only for current context

#

in every system you just do the same

#

where you need pass your static NHM in to ForEach

leaden hatch
#

it doesnt seem very efficient if I have to sort all my positions in every system that needs that info

#

maybe i'm going about this the wrong way?

#

but I get an invalid operation when I try to access the hashmap from another system, which says " You must call JobHandle.Complete() on the job QuadrantSystem, before you can read from the Unity.Collections.NativeMultiHashMap"

#

I guess its saying I need to wait for the system to finish its jobs. So I put

[UpdateAfter(typeof(QuadrantSystem))]``` in the accessing system but it didnt fix it :/

The accessing system:
```csharp
 [UpdateAfter(typeof(QuadrantSystem))]
 public class WorldRenderer : ComponentSystem
 {
     protected override void OnUpdate()
     {
         Debug.Log(QuadrantSystem.quadrantMultiHashMap.Count());
storm ravine
#

it doesnt seem very efficient if I have to sort all my positions in every system that needs that info
This error will be expected, you should handle dependencies for your container it's not managed automatically. UpdateAfter only define systems update order, not jobs chain. Dependency chain responsible for jobs waiting

#

You have systems A which populate that map

#

and all other systems which will use that map should be in the same dependency chain

#

it doesnt seem very efficient if I have to sort all my positions in every system that needs that info
@leaden hatch You shouldn't

#

Read again:
This local variable only for current context in every system you just do the same where you need pass your static NHM in to ForEach
you should do the same local variable approach, not ForEach itself. First system populate map, other systems use map.

leaden hatch
#

I added a local variable like this :

var LquadrantMultiHashMap = quadrantMultiHashMap.AsParallelWriter();
        JobHandle hashJobHandle = Entities
            .ForEach((Entity entity, int entityInQueryIndex, in Translation translation) =>
            {
                int hashMapKey = GetPositionHashMapKey(translation.Value);
                LquadrantMultiHashMap.Add(hashMapKey, new SectorData
                {
                    entity = entity,
                    position = translation.Value
                });
            })

Is this what you mean by a local variable?

#

I tihnk I'm misunderstanding what you mean

storm ravine
#

I recommend you start from docs and samples repo and understand basics, understand dependencies and how DOTS manage things, check source code πŸ™‚ It will be better for you than just drop inside blindly.

leaden hatch
#

thats fair

storm ravine
#

And all other things from manual section.

leaden hatch
#

I'll take a look, tyvm

storm ravine
#

What you need to do in your case. Store your static map in local variable in this system (as you already did) pass that local variable in to lambda for processing. Store this system job handle (guess you'll use static field for that if you using static field for map). In every system which should use that map you should combine this job handle with system job handle and use as dependency, return it back etc and use your static NHM. it become a mess very fast with this approach πŸ™‚ Better is use some dummy type with ICD class (and use that class as Singleton entity), which store that map, and give unity manage dependencies by that dummy type.

leaden hatch
#

@storm ravine Ty I'll look into this and read up on ecs/dots

#

@storm ravine I actually got it to work in the end. The error message I posted was actually telling me what to do lol. I needed to use hashJobHandle.Complete();

#

This ran super slowly with ComponentSystem, but with JobComponent system its ridiculously fast, basically not even a hitch. Unity's ecs is pretty neat. Hopefully I can use this to only render what the camera sees and have all the fps in the universe!

protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        EntityQuery entityQuery = GetEntityQuery(typeof(Translation));

        quadrantMultiHashMap.Clear();
        if (entityQuery.CalculateEntityCount() > quadrantMultiHashMap.Capacity)
        {
            quadrantMultiHashMap.Capacity = entityQuery.CalculateEntityCount();
        }

        var LquadrantMultiHashMap = quadrantMultiHashMap.AsParallelWriter();
        
        JobHandle hashJobHandle = Entities
            .ForEach((Entity entity, int entityInQueryIndex, in Translation translation) =>
            {
                int hashMapKey = GetPositionHashMapKey(translation.Value);
                LquadrantMultiHashMap.Add(hashMapKey, new SectorData
                {
                    entity = entity,
                    position = translation.Value
                });
            })
           .WithStoreEntityQueryInField(ref query)
           .Schedule(inputDeps);

        hashJobHandle.Complete();

        return inputDeps;
    }
storm ravine
#

Both deprecated. Use SystemBase instead πŸ™‚

leaden hatch
#

Oh really, haha crap thanks

#

Ok with SystemBase lol. Thanks again @storm ravine

protected override void OnUpdate()
    {
        quadrantMultiHashMap.Clear();
        if (query.CalculateEntityCount() > quadrantMultiHashMap.Capacity)
        {
            quadrantMultiHashMap.Capacity = query.CalculateEntityCount();
        }

        var LquadrantMultiHashMap = quadrantMultiHashMap.AsParallelWriter();

        Entities
            .ForEach((Entity entity, int entityInQueryIndex, in Translation translation) =>
            {
                int hashMapKey = GetPositionHashMapKey(translation.Value);
                LquadrantMultiHashMap.Add(hashMapKey, new SectorData
                {
                    entity = entity,
                    position = translation.Value
                });
            })
           .WithStoreEntityQueryInField(ref query)
           .ScheduleParallel();
        this.CompleteDependency();
    }
thorny halo
#

hello, does anyone know of the fastest way to set all NativeArray elements to 0? Iterating over a for loop seems takes up quite some time.

warped trail
#

MemsetNativeArray<T> ?πŸ€”

thorny halo
#

@warped trail thanks, that just improved performance by 10

graceful mason
#

Im struggling to understand Big data.... my map is saved in pieces... for any XYZ in worldspace, I have a function so I know to get the data I need I must open "Piece A" at array poisition "B"

#

But how to pass this function to a job

#

dont want to pass my whole world data πŸ˜„

#

really the job just needs Read only access to the world

#

(pieces are entitys)

#

example, my playercontroller system must see if I am touching the floor. Rather than looping every entity in world, it only needs to loop 1, in the place I am sttod

#

before I just had a simple function: world.IsBlockSolid(testPOS) but implementing this into a system is bvlowing my mind πŸ˜„

low oasis
#

General NativeCollection question. If I'm writing a function that returns an array of float2 I'm wondering if it's better to use NativeArray or just return a float2[] and deal with it, given that the function may or may not be called by DOTS or Jobs code? Is the NativeArray faster than float2[] or is it just the garbage collection?

dull copper
zenith wyvern
#

General NativeCollection question. If I'm writing a function that returns an array of float2 I'm wondering if it's better to use NativeArray or just return a float2[] and deal with it, given that the function may or may not be called by DOTS or Jobs code? Is the NativeArray faster than float2[] or is it just the garbage collection?
@low oasis

NativeArray is only faster than a managed array if it's used in burst. Otherwise it's slower.

safe lintel
#

i miss browsing bintray πŸ™‚

dull copper
#

that's still against older entities πŸ˜…

#

but it might still be compatible

low oasis
#

@zenith wyvern So, if I'm making a static function it is probably better to return a float2[] and convert it if I'm doing anything with Burst, which I would hope to take advantage of.

zenith wyvern
#

Depends on a lot of things. If you aren't going to be keeping that managed array around that's an unnecessary allocation.

sand prawn
#

@bright sentinel @ocean tundra I rather thought the PresentationGroupSystem was for UI bits? @bright sentinel I know all of these client worlds will be in the "AllWorlds" list because they're all running in editor. Just don't know which one is currently presenting.

safe lintel
#

@dull copper it works with the latest entities(0.10), i have a small project to test it out with. from the notes theyve upgraded to using systembase for at least some of the systems(cant tell if its all) so its ahead of physics in that regard πŸ™‚

sand prawn
#

Ah, got it. It's the ClientPresentationSystemGroup that I care about

ocean tundra
#

Anyone found any change logs for Unity.Animation?

#

@sand prawn Nope Presentation is for all visual things, DOTS has no UI bits yet

safe lintel
#

its in the package

#

wish i understood how to create a dataflow graph in it 😩

ocean tundra
#

whats a dataflow graph??

safe lintel
#

something animation uses to connect up all the clips with rootmotion and mixers

#

im guessing the final thing might be visual or at least include a visual part because theres descriptions in the code for the animation nodes like rootmotion

ocean tundra
#

sounds cool

safe lintel
#

like [NodeDefinition(category:"Animation Core/Root Motion", description:"Extracts root motion values from animation stream so these can be used for different operations (i.e store state values in entity components)")]

ocean tundra
#

do we have to use it for animation? ideally i would like to just Play a animation clip

safe lintel
#

well you need to use it to make a graph to drive any animation in dots, assuming its the equiv of the playables in regular unity but I really barely understand whats going on πŸ™‚

#

cant figure out how to add rootmotion to the play clip example in the samples 🀷

ocean tundra
#

sometimes i feel like unity does the really big stuff and forgets about small stuff, why not give us the ability to just play a clip and then work on the next level up

#

i want to have my animations controllable via data, and things like the animator makes it super duper hard to swap animations at runtime

safe lintel
#

well theres an example to do that in the samples

#

all the easy side of things will come later, i do wish later was sooner but thats the price of being an early adopter for this stuff

ocean tundra
#

πŸ˜›

#

yup

#

i love it tho

#

the whole ecs coding pattern is awesome

#

that data flow graph thing, is basicly a state machine??

safe lintel
#

i dunno? maybe more like a behaviour tree?

coarse turtle
#

there's a data flow graph in entities now? πŸ‘€

#

I might've missed the context

ocean tundra
#

@coarse turtle Inside animations, I dont really understand what it is tho, Animator for ecs?

coarse turtle
#

o

safe lintel
ocean tundra
#

oh nice

safe lintel
#

i havent tried it at all though

ocean tundra
#

so what could i use this for?

#

apart from animation πŸ˜›

#

AI tree of some sort?

safe lintel
#

something for tweening too, not sure but @tawdry tree might want to see it(i think you were working on a tween package for dots?)

tawdry tree
#

That wasn't me, can't remember anyone working on a package for that

#

But I do remember discussing it, so someone else might've been working on a package

amber flicker
#

πŸ– I’m working on a dots tween library. Similar functionality to DOTeeen. Though it will work with monobehaviours and much more. Hopefully there’s room for both what I’m making and what Unity comes up with πŸ˜….

#

About a year and a half in... wasn’t as easy as I thought 😬

safe lintel
#

i guess its animation related but maybe something there you could steal πŸ™‚

ocean tundra
#

Any documentation for it? (im guessing no?)

safe lintel
#

all the docs are the examples

ocean tundra
#

yup thought so πŸ˜›

#

will get looking at them

spring rapids
#

Quick question:
Any good way to use non Blittable type variables with the Job system?
I kinda need to find a way to make an OpenCV method that takes ~300ms run in the background so it won't freeze the UI constantly.
The only problem I'm left with is how to get the Cv2.Mat into my job without referencing the static var from inside the job (which works but yeah no)
I tried converting it in a couple of ways but neither worked so far

Currently thinking about just using the regular multithreading system

ocean tundra
#

How do i add unity animation again?

#

do i need to manually add it to my package thing?

safe lintel
#

probably easier to clone the animation samples repo

amber flicker
#

wip - you'll be able to create an animation as an asset, edit it on a Timeline, target gameobjects or entities independent of hierarchy and use it with entities/conversion workflow or else do something like myEntity.TweenTranslation(..).OnComplete() etc

ocean tundra
#

@amber flicker Oooo how did you get timeline working with ECS???

amber flicker
#

The UI? It's all custom sadly - couldn't sufficiently repurpose either the Timeline or Animation window - it's still a work in progress - turns out bezier curves are easy... weighted bezier curves not so much

ocean tundra
#

No i mean the actual Timeline Data

#

I would love to use it to mix animations/sounds/effects for my game

amber flicker
#

it'll be on the asset store eventually .. I hope πŸ˜… - lots of cool features - keyframes can be relative so you can reuse animations across many different projects - they can be nested so you can make and reuse a 'fade' animation everywhere for example. Event system built-in too that uses scriptable objects. It's a bit early to be sharing probably πŸ˜„

ocean tundra
#

yea but how did you get the data compatable with DOTS?
Convert the timeline at runtime into a blob asset of some sort?

amber flicker
#

sure - it's conceptually pretty simple - an asset that stores the keyframe data which is then used to create the entity with the kind of component data you would expect (start time, duration, start value, end value kind of stuff) - entities can be created at runtime or as part of the subscene conversion process

ocean tundra
#

interesting

#

not a blob asset?

amber flicker
#

in my tests entities with e.g. dynamicbuffers of points is faster than using blob assets due to the linear access

ocean tundra
#

sweet

#

thats a good tip πŸ™‚

amber flicker
#

it also makes it much better for inspecting - all the data could be hidden away in native arrays but you really don't lose much perf by just exposing it all

ocean tundra
#

yea they need a better way to inspect data

amber flicker
#

that's coming apparently.. just nobody knows what it looks like or when

ocean tundra
#

everything is comming πŸ˜›

amber flicker
#

Working on the code-gen UI today - you use this to mark what components you want tweenable (both in the Timeline and via code). Still some work to do but at least it shows you how many times each property is used and where.

ocean tundra
#

Oh nice

#

i have code gen working in my project too

amber flicker
#

Yea kinda essential for a lot of ecs

ocean tundra
#

im using those TT templates

amber flicker
#

oh good luck πŸ˜„

ocean tundra
#

and a scriptable object in unity

#

what are you using?

amber flicker
#

hand-rolled inefficient stuff

ocean tundra
#

oh

#

i defiantly recommend the TT templates

amber flicker
#

don't they require visual studio?

ocean tundra
#

Theres a pre process mode that turns the Template into a c# class that you can then call from unity (thats what my Scriotable obejct does) to pass in Unity stuff

#

um i'm using Rider

#

pretty sure theres a VS Code extention for them

amber flicker
#

might investigate for a future project but I'm pretty happy with the current solution tbh - totally in my control and plenty fast enough

#

no external dependencies beyond unity is pretty appealing

#

for an asset

ocean tundra
#

yea i get that

opaque escarp
#

I want to have a NativeHashMap with NativeArray values, but that doesn't work, so I tried creating native arrays and having the hashmap store the pointers instead, then reconstruct the native array and dispose later, but Unity complains about a memory leak, presumably because it can't track the native array after it's been converted into pointer form. How can I tell it to chill?

ocean tundra
#

@opaque escarp Have you seen MultiNativeHashMap

opaque escarp
#

yeah, but I'd like to be able to performantly access it by abritrary index

ocean tundra
#

its basilcy <KEY,NATIVELIST<VALUE>>

opaque escarp
#

seems like you can only access them sequentially in multihash

ocean tundra
#

yea i have noticed that

#

There are also these:

opaque escarp
#

I might check that out. Otherwise I guess I could manually allocate

zinc plinth
#

NativeMultiHashMap is nice but you only have Next, you can't access the NativeLists or whatever holds the multiple values for each key

ocean tundra
#

Actually theres GetValueArray

#

and getValuesForKey

#

Does that help?

#

oh no just noticed its still a Enumerator

#

Anyone looked at building a custom DynamicBuffer?
I'm just interested if its possible

ocean tundra
#

its probably a terrible idea

zinc plinth
#

what would be the usecase of that ?

ocean tundra
#

mainly to have those native collections attached to entities

#

like that 2d array

#

but its all sugar and not needed

#

maybe was overthinking things too

#

πŸ˜›

zinc plinth
#

just use a method to cnvert 2d index to 1d index GWaobloChildPepeShrug

ocean tundra
#

yup

zinc plinth
#

that's just what NativeArray2D is under the hood

ocean tundra
#

was definitely over thinking

zinc plinth
#

tho be careful with dynamic buffers

until they're above their limit, they will put themselves in the chunks; if you have too big buffers you might make so that very few entities can fit in that chunk

ocean tundra
#

yea so some of my bufferes are HUGE!!!

zinc plinth
#

so if you plan on having big dynamic buffers, put the threshold size of like 8 so that it goes to the heap imediatly

ocean tundra
#

like 1000s of items can build up in them pertty quickly

#

yea going to set it at like 4

#

but im still not sure what to do about those big bufferes

#

its mostly unneeded data so for clients i was thinking ill trim them down to the last 10 or so items

#

but for the server i actually want to keep that data (its basically replay data) so was thinking to write out old data to files or something

zinc plinth
#

unless this data creates alot of computation on the client, really don't bother

ocean tundra
#

really??

#

its not like i loop over it all, i generally only need the last 10 - 20 items max, so i loop backwards till i find what i need

#

but thought leaving it there would be bad practice

zinc plinth
#

I'm not proficient with ecs by any stretch, but I rly feel like this would be pretty late optimization to implement

ocean tundra
#

yea true

#

ok different question :P
Fog Of War DATA
Better implemented as?
NativeMultiHashMap, with Key = int2 of position (some math to get it) and Value's being the Entities. this is cleared and rebuilt every frame, could also have a static list which is updated once for things that dont move
OR
Entitis with DynamicBuffers<Entity> and a SharedComponentData(the key/position), much less frequently updated as moving things will remove themselfs and readd as they move around

#

Actually just reading it again makes me think the 2nd option would be better, but maybe combo it with a hashmap to quickly find the entity again (position, fog of war entity)

graceful mason
#

is it possible to make a temporary list in a system?

#

im trying like: NativeList<Vector3Int> rawChunks = new NativeList<Vector3Int>();

#

Or can I only define it as a component, or make a job and define a nativearray externally first

ocean tundra
#

@graceful mason yea you can do that, but you have a few things wrong

#

need to set a Allocator, probably temp into the contstructor

graceful mason
#

ah thats what that allocater is πŸ˜„

#

I see all over the place in docs

ocean tundra
#

and i think you should be using int3 instead of vector3int

#

finally you need to call .Dispose when done with it

graceful mason
#

ok thanks so much

ocean tundra
#

all good

graceful mason
#

lol do you know my material question πŸ˜„

ocean tundra
#

material?

graceful mason
#

1 sec..

#

worldManager = GameObject.Find("WorldManager").GetComponent<WorldManager>(); entityManager.SetSharedComponentData<RenderMesh>(chunkTerrain, new RenderMesh { mesh = mesh, material = worldManager.material });

#

Argh it wont let me paste

#

trying to assign 1 material to 1000s of meshes

#

is that a good way? πŸ˜„

#

it works, just no idea if its instanced or there all new instances

ocean tundra
#

pretty sure you can keep the RenderMesh and just pass it into the SetShared....

graceful mason
ocean tundra
#

that wont work in jobs and stuff

graceful mason
#

Im going to move it into PostUpdateBuffer soon

#

and that

#

or maybe run on main thread as it very fast anyway

ocean tundra
#

yea

#

if it works leave it for now

graceful mason
#

but the material, isnt crerating 1000s of different instances?

ocean tundra
#

thats something that keeps hanging me up, i keep trying to optimize early

#

na pretty sure that dosnt copy material

graceful mason
#

I use 1 material for all game objects, just wanna make sure im only using 1 as got FPS issues LD

ocean tundra
#

you can test it

#

hit play and spawn all your suffts

#

then find your material asset

#

and change something on it that you should be able to see

#

if it copied noting will change

graceful mason
#

ok that seems ok then

#

thanks a bunch once again

ocean tundra
#

all good

timber rivet
#

Does anyone have experience with raycasts in ECS? I have a bunch of detector entities on the ground of my scene and would love to do a ForEach over those, have each detector entity cast a ray straight up, do math with components of any target entities the ray hits, and write the result to a component of the detector entity

#

But I haven't touched DOTS physics yet, so I'm not sure if it can be that easy

ocean tundra
#

its a bit more annoying

#

but not by much

#

Heres the docs

#

they have examples of everything at the bottom

timber rivet
#

Hmm

#

So suppose I have like five of my target entities floating above a given detector entity and they have flat circle-shaped colliders. I suppose I want to take the ray cast code and have that within my foreach or job, but it sounds like that will only return one of those entities, so I would have to monkey around to actually get it to give me all the applicable entities?

graceful mason
#

Argh I worked out my problem , I was trying to declare my NativeArray in a system like on this page: NativeArray<float> result = new NativeArray<float>(1, Allocator.TempJob);

#

but it only works if I dont put in the intial size

ocean tundra
#

@timber rivet Theres a overload that will return everything along the ray

timber rivet
#

ah

#

So the big thing I'm looking at is CollisionWorld.CastRay and I need to look into the overloads on that

ocean tundra
#

yea that sounds right

timber rivet
#

And either way this requires a separate component on the targets I want to hit, right, a collider

ocean tundra
#

yup

#

if your using the authoring flow you can add PhysicsShape to your thing

#

if your not it looks super hard to construct the colliders

sand prawn
#

if your not it looks super hard to construct the colliders
You mean programmatically?

ocean tundra
#

yea

sand prawn
#

I am going to need to figure this out

timber rivet
#

So that's not as easy as just assigning a mesh like one would do with rendering meshes, then

ocean tundra
#

na bit more invloved

sand prawn
#

Is it? It's not just ComponentData?

ocean tundra
#

it is

#

but the collider is magic

#

like crazy magic

sand prawn
#

Got a doc somewhere?

sand prawn
#

Oh, man. That's an amazing sample though

timber rivet
#

I wonder if the system will yell at me for messing getting another set of entities in a foreach/job because I've had to jump through hoops to do that before. But I only plan to read from the raycast targets so in principle it should be thread safe

ocean tundra
#

Actually the collider looks easyier then i thought

#

most of that is for the physics body

sand prawn
#

yeah, gonna say... that doesn't look that magical

ocean tundra
#

maybe it got better πŸ€·β€β™‚οΈ

sand prawn
#

Hm

#

Where does the BlobAssetReference come from?

timber rivet
#

Okay, I should be able to work with this. Thanks a bunch

ocean tundra
#

@timber rivet na it should be fine, if you need components from those entitys use ComponentDataFromEntity

sand prawn
#

oic

#

nm

timber rivet
#

oh yeah

graceful mason
#

is burst on by default for a systembase.. They seem active for me in the burst inspector

#

public class ChunkLoaderRequestListSystem : SystemBase{ protected override void OnUpdate() {

ocean tundra
#

It says in one of the menu items at the top

#

Jobs maybe?

#

Jobs > Burst > Enable Compilation

timber rivet
#

As I understand it, Entities.ForEach uses burst by default

ocean tundra
#

yup it does

wide fiber
#

Guys I am getting a weird error when I am playing (after a while, not at the start).

It says that "The component of type:... has not been added to the entity", but I add the component using an Authoring script and I never remove it (I can check it with the entity debugger)

#

I only use that component in the queries (with ref or in based on the system)

wide fiber
#
{
return math.acos(math.dot(v1, v2) / (math.length(v1) * math.length(v2)));
} ```
I don't remember who gave me this function, but sometimes it returns NaN, why?
storm ravine
#

Because one of length == 0

#

Thus you divide by 0

#

And it produce NaN

wide fiber
#

Ok ty

#

So if it returns NaN it means that the angle is 0?

storm ravine
#

This function (I gave it to you) require vector with length (because it obvious for angle between vectors)

#

So if it returns 0 it means that the angle is 0?
@wide fiber yes, just use same vector for both arguments and it should return 0

#

Because angle between them will be 0

wide fiber
#

@wide fiber yes, just use same vector for both arguments and it should return 0
@storm ravine Sorry, it wasn't the right question, I've edited it

mystic mountain
#

I want to add a component on each material of a mesh in conversion, and hopefully also link these to a buffer on one of the parents. Anyone know in what stage the child entities are created in the conversion, or any shortcut to make this happen?

storm ravine
#

@storm ravine Sorry, it wasn't the right question, I've edited it
@wide fiber No. There is no angle, because one of arguments has zero length.

#

If one of the vectors is zero-length - it's just (0,0,0) point, and which angle you expect between vector and point - 0? 360? 1080? it hasn't any angle.

opaque ledge
#

is it possible to get a position of trigger event ?

mystic mountain
#

Found that you can use GetEntities of a gameobjct to get the entities at least, not sure if best way. But it's one way at least πŸ˜„

tribal cobalt
#

.

amber flicker
#

dots joke @tribal cobalt ? πŸ˜…

tribal cobalt
#

Yeah, sorry lol.

graceful mason
#

if I got unlimited Data to process without any deadline, got any suggestions? I was thinking, loop entities, populating output buffers, until deltaTime hits a threshold.

#

I guess I may have issues with it clogging other actual imporotant jobs but I can hit that later πŸ˜„

#

maybe if deltatime thresh is low enough, im ok

gusty comet
#

I'm having trouble getting the camera to follow the player...
What I did:
-Camera In subscene
-IConvertGameObjectToEntity
-dstManager.AddComponent(entity,typeof(CopyTransformToGameObject)); / CopyTransformFromGameObject
-In a Job(under entities.foreach): cameraTranslation.Value = playerPos; (float3)

#

yet, the camera isnt updating.. I should mention that the camera entity does update as desired, but the "gameobject" inside the subscene doesnt change

#

am I missing a step?

mystic mountain
#

@gusty comet I noticed some weird behaviours with camera depending on how I converted it. So what I experienced is that it seems that the Camera component is converted, but doesn't seem to update correctly in world (or in time?) So what I currently do is spawn it with GameObjectConversionUtility, and use the gameObject camera.

gusty comet
#

Ah nice. I think i'll do that anyway, cause the conversion system seem to hit the performance quite a bit too

undone torrent
#

hi, is there a way to check live conversion in edit mode is ON via code

wide fiber
#

Has anyone ever used particles in Unity DOTS?

odd cipher
#

Has anyone here tested the performance of NativeMultiHashMaps? I know I've talked about this before but I havn't really solved much of my previous issue (if there even is one, which is why I'm asking this)

thorny halo
#

Hello, i'm writing a terrain LOD rendering system and making it composed of structs to make use of the job system. I'm finalizing the logic and looking at ways to optimize the algorithm, which needs quite a lot of optimization as right now it's currently taking 1ms per terrain and i expect ~64 terrains to potentially be active at any one time. The system initializes ~90% of the data used in the tree once and then needs to recalculate the rest every frame.

I'm using a quadtree which is made out of nodes where the nodes store data like neighboring node indexes, depth, aabb, etc. At first i found using an array of nodes inside the tree as a convenient way to keep logic related to the tree inside the tree and logic related to the nodes in the node struct. However, after moving to a NativeArray i noticed that in order to override an index of the array you can't just do stuff like "array[0].depth = 0", instead a whole new struct needs to be given to it. The node struct which I've been using is pretty huge, more than 150 bytes in size. The copying of a 150+ byte node has pretty high cost, which is why I've decided to split the parts of the node struct which need updating per frame into different NativeArrays inside the tree. This improved the performance by a lot as now I'm only updating the necessary data without any overhead from the whole struct by doing "depth[0] = 0".

Having said that, now i feel as if i'm bleeding half the logic which should belong to the node into the tree. Is splitting up a struct in this fashion the way to go or am i perhaps missing something?

wide fiber
#

LocalToWorld.Position is the global position while Translation.Value is the local one?

warped trail
#

if your entity has parent than Translation is in parent space

#

and LocalToWorld is always in world spaceπŸ€”

odd cipher
#

Is there a way to see what is taking the most time in a Job?

wide fiber
#

if your entity has parent than Translation is in parent space
@warped trail ok..
I am making a raycast and I am getting some inaccurate results and I can't understand the problem.. I will send the code if I can't solve it

odd cipher
#

also.. I still have to optimize my noise generation. Since a lot of you say that generating a 200x200 noise map in 0.20ms is slow. Though I don't really know any way to make it faster

zinc plinth
#

are you throwing burst at it ?

#

are you doing seq writes and not random writes

odd cipher
#

Yeah it uses burst, don't know what you mean by seq

solemn ice
#

I got a weird bug where when I load a new scene with entities that get created with ConvertToEntity, previously destroyed entities' number and version gets reused. I check with EntityManager if an entity still exists and it returns true, and the entity it references is completely different from the one I checked originally. Anybody knows how that can happen?

zinc plinth
#

@odd cipher sequencial, aka you're writing to your array inder after index and not out of order

odd cipher
#

I am confused what you mean by "inder" and it is a IJobParallelFor

obsidian halo
#
[BurstCompile]
public struct AssignVoxelJob : IJobParallelFor
{
    public NativeArray<byte> voxelArray;

    public void Execute(int index)
    {
        if (index > (32*32*32)/2)
            voxelArray[index] = 1;
        else
            voxelArray[index] = 2;
    }
}```
opaque escarp
#

I'd wager you're not ever assigning voxelArray

obsidian halo
#

I did assign the array

NativeArray<byte> voxelArray = new NativeArray<byte>(32 * 32 * 32, Allocator.TempJob);

        AssignVoxelJob assignVoxelJob = new AssignVoxelJob
        {
            voxelArray = voxelArray,
        };```
opaque escarp
#

do you get the same error when disabling burst?

obsidian halo
#

The error only appears in Burst inspector, the job itself works fine.

leaden hatch
#

Is there a way to store the equivalent of a NativeMultiHashMap on a component? DynamicBuffer is more like an array it seems

leaden hatch
#

I guess I could store the map keys and values in a dynamicbuffer and then construct it back into a NativeMultiHashMap in the systems its required. But that doesnt sound too performant

opaque escarp
#

I've never seen errors in the burst inspector myself, always relied on the console

#

I think you could get away with storing a pointer to the NativeMultiHashMap maybe

sand prawn
#

What's the hotness for creating primitive meshes (cube/sphere/etc) in DOTS?

leaden hatch
#

ok different question :P
Fog Of War DATA
Better implemented as?
NativeMultiHashMap, with Key = int2 of position (some math to get it) and Value's being the Entities. this is cleared and rebuilt every frame, could also have a static list which is updated once for things that dont move
OR
Entitis with DynamicBuffers<Entity> and a SharedComponentData(the key/position), much less frequently updated as moving things will remove themselfs and readd as they move around
@ocean tundra I'm currently trying to solve the exact same problem πŸ˜‹ . If each SharedComponent with unique data is a separate chunk, if your world has a lot of positions wont it add a ridiculous number of chunks? I dont know if that will have an impact on the rest of the system or not

zinc plinth
#

shared components for this are a really bad idea

#

have a single dynamic buffer where 1 index = 1 grid coordinate and inside the struct you put the state of the fog of war for this tile

#

and convert a 2d index to a 1d index to access the elements of the buffer

leaden hatch
#

@zinc plinth What would you recommend if you want to store the entities in each tile? Should I just use a nativemultihashmap? or is there some way to store this data in a dynamic buffer or something

zinc plinth
#

you don't "store entities"

#

if you want to know the coordinates of an entity that is "placed" on the grid, just add a component to it with it's coordinates and size

#

you can't think of some entity "owning" other entity in ecs

leaden hatch
#

if I want to know the entities close to others doesnt it makes sense to pre sort them into a quadrant/tile system and then just check the current and adjacent tiles?

#

instead of checking every entity with a position component

zinc plinth
#

in a world of reference types that would make sense

but you can't really do that in ecs, not while keeping each entity a strict task

#

but I use a lil workaround for that

I have multiple stuff that need a value for every tile of my grid, so I added buffers to my grid entities containing those values

I still have grid element entities, but for values that are more part of a grid state more than a grid element (even if the value is a result of a grid element being there) I put in in a buffer in the grid

#

but then you have to be careful to update your states properly

#

with this you still can't just "get the neighbor grid elements", but for my cases it solved my problems

#

I mean you can by looping over the grid elements of one grid, but ya

leaden hatch
#

but isnt that what theyre doing in the boids example unity provides?
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Assets/Advanced/Boids/Scripts/BoidSystem.cs

                // Populates a hash map, where each bucket contains the indices of all Boids whose positions quantize
                // to the same value for a given cell radius so that the information can be randomly accessed by
                // the `MergeCells` and `Steer` jobs.
                // This is useful in terms of the algorithm because it limits the number of comparisons that will
                // actually occur between the different boids. Instead of for each boid, searching through all
                // boids for those within a certain radius, this limits those by the hash-to-bucket simplification.
                var parallelHashMap = hashMap.AsParallelWriter();
                var hashPositionsJobHandle = Entities
                    .WithName("HashPositionsJob")
                    .WithAll<Boid>()
                    .ForEach((int entityInQueryIndex, in LocalToWorld localToWorld) =>
                    {
                        var hash = (int)math.hash(new int3(math.floor(localToWorld.Position / settings.CellRadius)));
                        parallelHashMap.Add(hash, entityInQueryIndex);
                    })
                    .ScheduleParallel(Dependency);
zinc plinth
#

@leaden hatch from what I understand from it, with this you build a hashmap each time

ofc if you preprocess stuff you can get your multihashmap; but my solution didn't involve preprocessing

leaden hatch
#

Your way actually makes sense too, thanks, I'll have to think about it

storm ravine
#

I'm having problem with Burst where it throws error like that for a simple job.
@obsidian halo it's not an error in your code. It is cached error message and stack trace in case if this job write check fails and burst will need to throw it, as burst itself doesn't support throwing regular exceptions.

storm ravine
#

in a world of reference types that would make sense

but you can't really do that in ecs, not while keeping each entity a strict task
@zinc plinth You can. And moreover - you should. Spatial portioning (quad\octrees, simple spatial hash map, BVH tree etc) it's an exact case where you literally should store entities (or any other your type\indexer) for search\checks for performant and fast iterations on a scale. Space portioning absolutely not depend on reference\value types, OOP\DOD, it suitable and recommended for both approaches on performance-sensitive iterations, big scale. Simple example - physics, it's just can't work performant without that, this is why under hood, physics use this (BVH as one part of it). In our game we use spatial portioning for our own physics, for gameplay logic - closes enemy, closest resource, count in range etc. moreover we have more than one level of portioning. And of course, you shouldn't update it in a naive way every frame, you should use state change strategies (like state component, change filter, change order version etc.) BongoFat

ocean tundra
#

@storm ravine So many good ideas, im just starting combat now and have realised i need to find other units around me πŸ˜› sounds so simple but to support crazy numbers need to get real cleaver
So you find and cache closet enemy?

#

How do you know when it changes? wont you have to do a distance check every frame?

#

Except for your other point, you could update only when some other level of positioning changes

storm ravine
#

How do you know when it changes? wont you have to do a distance check every frame?
@ocean tundra
you should use state change strategies (like state component, change filter, change order version etc.)

ocean tundra
#

@storm ravine how do get around ref triggering the change number thing?

storm ravine
#

chunk iteration

ocean tundra
#

like i would like to have a condition first so not you update it

storm ravine
#

change filter

ocean tundra
#

oh i haven't really started with that yet

storm ravine
#

Change filter, filters chunks by type version in archetype, and wouldn't run your ForEach (not missing with running system itself, because it ignore filtering) if setted as filter component version for archetype for chunk wasn't changed. And If it changed it will process only entities in changed chunks.

#

Moreover for building spatial maps (any of type) you don't need ref only in and other systems which can change these types should use filtering, early out's, chunk iteration, CDFE with the conditional setter. For the new concept of IJobEntity (and Entities.ForEach) I requested, some code analysis processing for them, for check if you really change ref types in current code path and only in this case bump version, they noted that, and I hope this will be implemented soon.

ocean tundra
#

wait so your saying if eventually, if i dont change the value of the ref parameter it wont change the version?

storm ravine
#

That's the plan. But when it will (if will) not known yet.

ocean tundra
#

sweet thats awesome

wide fiber
#

In which update group should I put my system that performs a raycast to check it after the physics update? I think I am making a raycast but in the world that is 1 frame old

amber flicker
#

@ocean tundra Just wanted to emphasize change checks are per chunk - v useful but important to understand it's not per entity

wide fiber
#

In which update group should I put my system that performs a raycast to check it after the physics update? I think I am making a raycast but in the world that is 1 frame old
I have put [UpdateAfter(typeof(EndFramePhysicsSystem)] but it still perform the raycast in the 1 frame old world

ocean tundra
#

I put UpdateAfter BuildPhysicsWorld, im not sure if that is right

wide fiber
#

Ok ty I'll try

#

Thanks man, it works :D

ocean tundra
#

sweet

#

i never tested it

#

so good to know

#

πŸ˜›

amber quail
#

does anyone know if they are planning to add vfx to the dots stack?

thorny halo
#

Does anyone know if there're ways to return NativeArray indexes by ref rather than by value?

wide fiber
#

does anyone know if they are planning to add vfx to the dots stack?
I am also interested in VFX with dots

dull copper
#

I'm going to go and assume they mean that with DOTS as it's on dots subforum

mighty whale
#

Hi my friend and I are doing minecraft with ECS as a learning project, and we wanted to get the new Unity and ECS update yesterday however after the update our blocs became invisible SadCat

#

here are the components of our blocs

private static readonly EntityArchetype _archetype = _entityManager.CreateArchetype(
  typeof(Translation),
  typeof(Rotation),
  typeof(LocalToWorld),
  typeof(PhysicsCollider),
  typeof(RenderMesh)
);```
#

is this perhaps a known issue with the update that we can fix ?

#

ah turns out the solution was to add the renderbounds component

mystic mountain
#

What is worse, random read or random write? 🧐

vagrant surge
#

writes are read + write

#

unless some very specific instructions are used (not the case)

#

so actually random write is worse

#

unless the random read has a pipeline dependency (like being decision on a branch, or a pointer to other stuff), where latency is an issue

bold pebble
#

Can Burst be disabled for builds?

#

Never mind, found the option to disable it under "Burst AOT settings"

bright sentinel
#

@mighty whale Is your project pure DOTS or hybrid DOTS? Pure as in absolutely no references to UnityEngine and using the DOTS Runtime
If it's hybrid, then you might want to use the authoring workflow instead of making your objects in code. It will make it quite a bit easier to make objects in the future.

wide fiber
#

A rocket in my game has a Gameobject with a particle system as a child. How can I convert the rocket to an entity without converting the child? (The particle system doesn't work on entities)

tawdry tree
#

A custom IConvertGameObjectToEntity should be able to do it?

#

As part of Convert(), you most likely need to detach the child or something like that.

grave raptor
#

.

wide fiber
#

A custom IConvertGameObjectToEntity should be able to do it?
@tawdry tree isn't there a component that already does that? ConvertToEntity...

tawdry tree
#

IConvertGameObjectToEntity lets you cusotmize how it converts the gameobject to an entity. that will let you, you know, customize the conversion

wide fiber
#

The GameObject (the child, particle system) needs to follow the rocket entity and needs to be destroyed when the rocket is destroyed (I am using a linked entity group), I thought there was an easier way

tawdry tree
#

Not familiar with linked entity groups, and haven't really worked with gameobjects and entities interacting

wide fiber
#

@tawdry tree isn't there a component that already does that? ConvertToEntity...
Because if I try to use a normal GameObject with a particle system and Convert and Inject it works fine, but if I make it a prefab and I spawn the prefab in a system it doesn't work

storm ravine
#

Companion workflow exact for that purpose

#

@mighty whale Is your project pure DOTS or hybrid DOTS? Pure as in absolutely no references to UnityEngine and using the DOTS Runtime
If it's hybrid, then you might want to use the authoring workflow instead of making your objects in code. It will make it quite a bit easier to make objects in the future.
@bright sentinel conversion workflow is pure DOTS. Making entities through conversion doesn’t make it hybrid, it’s authoring, which at runtime - pure. Hybrid is when you using GO as runtime core with convert and inject, or manual syncing parts.

bright sentinel
#

@storm ravine I disagree, I'd say

  • Pure DOTS is using the DOTS Runtime (currently only Tiny).
  • Hybrid is using mostly DOTS, but still needing to inject gameobjects such as lights, cameras, UI that are still not possible, with the authoring conversion workflow. That's the way most people use DOTS/ECS right now
  • Unity GameObjects using jobs/ECS for specific parts. This doesn't have a name for me.
storm ravine
#

Again. Companion workflow - authoring for things not yet properly implemented. And its’s pure. Authoring workflow is intended pure. Using some things as helpers GO doesn’t make it hybrid. Build logic on GO/MB and DOTS parts as helpers - hybrid.

bright sentinel
#

Then why do you have to use the hybrid renderer for "pure" DOTS?

#

(Of course you don't have to, but there's no pure renderer - except for DOTS runtime)

storm ravine
#

Then why do Tiny use Unity.Tiny.Hybrid and Hybrid input if it pure? πŸ™‚

#

This is why I started discussion, to show β€œpoint of view difference” πŸ™‚ I doesn’t think personally, something here is pure or hybrid. I ended that separation long time ago. I just think about it as DOTS without any separation πŸ™‚

low tangle
#

pure dots was probably that one guy that bolted raylib onto tiny

#

rendering his own render entities directly

#

0 gameobjects

storm ravine
#

But I like arguing sometimes for showing that not all that simple and white/blackπŸ˜„ hope I didn't offend you @bright sentinel πŸ™‚ What about you @digital scarab, you can wait a bit, you destroyed my shiny plan, I prepared arguments/counter arguments which will show meaning difference in the end, but you destroyed that plan😒hate you (joke)

low tangle
#

hm

#

Pure ECS != Pure DOTS

#

the plot thickens

storm ravine
#

:blobsmilesweat2: I just wanted to make a joke about Joe being prayed to
@digital scarab and other guys from DOTS with I spoke about that🀣 From 2017 Unity become secret cultists praying about truth of pure or hybrid DOTS, even before It started call DOTS

low tangle
storm ravine
#

this is true, in fact DOTS was not a name we came up with, but was brought down from a mountain top having been etched in stone to be shared with the common folk
@digital scarab amen

warped trail
#

@storm ravine Tiny use Unity.Tiny.Hybrid so it will work in editor?πŸ€”

storm ravine
#

It’s namespace for HybridInput

warped trail
#

Hybrid input won't work in dots runtime cause there is gameobjects in there, so it is kinda editor only thingπŸ˜…

gusty comet
#

Yo, I explored DOTS a bit a while back. I remember it being quite feature incomplete ~6 months ago. Have been any "usability breakthroughs" done in that frame period? Or is it still a tool you only bring out when you need MAX POWAH?

stiff skiff
#

Now that the new "platforms" build system is required, does anyone know when the plan is to stabilize the API for that?

deft stump
#

can someone explain to me how ISharedComponentData work or how do I get the data between 2 entities to share the same data?

let's say I attached a sharedcomponent with an integer as it's data on 2 entities (let's call it E1 and E2).
On E1, I set the integer to 555.
but when I check at the debugger for E2's integer, it remained at 0.

am I fundamentally misunderstanding something how ISharedComponentData work?

graceful mason
#

I split a job into 5x different jobs as it takes a while, hoping to run them over 5 frames, anyone got any tips? I was trying to just add a componenent for each stage, so each system know what to process. But I think its running all 5 jobs in 1 frame. How to stop, do I just manually specify a reverse depdndancy chain? (e.g first job, depnds on second, depends on third)?

stiff skiff
#

A shared Component Data isn't "shared" between entities that have it

#

Its that entities with the same data in the "component" will share 1 instance

#

So 3 entities with "SharedMeshComponent" where 2 have a mesh A and 1 has a mesh B

#

results in 2 groups

graceful mason
#

so shared compnenet data is just all about chunks and performance, nothing functional?

stiff skiff
#

Its about filtering entities on data

#

Without them, you can query for all entities with "Mesh"

#

but you cant query for entities where "Mesh == A"

graceful mason
#

Oh I see, so it actually, splits your data into many more chunks?

deft stump
#

Aaaaaaaah.
It's not sharing but more like grouping

stiff skiff
#

Yeah, same archetype, but a group of chunks per variation of the shared component

graceful mason
#

ahaha I thought it was opposite πŸ˜„

stiff skiff
#

I try to avoid them, because they have an arbitrary limit of 8 per archetype

#

And I've found they are almost never the right design choice

graceful mason
#

I see, Ill have to think what I use them for. I thought storing my material in there would help with GPU instancing or something πŸ˜„

stiff skiff
#

It would

deft stump
#

I thought the same.

stiff skiff
#

Rendering can be batched if you render things with the same "parts" in sequence

#

Oversimplifying it a bit, but still

graceful mason
#

every object for me has unique mesh, shared material.

#

So I think they may get split into unique chunks

#

and it probably worse?

#

so its a unique value for everything

#

entityManager.SetSharedComponentData<RenderMesh>(chunkTerrain, new RenderMesh { mesh = unique_mesh, material = worldManager.material })

#

(I got the 0 batches in stats)

wide fiber
#

So there's no way to use particles in unity ECS?

#

But the problem is the prefab, because if the GameObject that has the particle system isn't a prefab and I put on it Convert and Inject it works perfectly

storm ravine
#

Hybrid supports a very specific set of internal components for use by the hybrid renderer. Right now it cannot support generally anything from classic Unity, such as particle systems.
@digital scarab but companion object doesn’t require hybrid renderer at all, it using classic hidden GO

#

Yep that’s true, but it works fine as temporary solution

#

We using that for camera, particles, post processing layers/volumes, audio

#

(Built-in renderer)

#

Yes. Same you can see in 5argons blog, I’ll find link for you

#

Companion Object section, exact sample for particles

#

And again how it relates to HR if they completely separate. Even your own tests use just any MB.

#

Under hood it not relates to this at all πŸ™‚ it's simply list oh hidden object with indicies for synch (simplified) πŸ˜„

#

looks like when we did that, we forgot to add the renderer :blobneutral:
@digital scarab seems so πŸ˜„

#

Afaik Fabrice making all that hybrid thing

#

Yep I know we speaking with him often, include Hybrid components topic πŸ™‚ He is one of Unity guys to which I met in person πŸ™‚

#

Hahaha yeah

#

When he came to Russia we often compare how similar French and Russian words

#

Yep hybrid components still buggy, bud what I heard and tested it's fine for most cases with convert to entity, and most part of bugs from subscenes workflow

#

have you met Valentin and Anton as well?
@digital scarab yep, of course, we chat with Val every day πŸ™‚ And with Elena from time to time πŸ™‚ Also I know two Ilya's (one working in Helsinki (he worked in Rovio), last time he brought me nice liqueur πŸ˜„ , and the second one always with funny green\pink hair :)forgot his second name, but I'm sure you know whom I mean) With Anton (if you speak about Anton Kruglyakov from DOTS team) we don't met in person but by email when we discussing with Unity about access to our game repo and Unity can look at our code, and how we utilise DOTS πŸ™‚ I also know more foreign guys (I mean not Russian) in person from different Unity teams, and whole more by direct chatting or video calls πŸ˜„

stiff skiff
#

Slack?

storm ravine
#

Including slack channels (like ext-dots, ext-hybrid-renderer)

wide fiber
#

@wide fiber exception not about conversion, but about command buffer
@storm ravine it gives me the errors only if I add that component to the entity

storm ravine
#

Well I know him only by emails πŸ™‚ (Kruglyakov?)

bright sentinel
#

@storm ravine Not offended at all, just busy with exams πŸ™‚ I think the real problem is that there is no official stance on it and the concepts are a bit muddied. I think we're mostly speaking about terms here, and we're both very aware of the differences.

storm ravine
#

Yep is exact what I meant (and Topher spoilers) - even Unity don't know where edge and what is Hybrid and what is Pure (yet) πŸ™‚

#

Well then I know about him a bit πŸ˜„ Sometimes I feel ΡŒΠ½Ρ‹ΡƒΠ΄Π° like I'm working in Unity, especially when spent a couple of hours per days with you guys fixing or reproducing some bugs in DOTS. But it's pretty funny, and helps both sides - Unity fix hidden tricky bugs, us - fix project and continue work without workarounds πŸ˜„

#

Earth small, you always know someone who know someoneFeelsRainMan

wide fiber
#

Ty I'll check the videos later :D

verbal pewter
#

How do you check if an entity has a component within a system? It's not the entity that I'm currently iterating over, either.

storm ravine
#

@digital scarab Np, glad to help, it will help many newcomers and studios who want to try DOTS πŸ™‚ this sort of bridge will simplify their life

#

How do you check if an entity has a component within a system? It's not the entity that I'm currently iterating over, either.
@verbal pewter if it on main thread - EntityManager. If it on main thread - ComponentDataFormEntity. And if you inside SystemBase then you have helpers wrapped around things above - HasComponent, AddComponent, GetComponent

verbal pewter
#

@storm ravine Yeah, it's inside SystemBase. Hmmmm, it seems like I'm able to call HasComponent within the OnUpdate call, but I'm not able to call it from a static method that belongs to the SystemBase class.

storm ravine
#

Yes

verbal pewter
#

Are we meant to use EntityManager outside of OnUpdate?

storm ravine
#

Use EM (for main thread) or ComponentDataFromEntity which passed as argument to static method

verbal pewter
#

Ah okay

#

I haven't used ComponentDataFromEntity yet, will need to look into that.

storm ravine
#

Are we meant to use EntityManager outside of OnUpdate?
@verbal pewter of course, you can use it anywhere on main thread

#

Just remember about Synch Points

verbal pewter
#

I'll be honest, I'm not super familiar with them. My understanding is that they represent points where the program has to wait to ensure all threads are caught up to proceed, so that it can guarantee that specific data isn't going to be changed in the middle of being used. Is that right?

storm ravine
#

yes

timber rivet
#

So I have implemented a simple raycast in an Entities.ForEach where I do a raycast for each of my detector entities that I am looping over, find the closest target entity, get component data, and write to the detector entity's components. I'd like to have it return all entities the raycast hits, though, not just the closest, and when using the overload for that Unity gives me a lot of errors that look something like this:
InvalidOperationException: The previously scheduled job DetectorSystem:<>c__DisplayClass_OnUpdate_LambdaJob0 writes to the NativeArray <>c__DisplayClass_OnUpdate_LambdaJob0.JobData.collisionWorld.Broadphase.m_StaticTree.Nodes. You must call JobHandle.Complete() on the job DetectorSystem:<>c__DisplayClass_OnUpdate_LambdaJob0, before you can read from the NativeArray safely.
So it sounds like collisionWorld.CastRay(input, ref allHits) is actually writing to something in CollisionWorld and for obvious reasons ECS doesn't like that. Is there any possible workaround to that so I could use that overload in parallel?

deft stump
#

how do I approach a grid-based movement in ECS?
I have 2 ideas but I dunno which is best
is it 1.) make every cell it's own entity with it's own coordinates component?
or 2.) do I make a "grid manager" entity with a dynamic buffer component?

thorny halo
#

Hello, does anyone know how to lay out data of a NativeHashmap to make "NativeHashmap<key, NativeArray<>>" viable as a concept? I'm currently doing "NativeHashmap<Vector3Int, struct>" where the struct has multiple NativeArrays inside it, which makes it unusable in a job due to NativeContainer not allowed in a NativeContainer problem. Once in a job, the structs will need to access the NativeHashmap again to check for neighbouring structs of same type.

storm ravine
gusty comet
#

question: is indirect lighting still not supported for HDRP in the hybrid renderer?

wide fiber
#

The problem exists only when I try to Instantiate the prefab in a system (with an ECB), not when I use it normally

#

If I comment one of the 2 lines (10, 11) it doesn't give me any error but it doesn't work...

storm ravine
#

When instantiating prefabs. Yeah it form ManagedChangesTracker.PatchEntitiesForPrefab where CommandBuffer fills commands queue where one of them PatchManagedEntitiesForPrefabs

#

Pointed Fabrice to this

dry dune
#

What is the right way to handle 3d object - mouse interactions using dots?

#

is Collision queries from unity.physics is a way to go?

ocean tundra
#

Whats muse?

dry dune
#

mouse

storm ravine
#

Mouse obviously

ocean tundra
#

wayy to early for me to figure that out :P, I use the Unity.Phyics for my mouse picking, i just do a raycast on mouse click

#

and for click and drag i create a frustum and test against that

dry dune
#

is there any up to date example for raycasts using dots?

ocean tundra
#

i just use the docs

#

theres a example at the bottom

dry dune
#

thanks

storm ravine
#

Well I showed simple example for mouse sphere interaction , year or 1.5 years ago, but yeah it's raycasting in general (I showed simple custom raycast, not from physics)

#

If you using physics already - use raycast, because it has optimised BVH for checks. If you not using physics, well I suggest choose between (again) physics or your own simplified solution. Because we not always require whole physics for such simple thing.

ocean tundra
#

yea theres tons of Physics im not using

#

eventually will look at replacing it

dry dune
#

before i had mouse interactions only with 2d grid on the fixed plane, so i've made my own simple reaycast function, but now i need to interact with 3d objects above that plane, so looking for right way to do it, i don't use physics
so looks like now i need physics just for collision queries

ocean tundra
#

yup thats what I use it for

dry dune
#

got it working, thanks

craggy hinge
#

hey! could anyone help me understand the difference between Schedule() and Run() for an ECS foreach loop?

safe lintel
#

i believe in JobComponentSystem, Schedule ran jobs as parallel(as opposed to ScheduleSingle which ran a job on one worker), using systembase now requires you to use ScheduleParallel, and Run is just running the job on the main thread immediately

craggy hinge
#

aha! Ok, thanks

ocean tundra
#

Anyone used Unity.Physics Triggers?
I have created a trigger collider and added it to my main entity all via code and i think im still missing something

#

I cant get any trigger events to fire

hollow sorrel
#

what does your code look like

ocean tundra
#

I probably have a issue with all my entitys being static as i dont want the physics system to move my things

hollow sorrel
#

you have static entities trying to (trigger)collide with other static entities?

ocean tundra
#

yup

#

probably not allowed

hollow sorrel
#

yea that sounds weird

#

if you're moving them with code instead of physics should make them kinematic

ocean tundra
#

hmmm

#

i basicly just want physics for the collision query's

#

i might just not use triggers

#

instead just use collider distance checks

#

whats the way to make a kenimatic physics entity?

hollow sorrel
#

should check if kinematic/static actually is the issue, i imagine if it's marked static it might not update its position on physics side at all but not sure

ocean tundra
#

yea was just going to test that

hollow sorrel
#

you mean from code not authoring?

ocean tundra
#

yup

#

just add a PhysicsVelocity?

#

oh wow i thought physics would completly take over

hollow sorrel
#

yea seems to be just velocity

ocean tundra
#

yea

hollow sorrel
#

physicsbody conversion seems to be adding a physicsmass and gravity as well with inverses and gravity set to 0

ocean tundra
#

i thought my objects would all fall over

hollow sorrel
#

dunno if that's needed

#

but yea kinematic is basically don't simulate physics on this object but still include it in queries

ocean tundra
#

sweet

#

looks like its happy

hollow sorrel
#

πŸ‘

ocean tundra
#

sweet

#

even trigger vs trigger works

wide fiber
#

It like a bug in PatchEntities
@storm ravine so it is a bug, for now there is no way to get around it?

south falcon
#

Do you guys know how to make a buff system in ECS?

toxic walrus
#
public class BuffSystem : SystemBase
odd cipher
#

lol

south falcon
#

πŸ˜‚

storm ravine
#

But you all know...technically... Brows

graceful mason
#

cant debug my enteties as I polluted them all with strings

burnt depot
#

Dumb question that probably relates to a fundamental misconception somewhere.... I am doing a "hello world" project with DOTS & Tiny that just has 1 entity that is a spinning sprite on screen. I access that entity via
var logoEntity = GetSingletonEntity<Logo>();
... and hitting play in editor, that works exactly right. It spins. Great. Hello, World! But... if I build to wasm and run in browser, I get this error:
The exception message is: GetSingletonEntity() requires that exactly one exists but there are 0.
So what gives? Why is it even possible that this line runs in Editor but not in the build? What detail am I overlooking? Do I have to explicitly register my singleton and there's a race condition or something?

viral sonnet
#

hey! any resources for dots fast-forward/rewind?

pliant pike
#

@burnt depot are you sure you don't get that error in the debugger when running in editor, you normally get one warning at beginning when using getsingleton because systems exist before entity's and so there is no entity at the start

burnt depot
#

i do not get any warning or error in editor (while running)

pliant pike
#

well anyway I usually use HasSingleton to check first if there is a singleton

bright sentinel
#

@burnt depot How are you building? First off, I have no idea whether web is supported yet for DOTS/Tiny unless doing some custom stuff. It may be that it is though, but I have no idea. Secondly, you probably need to use the build configurations rather than just "build and run"

burnt depot
#

i am using the build configuration, yes -- used project tiny samples for reference. I have built several of those to wasm and deployed them runnably successfully

bright sentinel
#

Alright, that seems right, just wanted to confirm it. How are you creating the cube?

burnt depot
#

short circuiting the system with HasSingleton seems to work in editor and in build now. I'm going to squint at that for the moment as something-something-cache-something πŸ‘€

pliant pike
#

instead of using hassingleton you can use RequireSingletonforupdate as well, depending on your use case

burnt depot
#

it took me approximately 2 hours to write and deploy a spinning sprite that changes color that runs on my phone (browser). It's like learning how to program all over again. I am enjoying my confusion πŸ˜›

leaden hatch
#

to test the material property stuff I'm trying to link my entities' material properties to the color, but it doesnt seem to be changing
I've got my component set up like

[MaterialProperty("_ColorTest", MaterialPropertyFormat.Float3)]
public struct SPHVelocity : IComponentData
{
    public float3 Value;
}

And my shader just takes the normalised float3 value as the color. But ingame its permanently the default color. Not sure why when the velocity is definitely changing

coarse turtle
#

o when did they add a material property attribute?

leaden hatch
#

like 2018 πŸ˜›

#

I think

coarse turtle
#

πŸ‘€ I'm late lol

#

any link to a doc? Trying to find it in their scripting api lol

leaden hatch
#

oh wait maybe not 2018, srry πŸ˜„

coarse turtle
#

o it's part of the hybrid renderer

#

ah that's why i didn't know abt it- haven't used it yet haha

leaden hatch
#

and I'm on 2020.1.0b8 which is past what they require

#

they allow vector 1 and 4 but not 2/3 D:

leaden hatch
storm ravine
#

@storm ravine so it is a bug, for now there is no way to get around it?
@wide fiber Well, Fabrice answered that he is 90% sure that it's fixed internally (not released yet) but he want double-check that. Anyway it's bug and it already fixed (90%) and, possibly, will be in next release

wide fiber
#

Ok ty

mint iron
#

@coarse turtle its pretty recent, you could do it in HR v1 with significant hacks, then they put it in proper for v2 so its like 1 month old-ish.

coarse turtle
#

good to know πŸ™‚

scarlet inlet
#

Hello, long time now see. There is something with the profiling that is driving me crazy, who's up for some fun stuff regarding mono CLR and maybe IL2CPP too? It may be DOTS related because it's about iterating an array of 1M elements (without using BURST)

burnt depot
#

any idea if text is supported in project tiny? ... I see there used to be a Unity.Tiny.Text package/components in much older versions (~0.13) but I do not see these in later versions (~0.22). Did this get dropped perhaps?

#

and suspiciously see text in the samples as being baked into sprites

flint schooner
#

Need help with NativeSlice anyone have experience with it and a couple of minutes to explain something

storm ravine
#

Everyone. What the question?

flint schooner
#

documentation refrences things like ToArray() and such, but VS2019 doesn't show that as a method etc (and most of the othe things the docs sy)

storm ravine
#

It converts it to T[] which mean it's not for jobs, but you can use it on main thread

flint schooner
#

huh weird

storm ravine
#

Nullable type

#

Why you using it here

flint schooner
#

DOH

storm ravine
#

.Value gives you ToArray

flint schooner
#

I want to copy out the positions from the DPC from arfoundation for my own manipulation

storm ravine
#

show where you set positions from point cloud list

flint schooner
storm ravine
#

I asked where exact slice set, from where that event was thrown πŸ™‚

#

Or it's from engine side? Which type of these positions exact? Same nullable slice?

flint schooner
#

From a Unity3d ARPointCloudManager Unity component (engine)

#

public event Action<ARPointCloudChangedEventArgs> pointCloudsChanged;

#

public struct ARPointCloudChangedEventArgs : IEquatable<ARPointCloudChangedEventArgs>
{
public List<ARPointCloud> added {
get;
private set;
}

public List<ARPointCloud> updated {
    get;
    private set;
}

public List<ARPointCloud> removed {
    get;
    private set;
}
storm ravine
#

Which type of these positions exact? Same nullable slice?

#

Hover mouse to positions in VS

flint schooner
storm ravine
#

Yep I looked at docks

#

Sh***y design....using nullables 🀒

flint schooner
#

hopefully I'm back on track now you pointed the nullable out, can't believe I didn't see it.

So very few examples of this code in the wild to verify against!

storm ravine
#

Well in this case you should use slice?.ToArray(); which will return null if slice null or T[] if not null

flint schooner
#

Yeppers

#

Thanks for the help πŸ™‚

sand prawn
#

Anyone else witnessing TONS of draw-calls for shadows using the Hybrid Renderer?

#

Am I doing something obviously wrong?

bright sentinel
#

Can you even do NativeSlice<Vector3>?

sand prawn
#

(this is if I draw 10000 cubes, btw)

bright sentinel
#

Shouldn't you use float3?

sand prawn
#
    protected override void OnCreate()
    {
        ecbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();

        GameObject go = Resources.Load<GameObject>("3DObjects/RedCube");
        if (!go)
        {
            UnityEngine.Debug.LogError("Couldn't load RedCube prefab, bailing!");
            return;
        }
        redCube = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, GameObjectConversionSettings.FromWorld(World, assetStore));
    }

    protected override void OnUpdate()
    {
        var ecb = ecbSystem.CreateCommandBuffer();
        Entities.ForEach((Entity entity, ref PWCmdRpcCommand command) =>
        {
            Console.WriteLine($"Server got PWCmd: {command.command}");
            float3 position = new float3(1.0f, 1.0f, 1.0f);

            using (NativeArray<Entity> entities = new NativeArray<Entity>(10000, Allocator.Persistent))
            {
                EntityManager.Instantiate(redCube, entities);

                for (int i = 0; i < 100; i++)
                {
                    position.x += 2.0f;
                    for (int j = 0; j < 10; j++)
                    {
                        for (int k = 0; k < 10; k++)
                        {
                            Translation pos = new Translation();
                            pos.Value.x = position.x + i * 2.0f;
                            pos.Value.y = position.y + j * 2.0f;
                            pos.Value.z = position.z + k * 2.0f;

                            var ent = entities[(i * 100) + (j * 10) + k];
                            ecb.SetComponent(ent, pos);
                        }
                    }
                }
            }

            PostUpdateCommands.DestroyEntity(entity);
        });
    }
#

Oooh, sorry for the spam

#

Thought it would end up in a smaller window

storm ravine
#

Set GPU Instancing on material.

sand prawn
#

Ooh, durh. Thanks!

#

Down to 40ish draw calls. Nice, thanks!

ocean tundra
#

So I'm moving some common code to a static class so i have a bit of reuse. Is there any point to marking the input parameters as 'in'? and should I worry about using a return or have a 'ref' parameter?
Finally is that AggressiveInlining attribute worth it?

sand prawn
#

How do people do profiling of netcode? Bytes/sec that sort of thing?

bright sentinel
#

@sand prawn There's the PlayMode tools debug

#

In the NetCode menu in Unity

sand prawn
#

@bright sentinel Thanks!

#

@bright sentinel I can make my network suck there, don't see a way to measure?

bright sentinel
#

suck?

sand prawn
#

@bright sentinel Okay... I'm now able to see bytes serialized on a frame by frame basis... but I'm not seeing in/out bytes sent after delta compression

tardy locust
#

So here is a question as I've not used it before

#

If I use the "Conver to Entity" script on a prefab that has no scripts but is just a bunch of gameobjects put together to look like a model

#

And then choose "Convert and Inject" rather than "Destroy"

#

How do I reference the resulting entity that is injected?

sand prawn
#

@tardy locust Tag it with a unique component so you can find it in queries?

tardy locust
#

Alright. I don't know how they expect you to work with it so if that's how to do it I can do that

sand prawn
#

I could DEFINITELY be wrong

#

but based on how everything seems to work

#

that seems to be the expectation

tardy locust
#

Okay

sand prawn
#

@tardy locust Even down to like, state-machine style behavior where you remove one tag comp. and add another to indicate a state transition

tardy locust
#

Oh

#

What about Instantiating prefabs?

#

Lets say I wanted to make 50,000 of those Bees

#

I can do that fairly easy by spawning a bunch of mesh renderers with Entities

#

But they don't look like my lil' bee

graceful mason
#

I just want to check, an IJob can run indendantly of the game loop, potnetailly for 5-10 seconds?

sand prawn
#

@tardy locust Like, the meshes are distorted or something?

tardy locust
#

It's a bunch of GameObjects

#

Just primitives

sand prawn
#

@tardy locust There's a routine for converting the heirarchy

tardy locust
#

How do?

sand prawn
#
        GameObject go = Resources.Load<GameObject>("3DObjects/RedCube");
        if (!go)
        {
            UnityEngine.Debug.LogError("Couldn't load RedCube prefab, bailing!");
            return;
        }
        redCube = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, GameObjectConversionSettings.FromWorld(World, assetStore));
#

I'm doing that

#

Where assetStore is a BlobAssetStore I'm allocating and then Disposing in OnDestroy()

#

Now redCube is an entity that I can instantiate

tardy locust
#

So RedCube is a prefab?

sand prawn
#

Yeah, "3DObjects/RedCube" is a regular prefab, basically

#

(I have a ghostauthoringcomponent on it for multiplayer)

#

(note that it has to be in a Resources directory for the Resources.Load to work)

tardy locust
#

I'm just making a little sandbox thing. I'm not doing MP right now

sand prawn
#

Yeah, you don't need that component then

#

@tardy locust If you want more code than that, I pasted a bigger hunk further back

tardy locust
#

I'll try and see if I can do with this

#

thanks

zinc plinth
#

I wonder if the routine fuses the meshes or ?

#

cuz if not that seems to be really ineficient vs creating a single mesh with everything in it

sand prawn
#

I don't think it changes meshes at all? Are you talking about the ConvertGameObjectHeirarchy I posted above?

zinc plinth
#

ya

sand prawn
#

I don't think so. Just makes components out of the bits of data that have Convert() overrides, I assume

#

(ie., they implement that IConvertableToEntity thing or whatever)

zinc plinth
#

yea..

sand prawn
#

There's a way to merge meshes, though, I think? Could be done here at load-time fairly cheaply, I would think?

tardy locust
#

Well given that it's supposed to happen before the game starts

#

The time is something you can ignore, mostly.

sand prawn
#

I'm loading my objects dynamically here

#

You can probably do better than this if you anticipate being able to bake merged meshes at build time or something

tardy locust
#

Any reason you wouldn't load at least the prefabs ahead of time to make archetypes of them?

sand prawn
#

Nope, there's no reason not to do that

#

I just don't know how

tardy locust
#

What does the Conversion return to you?

sand prawn
#

And I needed my objects loaded dynamically anyway

#

An entity

#

Entity

#

(with all of its sub-entities converted, too, if they can be, presumably)

#

(And components converted from old-style to ECS friendly, for those that support it)

tardy locust
#

So all the components you get from the conversion and the entity

#

Could be put in an archetype

#

right?

sand prawn
#

Sure, but as you add components, your stuff is likely being moved anyway

#

You end up w/ archetype chunking whether you want it or not, afaict

tardy locust
#

But you talked about loading prefabs dynamically, not about switching out components right?

sand prawn
#

The code I gave you loads a GameObject prefab and converts it to entities. GameObjects have non-ECS components that need conversion

#

right?

tardy locust
#

I suppose so, yes. But are they not converted at the same time?

ocean tundra
#

PS i recommend using Addressables instead of resources πŸ™‚

sand prawn
#

@tardy locust They are.

#

@ocean tundra Yeah, just didn't wanna learn both today

tardy locust
#

@ocean tundra I do wanna learn about those

sand prawn
#

@ocean tundra Also: really hard to find ECS-friendly examples of Addressables in use

ocean tundra
#

i use them, dont really have any good examples tho

sand prawn
#

@ocean tundra For example, all the Addressables stuff is async, right? How do I load that stuff in OnCreate?

ocean tundra
#

i just do addressables.load and then pass the result into the gameobject convertion utility

sand prawn
#

Can my OnCreate be an IEnumable ?

ocean tundra
#

oh yea it is, i have all my load stuff in a normal monobehaviour

sand prawn
#

Ah, ok

ocean tundra
#

as i dont use the autocreated worlds

sand prawn
#

Autocreated worlds?

ocean tundra
#

the default world

#

i make my own

sand prawn
#

I assumed DefaultWorld was just legacy Unity (GameObject) style data anyway?

ocean tundra
#

and i dont have them updating automaticly, i call world.Update on them

sand prawn
#

Is it not?

#

From a MonoBehaviour script?

ocean tundra
#

yea

sand prawn
#

So no SystemGroups?

ocean tundra
#

its cause i wanted my server world to update in fixed update

sand prawn
#

Aren't you losing out on some free coordination?

ocean tundra
#

i still have those

#

i still create and setup the world the same, but its not auto updating

sand prawn
#

hum

#

Wish I could look at your code; having a hard time wrapping my head around that

#

What's the purpose of that structure?

ocean tundra
#

for MP, my server world updates in fixed update

#

but my client world runs in update

sand prawn
#

Hm, ok... and you're using ENet-CSharp, right, not NetCode?

ocean tundra
#

i also wanted full control of the loop, so i can break out bits, for example i have a bit of server code that runs in the update AFTER fixed update πŸ˜›

#

yea all enet

#

i may use netcode

#

but theres like only a small part of it i would want

sand prawn
#

Which part is that?

ocean tundra
#

Jobs + reliable messages

#

any of the replication/prediction stuff will get in the way of my stuff

sand prawn
#

Does ENet not have a reliable layer?

#

I thought it did

ocean tundra
#

yea ENet is reliable

#

but unity.Transport isnt

#

and netcode is on top of that

sand prawn
#

Wait, does ENet not have an unreliable layer, then?

#

Right....

#

NetCode's replication tech seems pretty tidy, but the prediction is, so far, not my favorite. I probably haven't wrapped my head around the whole thing yet

ocean tundra
#

so for some world creation code:
var world = new World("Server");
var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default, false);

#

that will create a world that match the default ones, (all systems and groups and stuff)

#

sorry with this bit too

#

DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, filteredSystems.ToArray());

#

between those i do some of my own stuff, like netcode does with the UpdateInWorld attribute

sand prawn
#

ok....

ocean tundra
#

then to update the world just call world.Update

#

the biggest issue is the DOTS inspector, it wont show me the systems for the world 😦

#

but I've reported it, and its on the to fix list

#

to make it worse i plan to have many server worlds, (maybe many client worlds too??) so parts of my game can be completely separate

#

PM me if you want any more details

zinc plinth
#

is an entity version updated only in ECBS, or as soon as you get the command in the ECB ?

#

I would guess there would be concurrency issues if it's in the ECB, but I'd prefer to be sure ^^'

ocean tundra
#

?? More details?
The entity version never changes, unless you destory then recreate

zinc plinth
#

context: filling a dynamic buffer with entities, and making sure that those entities don't sudenly refer to nothing

and isn't it the version that changes when you make structural changes (add/remove components) ?

but I'll make my question more broad: does an entity change(id or version) outside of ECBS

ocean tundra
#

not that ive seen

#

i add and remove all the time

zinc plinth
#

so I don't have to keep track of components getting added/removed when storing Entity structs ? :O

ocean tundra
#

nope

#

i use it between my client and server

zinc plinth
#

well that will be wayyyy easier than I thought then lul

storm ravine
#
        GameObject go = Resources.Load<GameObject>("3DObjects/RedCube");
        if (!go)
        {
            UnityEngine.Debug.LogError("Couldn't load RedCube prefab, bailing!");
            return;
        }
        redCube = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, GameObjectConversionSettings.FromWorld(World, assetStore));

@sand prawn bad practice. In this case you create and destroy conversion world for every call, very ineffective πŸ™‚

ocean tundra
#

instead of having a network id im currently using the server Entity

#

@storm ravine is the bad part creating a new GameObjectConversionSettings?

sand prawn
#

@storm ravine That code only happens in one OnCreate()

#

But what world am I creating/destroying?

storm ravine
#

context: filling a dynamic buffer with entities, and making sure that those entities don't sudenly refer to nothing

and isn't it the version that changes when you make structural changes (add/remove components) ?

but I'll make my question more broad: does an entity change(id or version) outside of ECBS
@zinc plinth structural changes affect types versions in chunks (or order version if you create/destroy entities). Entities version persistent until you destroy and create, thus index will be reused with different version.

zinc plinth
#

so as long as I track create/destroy of entities I'm good ?

ocean tundra
#

yea i guess so, when one of your entities is destoryed you probably want to remove from that list

#

use ISystemStateComponents for that

storm ravine
#

@storm ravine is the bad part creating a new GameObjectConversionSettings?
@ocean tundra > @storm ravine That code only happens in one OnCreate()
@sand prawn call ConvertGameObjectHierarchy for every prefab - bad practice. If you have 1-2, thats not so important, but if you have more... This method on call create new conversion world, converts GO, return converted entities to destination world and destroy conversion world. I’m going to sleep now, maybe I’ll show you tomorrow why it’s bad if don’t forget.

ocean tundra
#

@storm ravine Sweet, looking forward to it, I def do that per prefab, but I do that all during load so not super worried yet

storm ravine
#

use ISystemStateComponents for that
@ocean tundra or GetCreatedAndDestroyedEntitiesAsync

ocean tundra
#

OOOOOoooo Never seen that, To the Docs!!!

sand prawn
#

@storm ravine What's the superior approach, then?

ocean tundra
#

@sand prawn At a guess i would say that GetCreatedAndDestroyedEntitiesAsync but im unsure how to use it

tardy locust
#

If you can make something happen async

#

Then it seems to be the way to go in general

ocean tundra
#

agreed

#

but i dont know where you get the State input list for that method

#

but also, i would start with whats easiest to get going

#

then when you start profiling refactor bits

ocean tundra
#

What's the best way to do a timer now?
Example is a attack timer (can only attack every 5 seconds)
Currently I add a attack component with a timer value set to 5 seconds then inside OnUpdate i ForEach over them and subtract delta time until it equals 0

wide fiber
#

Can you give me some tips on using UI with Unity DOTS?

Should I convert to entity the canvas... Or should I keep them GameObjects?
Can I access components in entities from a MB?

eager jungle
#

hi guys, can anyone point me to the proper way of creating a custom begin/end ECB system for a custom group? I looked at DefaultWorld.cs, but the code is using some internal member. Cheers

Edit: I'm using var m_systemsToUpdate = this.Systems as List<ComponentSystemBase>; to do the re-ordering, which is a bit dirty imo knowing this.System is a readonly IEnumerable, but it works... Any better / official way of doing it is very welcome.

storm ravine
#

@sand prawn @ocean tundra Ok I'm here. Now I'm explain why ConvertGameObjectHierarchy bad on scale. If you look at source code and how it works it become obvious. Inside ConvertGameObjectHierarchy you'll see this. And if you look in to it you'll see that it creates new World (see second image) for conversion, add bunch of conversions systems with their initialization (from settings or from default systems), converts just one your game object, move to destination world and destroy conversion world. And this happens every time when you call that method, if you will convert 30 prefabs - you'll create new world, populate it by systems, destroy that world 30 times. Even in start\oncreate it become expensive.

#

In opposite, if you look how ConvertToEntity works - it also create new conversion world and populate systems, BUT (big but) it doing that once for batch of objects. And when if things in OnCreate\Awake\Start they all converted with World created once

#

Because ConvertToEntity in Awake populate list of all ConvertToEntity mono behaviours.

#

And performance difference very valuable, no one want stuck game at loading for 30 seconds instead of 5

#

About addressables and how we using them with DOTS

#

SubScenes doesn't have good support, currently, for them, and we using ConvertToEntity here. We loading all required AssetReference's through LoadAssetAsync, which not freeze main thread and we can do any thing (in our case it's game intro\credits\etc at application start), when all required assets loaded we create one hidden go with convert to entity and pass all loaded GO to this hidden GO (with specific mono behaviour - PrefabsConverter) which populate IDeclareReferencePrefab, and in Convert fill our dictionary of entity prefabs (we have own unique ID system where every object has it's own unique persistent ID). And thus converts all prefabs at once.

#

In our authorings we have some custom inspectors for these unique ID's which allow us to has "reference" to prefab even without that prefab and before conversion

#

Because that ID is persistent (important) unique int which mean it will be the same in build and in editor

#

There is couple of custom editors, scriptable objects etc which helps other people in team (like artist, gamedesigner etc.) easily setup things, for example they just create prefab, fill it by required authorings and press one button and all this converts to required for loading representation, with required labels, utility components and SO, addresable references and groups etc.

#

Which allow you do every thing you need with that prefabs in editor before conversion. Like create initial buildings presets with all params like this when you can easily select required prefab and add to initial building set with parameters drag it through map, literaly "draw" them on map. and see where it will be in game for selected generation preset.

#

And approach of converting this things through that hidden GO with ConvertToEntity much faster than ConvertGameObjectHierarchy (which obvious)

#

Sorry to other for that little lecture for these guys πŸ˜„ they asked I answered

#

OOOOOoooo Never seen that, To the Docs!!!
@ocean tundra It's new from 0.10 (I knew about that before from Simon because I requested exact same thing, and luckily they implemented that at the same time), it allow you to have lists of created\destroyed entities between calls which also very useful for processing chunks with destroyed entities (because change filter doesn't handle entity destroying per chunk, and order version does)

wispy walrus
#

Hey, I've got a NativeArray<MyType> that I am passing around through managed code functions, and each time it obviously creates a copy of the wrapper that holds the pointer to the native array, and throws errors about memory leaks, although I dispose the allocated memory later on. Do I have some kind of a misunderstanding about this (is the NativeArray not a wrapper, is there an actual leak everytime its cleared from stack?) or the errors are just stupid?

stiff skiff
#

What do the stack traces for the leak say?

wispy walrus
#

Just points out where the memory was allocated (created)

#

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:

amber flicker
#

are you passing by ref?

stiff skiff
#

Shouldn't need to right?

#

The DisposeSentinel works by its finalizer, and if you pass by value both instances of the NativeArray will reference the same sentinel

wispy walrus
#

I tried, no luck

amber flicker
#

Short answer: I don't know. This could be a bug with the safety system I guess.

wispy walrus
#

currently withhout ref

amber flicker
#

Don't suppose you can tell if you actually do have a leak?

wispy walrus
#

as far as I can tell no leaks

#

the behavior seems as I would expect

stiff skiff
#

Do you have a snippet to share?

wispy walrus
#

its all over the classes, but I can share something later, I havea noob quesiton first πŸ™‚

amber flicker
#

If you can reproduce it with a small snippet, sounds like it would be worth posting on the forums.

stiff skiff
#

@wispy walrus Which version of entities are you on?

wispy walrus
#

I dont have entities package but I think I have burst

#

yes entities is not installed

stiff skiff
#

you have burst, its installed through entities as a dependency

wispy walrus
stiff skiff
#

You're on 0.8.0, that page just shows latest (0.10.0)

wispy walrus
#

I was trying to show the install button implying that I dont have it installed

stiff skiff
#

What kind of Job is JobExample? (Which interface)

wispy walrus
#
struct JobExample : Unity.Jobs.IJob {
    public void Execute() {
    }
}```
stiff skiff
#

Ah.. I mixed collections and entities, wow, SORRY

wispy walrus
#

do I need it for schedule to work?

#

it shhould be a dependency no if so?

stiff skiff
#

Just normal Schedule() should do

wispy walrus
#

there is no normal schedule

#

😦

wide fiber
#

I don't know what's the problem, but the VSCode Editor 1.1.4 package has a lot of problems, downgrade to 1.1.3

stiff skiff
#

Do you have using Unity.Jobs; at the top?

wispy walrus
#

nope

#

is thaht extension method?

#

@stiff skiff THHANK YOU! that works πŸ™‚

#

noob slight )

stiff skiff
#

Its a super easy mistake to make

#

The extension methods show up due to one of the using's you have, but the basic method didnt

wispy walrus
#

yeah didnt find the problem in docs for schedule

stiff skiff
#

Its because a lot of things are now extension methods for some odd reason

#

No idea why

storm ravine
#

@wispy walrus There is no need pass native container by ref. How long your container should live? And when you although I dispose the allocated memory later on I guess you doing that not in same (or close) frame, and later? If so, just show me where you allocate that container, or tell which allocator type you using. I guess you using TempJob allocator?

deft stump
#

@wide fiber there's vscode 1.2.0 which solves the problems in 1.1.4

wispy walrus
#

@storm ravine no, I am crreating a persistent container and it lives pretty much as long as the application life.

storm ravine
#

Well we need to see code. Because it's definitely work as we have many persistent containers which walking through outr systems until application close

wispy walrus
#

I also have native array pool (just a List) where I push and pop arrays. Each push and pop throws leak warnings because the value type is destroyed from stack but there are no leaks since the memory is 'shared'

zinc plinth
#

did you use Allocator.Permanent ?

storm ravine
#

@zinc plinth Persistent not Permanent and yes he using it as he mentioned. This is why we need to see his code. Because I'm sure is user error :)

@wispy walrus I am crreating a persistent container

wispy walrus
#

Can be, I will try to simplify and reproduce it than share the code if its still there

#

hah, calling Dispose in OnDestroy did it....

#

I had IDisposable implemented for everything that works with native collections, so that its responsible to release the memory later. But I did not call it thinking the class finalizer will trigger it anyway, but leak detection worked before the finalizer did.

#

thats my theory anyway

#

explicitly calling dispose fixed the problem

storm ravine
#

Yep, depends on how and where class instances lives finalizer can run much later than you exit play mode, especially when domain reload disabled. In simple case your destructor called not on exit from play mode, but right after pressing play and creating new instance for field where your previous instance lives. Personally I didn't like destructors pattern and prefer handle disposing things myself (not only in Unity context)

wispy walrus
#

agreed, I like to know where my memory is and how its handeled.
On hindsight that explains why the errors were so inconsistent and random.

frail seal
#

I got rusty at Dots, can anyone remind me why this piece of code crashes my editor as soon as I hit play?

#

Oh wait, now I think I get it.

golden elk
#

check the editor log for the error

frail seal
#

It probably crashes because I divide 0 by 0

golden elk
#

that is certainly problematic

frail seal
#

Yeah, but if it is the cause, then it's just stupid

golden elk
#

yes it is

frail seal
#

.....yeah. That was the issue.

#

I was wondering what the hell is happening for hours, and as soon as I posted my question I realized the problem.

golden elk
#

for future crashes, I do recommend checking the editor log though, vs just trying to figure it out

#

usually there will be a stack trace of some kind in there

frail seal
#

Well, Dots errors are often pretty unhelpful. At least in my experience. And yes, I also kinda forgot that logs are stored as a separate file.

golden elk
#

also turning on all the safety checks and stuff

frail seal
#

I have also another issue

gusty comet
#

Can I not change a value in a buffer without rebuilding it?
When doing:
activeBuffer[playerIndex.index].value = 1;
I get
Cannot modify the return value of 'DynamicBuffer<ActiveGrid_Buffer>.this[int]' because it is not a variable

frail seal
#

When I stop the game, my entity debugger GUI breaks and my console is spammed with these errors

storm ravine
#

First what you should to do when you got crash - disable Burst, usually it crashes only with burst, with disabled burst compilation you'll see clear errors.

#

When I stop the game, my entity debugger GUI breaks and my console is spammed with these errors
@frail seal yep it's known