#archived-dots

1 messages Β· Page 197 of 1

gusty comet
#

and also BufferFromEntity

#

whats the diff?

ocean tundra
#

on what object?

gusty comet
#

I guess its a member of SystemBase

ocean tundra
#

honestly im not sure

#

i think GetBuffer can get rewritten by the code gen

#

so safer to use

#

Oooo docs have updated

#

yea use GetBuffer

gusty comet
#

alright cool thanks

zenith wyvern
#

Keep in mind with GetBuffer you can't specify your access as readonly

#

You need to manually pass in a BufferFromEntity for that

gusty comet
#

What would you need a readonly buffer for?

#

will the job system complain even if you don't write to it?

zenith wyvern
#

Like any component how you access it in a job determines the scheduler's ability to parallelize your jobs

#

Plus if you wanted to access a buffer that isn't in your query inside a parallel job in the first place, the safety system will complain if it's not read-only

ocean tundra
#

Oooo theres a Timeline dots package

#

0 docs πŸ˜›

safe lintel
#

theres samples tho πŸ™‚

ocean tundra
#

Ooo fun

#

unfortuantully all their curve stuff is blobs which are read only 😦

#

so im wanting to stream out data (replay info) as it gets old
I have a dynamic buffer per type im recording which is the keyframe info that builds up as the game goes on
So far i havnt seen anything in DOTS that would help with this

My current thoughts are to write it into a native stream as it gets old and use a long lived Thread to handle writing it to files
Any ideas on this?
Can I use native collections in old Threads?

gusty comet
zenith wyvern
#

var bfe = GetBufferFromEntity<ABuffer>(true); // <-- Bool specifies read-only

#

Pass that into the job

#

And use WithReadOnly(bfe)

honest plinth
#

The most common reason is you want to run some rendering code at a specific point in the rendering pipeline. A place your code is not executed. So you record a (rendering) command buffer and attach it to that point of execution. That was the way to extend the built in pipeline, and scriptable render pipelines are built the same way, making it possible to interweave C# driven rendering code with C++ work without jumping back and forth between and doing callbacks

#

Not very DOTS related though πŸ˜‰

warped fog
#

So... voodoo. That's all you had to say. Voodoo.

gusty comet
#

@zenith wyvern worked thanks.

safe lintel
#

whats the difference between math.select and just using a ternary operator?

warped coral
#

am i doing this right? how come i cant use the allocatestring with using (BlobBuilder)? it makes me manually dispose [Serializable] public struct RoomInfo { public string Name; public string Description; public BlobAssetReference<RoomInfoBlob> ToBlob() { BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp); ref RoomInfoBlob roomInfo = ref blobBuilder.ConstructRoot<RoomInfoBlob>(); blobBuilder.AllocateString(ref roomInfo.Name, Name); blobBuilder.AllocateString(ref roomInfo.Description, Description); BlobAssetReference<RoomInfoBlob> blob = blobBuilder.CreateBlobAssetReference<RoomInfoBlob>(Allocator.Persistent); blobBuilder.Dispose(); return blob; } }

half jay
#

im not sure but i have random crashes on android and in systems which Run on main thread with EntityManager so potential there are no errors should be

#

is it legal to use async in systems?

ocean tundra
#

probs the async method

half jay
#

yes im not sure about this too but can't find info to confirm of usage async methods

ocean tundra
#

i would expect async to not be supported

half jay
ocean tundra
#

yea but that could easyly be a async issue

#

cause it works 'sometimes'

acoustic spire
#

Probably silly question. If data components are pure data then where am I supposed to store methods for that data? Extension methods?

ocean tundra
#

as sometimes its faster, or slower

#

wait the crashes are in other systems?

#

@acoustic spire what sort of methods?? your mainly writing your methods in systems as ForEach's

acoustic spire
ocean tundra
#

weirdly i dont really have many of those

#

the few i did i made into a normal static method

#

but im not sure thats correct

#

@half jay If you remove that system do you still get the random crashes?
Maybe do more testing and see if you can narrow down exacly what system is causing issues

acoustic spire
#

yea, static method is the most obvious way. however, it's not so good for code organizing

half jay
ocean tundra
#

then its probably not that code πŸ˜›

#

i would replace the async at some point, as it seems risky to me

half jay
#

one of the crashes

#

and how there can be an error if query exists

karmic basin
karmic basin
ocean tundra
#

@half jay I didnt think you could WithBurst entity manager stuff?

#

I would change that whole system to use a command buffer

#

then you can definitly burst

#

and use schedule

half jay
#

ye im testing this without Burst. But log with crash that im show above one of the cases.

ocean tundra
#

singleton?? only 1?

half jay
ocean tundra
#

will there only ever be one?

half jay
#

yes

ocean tundra
#

then delete all the system stuff

#

no point really for 1 entity create step

#

sorry not delete sysem, delete the foreach

#

and use the singleton entity manager methods to get to the data

half jay
ocean tundra
#

a manual entityquery.tonattivearray.first??

half jay
#

and singleton entity really shoudn't break there anything or im mistaken?

half jay
#

same crash

ocean tundra
#

weird...

half jay
#

yes

ocean tundra
#

definitly that system?

half jay
#

yes

zenith wyvern
#

Please use code tags for posting code

#

I don't see anything wrong with it, I can only assume it's from some interaction between that system and something else in your game

ocean tundra
#

it has a bunch of removecomponent log messages...

pliant pike
#

I'm confused for some reason before I destroy an entity after a job I have to create a sync point is that normal πŸ˜•

ocean tundra
#

maybe post of components as well?

#

@pliant pike use a command buffer

pliant pike
#
this.CompleteDependency();

        if (HasSingleton<FindNeighborCellEvent>())
        {
            
            var tempevent = GetSingletonEntity<FindNeighborCellEvent>();
            EntityManager.DestroyEntity(tempevent);
            //Debug.Log("It's not destroying the entity for some reason");
        }```
zenith wyvern
pliant pike
#

its outside the job so I dont think that applies

#

yeah if I don't use this.CompleteDependency(); then I either get a compiler error or it doesn't destroy the entity at all

zenith wyvern
#

What compiler error?

#

Although even if there was no error, by destroying an entity on the main thread you're forcing a structural change so it's going to cause a sync point anyways

pliant pike
#

The previously scheduled job FindNeighbourSystem:FindNeigbourCell writes to the BufferTypeHandle<FlowfieldNeigborEntities> FindNeigbourCell.JobData._lambdaParameterValueProviders.forParameter_flowbuff._typeHandle. You must call JobHandle.Complete() on the job FindNeighbourSystem:FindNeigbourCell, before you can deallocate the BufferTypeHandle<FlowfieldNeigborEntities> safely.

zenith wyvern
#

Meaning effectively it would force your job to complete immediately anyways

ocean tundra
#

use a command buffer from the job

pliant pike
#

yeah I know destroy an entity creates it's own sync point but its just weird that it requires the job to complete before allowing it to destroy a completely unrelated entity

ocean tundra
#

everything will be happy then

rancid geode
#

@pliant pike doesn't seems to have anything to do with the destroy πŸ€”

#

mind sharing more code?

zenith wyvern
#

I'm not sure but to me it feels like you might be accessing that NeighbourEntities component/buffer on the main thread somewhere else

#

By forcing a sync point immediately after scheduling a job that accesses it you're just by coincidence triggering some dependency issue with how it's trying to schedule your jobs

pliant pike
#
Entities.WithName("FindNeigbourCell").ForEach((DynamicBuffer<FlowfieldNeigborEntities> flowbuff, in FlowFieldData fluffydata, in CellData tempcelldata) =>
        {
            //NativeList<int2> tempint2list = new NativeList<int2>(Allocator.Temp);
            FixedList64<int2> tempint2list = new FixedList64<int2>();
            //NativeArray<int2> tempint2list = new NativeArray<int2>(4, Allocator.Temp);
           tempNeigbourindices.Execute(tempcelldata.gridIndex, fluffydata.gridSize, ref tempint2list);

            for (int i = 0; i < tempint2list.Length; i++)
            {
                flowbuff.Add(tempint2list[i]);
            }
            //tempint2list.Dispose();
        }).ScheduleParallel();```
#

that's the job just above the code I already posted

safe lintel
#

@karmic basin wouldnt slapping burstcompile on a job that contains a ternary do the same thing?

rancid geode
#

I mean, the entire OnUpdate functions would be better

zenith wyvern
#

Not just in that system, anywhere

pliant pike
#

I don't think so πŸ˜•

ocean tundra
#

@safe lintel I belive the math.*** functions have some extra magic when it comes to burst

pliant pike
#

I haven't forced the order of the systems though

zenith wyvern
#

Well it sounds to me like what I was hitting when I was getitng buffers on the main thread to pass into other jobs. It created very annoying and hard to track dependency errors

#

I fixed it by never accessing a buffer on the main thread

#

Outside of a ForEach at least

pliant pike
#

the only other place its mentioned is where I create it

safe lintel
#

@ocean tundra hmm, it didnt have a math.select for quaternions/float4x4 πŸ€·β€β™‚οΈ

rancid geode
#

does your singleton entity with FindNeighborCellEvent happens to be the same one that have the DynamicBuffer<FlowfieldNeigborEntities> on it?

ocean tundra
#

the magic of the math class... maybe not everything exists

pliant pike
#

nope its a single entity with just that componentdata

#

maybe its just because systems at the beginning are running in the wrong order

#

although it should just run when that singleton entity exists

karmic basin
#

@safe lintel @ocean tundra yeah it has a directive to optimize the SIMD instructions. I guess the compiler does a not so great job on its own with a ternary

pliant pike
#

it does it in another job as well, it seems like it doesn't like structural changes after the jobs

zenith wyvern
#

I will say if forcing your job to immediately complete fixes the error - that's fine. Like I said it's going to happen anyways since you're causing a structural change

pliant pike
#

I've tried destroying the entity before the job and that seems to have fixed it

#

that's probably the better place

zenith wyvern
#

I mean the real best solution is what Roycon suggested, use a command buffer. Unless you have a good reason not to

#

Putting a structural change in the middle of your update loop should be avoided if possible

pliant pike
#

you can use commandbuffers outside a job

zenith wyvern
#

Yeah

pliant pike
#

is there some trick to finding jobs in the profiler?

#

according to the profiler the above job is only run once before all the entities are created and yet somehow it still fills in all the correct values

#

also Bursted jobs appear and disappear seemingly at random from the profiler

ocean tundra
#

not sure

#

you can give a job a name

#

.WithName

#

that might help

pliant pike
#

yeah it might help if I didn't forget I'd already made a similar named system leahF

ocean tundra
#

whats the way of using prefabs now?

#

especially with subscenes?

safe lintel
#

i dont think its changed

ocean tundra
#

πŸ˜›

#

so whats the old way?

#

cause subscenes is all about the actual entities right? not prefabs?

#

oh the updated docs have a bit on prefabs

safe lintel
#

well subscenes mostly preconverting stuff so no need to do it on the start of the game/scene etc

ocean tundra
#

Looks like i should have a IConvet that has a list of all my prefabs, and that will call DeclareReferencedPrefab

#

that way they will all end up in the subscene

safe lintel
#

though doesnt have to be in a subscene(if you slap a convertotentity on it)

ocean tundra
#

i read somewhere that convertotentity is on the way out

#

will be removed in a future version

safe lintel
#

yeah but that future could be a long way away πŸ₯²

ocean tundra
#

so def dont want to rely on it

#

i know πŸ˜›

#

i heard about it being removed like last year

safe lintel
#

i dunno, all you gotta do to update something with convert to entity(assuming one day it vanishes) is move it to a subscene, boom done πŸ˜‰

ocean tundra
#

it seems this whole subscenes and conversion flow is where unity is investing their time in, so eventually it should be good to go πŸ˜›

#

true

safe lintel
#

anyway there are issues with subscenes and uitoolkit and some other people have other probs so just saying it can be temporarily avoided if you also have issues with em

ocean tundra
#

convert to entity is runtime tho?

safe lintel
#

yes, like start, should happen just once at the beginning

ocean tundra
#

ill probably just try to make it work with subscenes

#

untill i run into issues

#

πŸ˜›

#

it would be good to be able to assign unique Ids to the prefabs all in the editor

zenith wyvern
#

I mean they still use ConvertToEntity with the new dots editor that is being actively worked on

#

I don't think it's going away any time soon

ocean tundra
#

yea probably not

light mason
#

Wondering if someone could help me with a project tiny question

#

Seems like my webGL build fails when using IConverGameObjectToEntity ?

#

Can I not sure that interface ?

acoustic spire
zenith wyvern
light mason
#

Ah

#

Let me try that

#

@zenith wyvern

#

Do you have your root assembly in script and then move authoring above it ?

zenith wyvern
#

Sorry I don't understand the question. Your root assemblies exist alongside your scripts. You need your authoring scripts in their own folder with their own assembly that isn't included in the root assembly that gets referenced by your build configuration

light mason
#

Ok let me try thank you

gusty comet
#

What could be causing Entity Doesn't exist exception in this code? It doesn't tell me where its happening at unfortunately :(.

private void SpawnPeds()
    {
        if (pedCount >= 40)
            return;
        var archeType = pedArchetype;
        BufferFromEntity<Node> buffer = GetBufferFromEntity<Node>(true);
        var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter();

        var peds = pedCount;
        Entities.WithReadOnly(buffer).ForEach((Entity entity, int entityInQueryIndex, ref Path path) =>
        {
            
            var rand = Unity.Mathematics.Random.CreateFromIndex((uint)entityInQueryIndex);
            foreach (var node in buffer[entity])
            {
                if (peds >= 40)
                    break;

                int next = (node.index >= buffer[entity].Length - 1) ? 0 : node.index + 1;
                int prev = (node.index >= 1) ? node.index - 1 : 0;
                var pos = math.lerp(node.position, buffer[entity][next].position, rand.NextFloat(0, 1));

                var e = commandBuffer.CreateEntity(entityInQueryIndex);
                commandBuffer.AddComponent(entityInQueryIndex, e, new Coord() { position = pos });
                commandBuffer.AddComponent(entityInQueryIndex, e, new Ped() { nodeIndex = node.index, needsNewDestination = 1 });
                commandBuffer.AddComponent(entityInQueryIndex, e, new NeedsCompanion());

            }
        }).ScheduleParallel();

    }


    private void SpawnCompanions()
    {

        Entities.WithStructuralChanges().WithAll<NeedsCompanion, Ped>().ForEach((Entity entity, int entityInQueryIndex, ref Coord coord) =>
         {
             var agent = GetPedModel();
             agent.transform.position = coord.position;
             
             EntityManager.RemoveComponent<NeedsCompanion>(entity);
             EntityManager.AddComponentObject(entity,agent);
             pedCount++;
         }).WithoutBurst().Run();
    }


#

protected override void OnUpdate()
    {
        SpawnPeds();
        barrier.AddJobHandleForProducer(Dependency);
        SpawnCompanions();
}
coarse turtle
#

In your lambda, you are only querying for entities that have the Path component

#

So when you write foreach (var node in buffer[entity]) <- Are you sure that all entities with Path component have a Node buffer?

#

Also you can't use foreach statements in jobs because they rely on try catch. I don't think Unity has support for try catch statements in Jobs.

gusty comet
#

Yes they do

#

and

#

i ll try with for loop now

#

but all path entities have a node buffer

coarse turtle
#

You can access DynamicBuffers like so to: Entities.ForEach((DynamicBuffer<Node> nodes, ref Path path) => {})

ocean tundra
#

change the foreach to a for loop

coarse turtle
#

then the query will be all entities with <Path> & <Node>

ocean tundra
#

yea i was about to say that πŸ˜›

#

much easier when its part of the foreach

gusty comet
#

awesome thanks guys!

ocean tundra
#

also i dont see you adding a dependancy for that command buffer

#

is it a built in one?

#

oh its in that last bit of code πŸ˜›

gusty comet
#

Well that got rid of the error but i am having the weirdest issue, I think might be a race condition

#
var pos = math.lerp(node.position, buffer[entity][next].position, rand.NextFloat(0, 1));

the entity is set to this position

#

then I create a gameobject to mirror its position

#

and its not going to the same spot

#
private void SpawnCompanions()
    {

        Entities.WithStructuralChanges().WithAll<NeedsCompanion, Ped>().ForEach((Entity entity, int entityInQueryIndex, ref Coord coord) =>
         {
             var agent = GetPedModel();
             agent.transform.position = coord.position;
             
             EntityManager.RemoveComponent<NeedsCompanion>(entity);
             EntityManager.AddComponentObject(entity,agent);
             pedCount++;
         }).WithoutBurst().Run();
    }
ocean tundra
#

that would randomly position it between those 2 pos?

gusty comet
#

Thats what its supposed to do

#

but

#

there aree four nodes

#

and it only spawns at 1 of them

#

and

#

the value of the companion gameobject

#

is being set to something random its not setting it t o the value that ped is being set to in the parralel job

ocean tundra
#

check the entity inspector

#

is it creating all the enitities it should?

#

do they have the right position in the entity inspoector?

#

cause that SpawnCompanions bit is the part that looks odd to me

#

first bit looks right but may keep spawning forever as i dont see you removing Path

#

the SpawnCompanions part tho, looks like it will loop over all peds that have needsCompanion and attach them all to the same entity/agent

gusty comet
#

@ocean tundra

    private NavMeshAgent GetPedModel()
    {
        return GameObject.CreatePrimitive(PrimitiveType.Cube).AddComponent<NavMeshAgent>();
    }

#

its not the same agent

ocean tundra
#

so you should have a cube at every path point??

gusty comet
#

That is what I am attempting

#

but its just putting them all at every point in index 0 of the buffer

ocean tundra
#

so its actually spawning them all?

#

and youve confirmed the entitys in the entity inspector are correct?

gusty comet
#

They have the right ocmponents and stuff

#

but you can't see the values

#

or im just dumb

#

how do I see the values of entities components in entity debugger

ocean tundra
#

change the foreach to a for and use the for index not node.index

#

ummm they just show...

#

show your node component code

gusty comet
#
public struct Node : IBufferElementData
{
    public int index;
    public float3 position;
}
ocean tundra
#

yea thats fine

#

your node should look like child in that pic

#

after you have selected your entity

gusty comet
#

ah I had the inspector hidden

#

ok one sec gotta restart unity

#

the values are correct

#

the cubes are spawning at this position though

#

Vector3(58.3333359,0.691762924,31.5)

#

Vector3(58.3333359,0.691762924,28.3)

#

current code

#
 private void SpawnPeds()
    {
        if (pedCount >= 40)
            return;
        var archeType = pedArchetype;
        
        var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter();

        var peds = pedCount;
        Entities.ForEach((Entity entity, int entityInQueryIndex, DynamicBuffer < Node > buffer, ref Path path) =>
        {
            
            var rand = Unity.Mathematics.Random.CreateFromIndex((uint)entityInQueryIndex);

            for (int i = 0; i < buffer.Length; i++)
            {
                var node = buffer[i];
                int next = (i >= buffer.Length - 1) ? 0 : node.index + 1;
                int prev = (i >= 1) ? node.index - 1 : 0;
                var pos = math.lerp(node.position, buffer[next].position, rand.NextFloat(0, 1));
                Debug.Log(pos.ToString());
                var e = commandBuffer.CreateEntity(entityInQueryIndex);
                commandBuffer.AddComponent(entityInQueryIndex, e, new Coord() { position = pos });
                commandBuffer.AddComponent(entityInQueryIndex, e, new Ped() { nodeIndex = i, needsNewDestination = 1 });
                commandBuffer.AddComponent(entityInQueryIndex, e, new NeedsCompanion());

            }
        }).ScheduleParallel();

    }


    private void SpawnCompanions()
    {

        Entities.WithStructuralChanges().WithAll<NeedsCompanion, Ped>().ForEach((Entity entity, int entityInQueryIndex, ref Coord coord) =>
         {
             var agent = GetPedModel();
             agent.transform.position = coord.position;
           
             EntityManager.RemoveComponent<NeedsCompanion>(entity);
             EntityManager.AddComponentObject(entity,agent);
             pedCount++;
         }).WithoutBurst().Run();
    }
ocean tundra
#

change node.index to i

#

you can probs delete it

#

also you dont use prev

gusty comet
#

im going to

zenith wyvern
#

Maybe I'm blind but it doesn't actually look like you're using that rand

gusty comet
#

just not yet

#

@zenith wyvern ```
var pos = math.lerp(node.position, buffer[next].position, rand.NextFloat(0, 1));

ocean tundra
#

ok what about the enitities the command buffer is spawning

#

in the enitiy inspector

#

as that code looks ok

gusty comet
#

They are good

#

the cubes are spawning at this position though
Vector3(58.3333359,0.691762924,31.5)
Vector3(58.3333359,0.691762924,28.3)

#

and

#

i removed node.index

#

replaced it with i

ocean tundra
#

in SpawnCompanions print out coord position

#

and do you have any other systems messing with coord?

gusty comet
#

no

opaque escarp
#

anyone know if DOTS Animation is supposed to allow for retargeting animations in any capacity?

#

I tried manually constructing a rig using the rig authoring, but it doesn't seem to like the different bone positions

gusty comet
#

@ocean tundra The position its printing in SpawnCompanions is fine.

ocean tundra
#

@gusty comet wtf

#

what about another system that runs AFTER SpawnCompanions that messes with the component object

gusty comet
#

nope

#

this has to be a race condition no?

ocean tundra
#

how?? nothings racing

gusty comet
#

idk

#

hows it putting the cube at a random position

#

nothing moving it

#

The place its spawning isn't even anywhere near any of the nodes on the path either

ocean tundra
#

step 1 frame 1 you schedule spawn peds... frame 1 then ends frame 2 your scehding spawn peds again, and then SpawnCompanions would run

#

whats stopping spawnPeds from running again and again?

#

that should be spawning millions of entities

gusty comet
#
        if (pedCount >= 40)
            return;
#

its only spawning 40

#

That check is in spawnpeds job

#

then i increase ped count each time it spawns a cube in spawncompanion

ocean tundra
#

even if it spawns crazy numbers it should be ok

gusty comet
#

hmm

#

if i pause the editor

#

and then press play

#

and go through frame by frame

#

they spawn at the correct position

#

then teleport randomly later

ocean tundra
#

πŸ˜›

#

you must have anouther system

gusty comet
#

i don't 😦

#

I had one

#

but i deleted it

#

i wonder if

#

its still accessing it somehow

#

let me

#

delete solution

#

let unity recreate it

ocean tundra
#

check the systems window

gusty comet
#

ok

#

unity thinks the system is still there

#

but its not doing anything

ocean tundra
#

πŸ˜›

#

find that code and delete it

#

must still be there somewhere

gusty comet
#

I deleted that code like 2 hours ago xd

#

let me delete solution and relaunch unity

ocean tundra
#

check the files too

gusty comet
#

Ah yup

#

it was there in windows explorer

#

but not in the project window

ocean tundra
#

πŸ˜›

#

yay hopfully that solves it

#

@ me if it dosnt

#

i have to leave shortly

gusty comet
#

Yeah its still doing the same thing @ocean tundra

#

that didn't fix it

gusty comet
#

Ok i fixed it

#

Not sure how I fixed it

#

I changed like 4 things and now its working xd

zenith wyvern
#

Are you using subscenes by chance?

gusty comet
#

I am not

#

can each entity only have one buffer?

#

or can you create multiple buffers?

#

of different types

zenith wyvern
#

One per type, you can have multiple types

warped coral
#

how do i declare referenced assets? it says i can't do it in uh.. IConvertGameObjectToEntity and the IDeclareReferencedPrefabs is for gameobjects only. I wanna declare scriptable objects as referenced assets if possible

#

nvm i think i have to make a system for it

zenith wyvern
#

conversionSystem.DeclareAssetDependency

gusty comet
#

Its actually a joke how hard it is to get reliable "random" numbers using dots.

#

I've never had an issue with rng producing the same numbers before using it.

#

If you only have one entity of a certain type CreateFromIndex isn't usable, and

#

idk how you'd go about getting a seed for Unity.Mathematics.Random in a job

#

i would use time but its going to be so close every loop that it wont make a diff

zenith wyvern
#

Using extensions methods can make it pretty clean

#

Gives you a single seed point and you always have good distribution since you're reusing the same RNG

gusty comet
#

haha thats crazy

#

that you have to do it that way

zenith wyvern
#

I mean RNG is just a struct. So you could just attach it to a singleton entity in a component if you wanted to

#

I guess you would still have to get it on the main thread and pass it in though so I guess that wouldn't make it any more convenient than what he's already doing in that article

gusty comet
#

@zenith wyvern I think I am just going to pass the applications mem usage as the seed for unity.mathematics.random

zenith wyvern
#

You mean inside the foreach?

#

No matter what you do if you're not re-using the same rng you're just not going to see good distribution, afaik

#

But I'm no expert on the subject

ocean tundra
#

Whats a OrderVersionFilter ? it exists on Entity Query SetOrderVersionFilter ?

#

Filters out entities in chunks for which no structural changes have occurred.

zenith wyvern
#

Sounds like ChangeFilter but explicitly for structural changes

ocean tundra
#

so change filter will fire when a component is added or the id has changed??

zenith wyvern
#

Whenever a component is accessed as read/write. Including when it's created

ocean tundra
#

sweet

zenith wyvern
#

On a per-chunk level, mind you

gusty comet
#

Hmm whats an example use case of that lol

ocean tundra
#

how come Dependancy still isnt public on System?

#

am i making a mistake by making it public and using it?

zenith wyvern
#

It's used by the framework to handle dependencies between systems. The physics systems expose it to be able to force other systems to run before or after them

#

I think it should be fine as long as you don't try to write over it between updates

ocean tundra
#

Yea i have a system that builds up a nice unique list of ids that i need to access, to make that safe i need the write job dependancy

#

no ill never write to it

#

only use it to combine dependancies in another system

zenith wyvern
# gusty comet Hmm whats an example use case of that lol

My roguelike is turn based, so if the game is waiting for player input there's no reason for any systems to be running. I use change filters for that purpose, so my render system doesn't update until something in the game changes

#

In my case rendering a new game state involves rebuilding a mesh so there's a good reason to minimize it as much as possible

gusty comet
#

@zenith wyvern even the article you linkeds way is still always producing 0

#
Entities.WithNativeDisableParallelForRestriction(randomArray).ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex,DynamicBuffer < Node > buffer, ref Path path) =>
        {
            
           



                int val = randomArray[nativeThreadIndex].NextInt(0,1);
                Debug.Log(val.ToString());
}
#

I feel like the probleem is

#

I only have 1 path entity spawned

#

so nativethreadindex

#

is the same always

zenith wyvern
#

It's not inclusive

#

If you want 0-1 you need to put 0-2 in the range

#

And don't forget to assign back to the array

gusty comet
#

Still just produces 0

zenith wyvern
#

Remember it's a struct so you need to manually write it back to the array after you use it

ocean tundra
#

var rnd = randomArray[nativeThreadIndex]
//use rnd
randomArray[nativeThreadIndex] = rnd

gusty comet
#

ah

#

i see

#

sec

#

That worked

#

awesome!

#

thank you!

#

@zenith wyvern is NextFloat inclusive?

zenith wyvern
#

Not sure, I think so. It would be weird if it wasn't given how floats work

gusty comet
#

Lmao its odd to me that NextInt isn't inclusive but nextfloat is

#

yep

#

it is inclusive

zenith wyvern
#

UnityEngine.Random.Range is the same way

#

The way I always think of it is that if you pass in the length of an array as the second number you won't get an out of range exception

gusty comet
#

lmao I been passing length of array - 1

#

rip me

#

time to fix a ton of bugs

#

in a ton of diff projects

zenith wyvern
#

Hahah

gusty comet
#

I never noticed that the second value is exclusive in unityengine.random.range

zenith wyvern
#

Yeah I was confused by it a lot too for a while. The array thing always helps me remember

#

And for floats, it just doesn't make sense for it to be exclusive. What's "-1" for a float? Could be anything

gusty comet
#

So do I need to regenerate randomArray every now and then or will it be fine?

zenith wyvern
#

You should be fine to use it for the whole game

gusty comet
#

Alright also

#

do I need to do randomArray[nativeThreadIndex] = rnd

#

every time i use it

#

or just once after I use it 3 times

zenith wyvern
#

You need to do it before it leaves scope

gusty comet
#

ok

#

so

Use
Use
Use
Set

#

thats fine?

#

assuming all of that is in same scope

zenith wyvern
#

As long as you're not using it directly from the array yeah. Assign it to a local variable first like Roy showed, then assign that back to the array at the end

gusty comet
#

alright awesome

#

You guys are both legends

#

Also that blogged you linked

#

is a goldmine

#

I was looking at it earlier for how to spawn entities

zenith wyvern
#

Yeah he knows what he's doing for sure

gusty comet
#

so

#

are operations like buffer.toNativeArray slow?

zenith wyvern
#

ToNativeArray is a copy, so slower than the alternative AsNativeArray, which just gives "less safe" access to the underlying data

gusty comet
#

Would it be a bad idea to take do something like

#

var arr = Array.Sort(buffer.AsNativeArray());
then read the data from the array?

#

or even

#

arr = Array.sor....
buffer = buffer.FromArray(arr);

zenith wyvern
#

Well Array.Sort is for managed arrays. There are native array extension functions for sorting that should work

#

Not sure though

gusty comet
#

Array.Sort works fine on native arrays

zenith wyvern
#

You would be sorting the actual buffer though so as long as that doesn't mess you up anywhere else I tihnk it's fine

gusty comet
#

just wondering if it would break something internally

zenith wyvern
#

I don't think so. You can write to the arrays you get from AsNativeArray without any issues, so I can't imagine a sort would do anything harmful

gusty comet
#

Thats fucking awesome.

ocean tundra
#

yea i used to sort dynamic buffers by using as native array

#

you can even limit the sort to only run on X items

gusty comet
#

how?

#

this is how i am sorting now

#
public struct DistanceComparer : IComparer<Node>
{
    float3 value;
    public DistanceComparer(float3 distanceToTarget)
    {
        value = distanceToTarget;
    }
    public int Compare(Node a, Node b)
    {
        var targetPosition = value;
        return math.distance(a.position,targetPosition).CompareTo(math.distance(b.position, targetPosition));
    }
}


var pos = Camera.main.transform.position;
        Entities.WithAll<Path>().ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, DynamicBuffer<Node> buffer) =>
        {
            buffer.AsNativeArray().Sort(new DistanceComparer(pos));
        }).ScheduleParallel();
zenith wyvern
#

Looks fine to me. Assuming you're passing that buffer as Ref

ocean tundra
#

acutally im not sure how to only sort X items

#

was pretty sure it existed

zenith wyvern
#

NativeSlice maybe?

ocean tundra
#

yea thats what i was just thinking

zenith wyvern
#

I don't think you can use that in jobs though

ocean tundra
#

i think i must have sliced the bit i wanted and sorted that

zenith wyvern
#

Unless I'm remembering wrong

ocean tundra
#

yea i have no idea either

#

was sure there was a easy way

ocean tundra
#

When you use Job.WithCode..... and Schedule it wont parallel it right?

#

like only 1 job with that code runs?

zenith wyvern
#

Yeah it runs on one job on a single thread

gusty comet
#

Why is this job causing InvalidOperationException: The BufferTypeHandle<Node> has been declared as [WriteOnly] in the job, but you are reading from it.

#
    private void SortPeds()
    {
        var pos = Camera.main.transform.position;
        Entities.WithAll<Path>().ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref DynamicBuffer<Node> buffer) =>
        {
            var arr = buffer.AsNativeArray();
            arr.Sort(new DistanceComparer(pos));
            buffer.CopyFrom(arr);
        }).ScheduleParallel();
    }
zenith wyvern
#

I'm not sure but buffer.CopyFrom(arr); Doesn't make sense. arr is the buffer

#

They both point to the same data

gusty comet
#

it copies arr into buffer

zenith wyvern
#

it copies buffer into buffer

#

That's essentially what you just said

gusty comet
#

yes but don't I have to since buffer is a struct?

zenith wyvern
#

No, if you were reading an element out of the array at some index, and changing that element, then you would have to write it back to that same index. But you're changing the array itself

gusty comet
#

Ok fixed

#

lets see if it stops the exception

#

it did

#

thanks!

#

AsNativeArray doesn't take count into consideration and my loop was reading default(Node)

#

just something to note in case you ever run into some weird bug with it

ocean tundra
#

Native Stream, Does every AsWriter... BeginForEachIndex also need a AsReader BeginForEachIndex?
I'm getting : BeginForEachIndex can only be called once for the same index (0). errors

zenith wyvern
#

Yeah, I think essentially it's saying that when you read with BeginForEach then the contents for that index are annihilated as soon as you end reading

#

That's my guess anyways

gusty comet
#

Any good ideas on how to even disperse entities in an area around a vector?

#

right now I am just sorting an array of points then looping through it until I spawn the max amount

#

this is causing the entities to have less than desired spawn points

ocean tundra
#

ok cool

#

i think

#

i dont have a read yet

#

still wip

zenith wyvern
#

When that happened to me I ran a second "UnstickFromWalls" system that runs after spawning. It had better awareness of the map so could make better decisions on how to place entities

ocean tundra
#

so that would explain the error, im not reading so never resetting that index

gusty comet
zenith wyvern
#

If you're using random correctly it should be evenly distributed across an entire area

#

At least from what I've seen

gusty comet
#

well its random

#

sometimes that is true

#

sometiems rng doesn't work out

#

and more 3's than 2's generate

#

and then you have more entities in one area

half jay
#

Can i write system like this With burst and structural changes ?

  Entities
  .WithStructuralChanges()
  .WithBurst()
  .ForEach((Entity e, in RayHitComponent hit,in CalculateHitComponentSingleton comp, in SelectBlockInputComponent selectedBlock) =>
   {
       var requestEntity = EntityManager.CreateEntity();
       EntityManager.AddComponentData(requestEntity, new BlockPipelineTag());
       EntityManager.AddComponentData(requestEntity, new GhostTag{IsGhost = true});
       EntityManager.AddComponentData(requestEntity,new AddObjectPlanComponent{Id = selectedBlock.BlockId,Matrix = comp.CurrentLocalMatrixInGrid});//TODO should set from SelectBlock component
       EntityManager.AddComponentData(e, new SelectedObjectComponent{Id =  selectedBlock.BlockId});                    
       EntityManager.RemoveComponent<SelectBlockInputComponent>(e);

       Debug.Log("SelectBlockUserActionSystem");
   })
   .Run();

Im getting no error or something but want make sure that this is legal

gusty comet
#

I was under the impression you can't use burst on the main thread

#

but i could be wrong

zenith wyvern
#

You can use burst on the main thread, but WithBurst and WithStructuralChanges are mutually exclusive

half jay
#

i modify example. to be clear how my system look like

half jay
zenith wyvern
#

If it works then it means that it's just silently disabling burst. You can't use the entity manager in bursted or non-main-thread jobs

#

You should be able to see for yourself in the menu ->Dots->Dots Compiler->Open Inspector

ocean tundra
#

dam i wish we could attach native containers to entities

zenith wyvern
#

What's wrong with dynamic buffers

ocean tundra
#

I neeed native streams

zenith wyvern
#

Oh like non array containers

#

Yeah it would be awesome

ocean tundra
#

yea basicly just want to produce/consume messages

half jay
zenith wyvern
#

Yes

gusty comet
#

would this be too much work for a component system?

-Update
--Calculate viewport on main thread;
--list of used spawnpoint indexes
--Entities.Foreach through all possible spawn points (there are a lot of these) parralel
--- if spawn point is on screen spawn entity
--- add index of spawnpoint to spawnpoint indexes list
-- if number of spawned entities is less than max entities
---Entities.Foreach through all possible spawn points (there are a lot of these) parralel
---- loop through entiteis that have already been sorted by distance and spawn them if the spawn point has not already been used
zenith wyvern
#

I'm not sure about the exact setup but you should minimize job scheduling as much as possible

#

It sounds like a lot of job scheduling in one frame

#

Unless I'm misreading

gusty comet
#

Two jobs

#

in one frame

zenith wyvern
#

Oh okay, I thought you were scheduling in a loop

#

Then yeah, it seems fine to me. Profile it though, don't make any assumptions

#

Sometimes the dumbest things you could never think of turn out to be bottlenecks

gusty comet
#

just didnt' want to waste time writing code if it was absolutely too much work for a single system

zenith wyvern
#

Burst can generally tear through thousands of entities in a fraction of a millisecond, especially in parallel jobs

#

Depending on the work being done of course

gusty comet
#

woah

#

navmesh obstacles are really expensive

#

putting a navmeshobstacle on each agent dropped my framerate by half xd

#

i might stop trying to combine ecs and built in navmesh and just make it work with navmeshquery

gusty comet
#

How do you get a query in a parralel job?

pulsar jay
#

Is there a HasSingleton equivalent for queries? There is GetSingleton like with SystemBase but no HasSingleton

rancid geode
#

CalculateEntityCount != 0 I think

amber flicker
rancid geode
#

yeah, need to check out, probably it is

pulsar jay
#

I guess thats IsEmptyIgnoreFilter now

amber flicker
pulsar jay
#

good to know. should probably update. I am still on 0.14

stiff skiff
#

Good time to upgrade πŸ˜„

warped coral
#

im converting two rooms from scriptable objects to entities, and when i look in the entity debugger, the entity field references seems off. Idk why. the entities are created fine but their Entity field references are wrong

#

am i somehow using createadditionalentity wrong

#

weird i keep doublechecking and it seems right... i also stopped it from creating entities for rooms at coordinates it's already converted... so idk

#

hmm yeah something weird is going on

#

when i reference the assets everything is fine.. only when i use createadditionalentity do things get weird

#

createadditionalentity is returning the primary entity... weird

gusty comet
#

Is it not possible to create a new entity query in Entity.Foreach().ScheduleParralel()

#

I need to get some other entities in a system already querying different ones

safe lintel
#

create your queries in OnCreate, afaik its something you dont want to be doing constantly due to the performance of it

gusty comet
#

Then it tells me I can't access unsafe pointers in entities.foreach

#
InvalidOperationException: SpawnPeds_LambdaJob0.JobData.q.__impl uses unsafe Pointers which is not allowed. Unsafe Pointers can lead to crashes and no safety against race conditions can be provided.
ocean tundra
#

@gusty comet are you saving the query into a local var in OnUpdate?

gusty comet
#

yes I am capturing

safe lintel
#

i dont think you can use a query directly in a job outside of when you are scheduling it

#

not really sure what youre trying to do though

gusty comet
#

I am looping through some entities

#

with entities.foreach

#

and I need to loop through a group of different ones

#

well not even loop through

safe lintel
#

prior to the job you can get a copy of the entities or component data with something like query.ToComponentDataArray(Allocator.whatever) || query.ToEntityArray

gusty comet
#

I need to figure out how many of the other entities exist

safe lintel
#

and then use the resulting nativearrays inside your jobs

gusty comet
#

alright thanks

celest wraith
#

relating to that: in Systembase you need to do the queries and put them in NativeArrays before Entities.ForEach correct? What if some query results may need to be had only in certain situations and others in other situation in the same ForEach? Is it possible to have some queries get results only if those certain conditions meet or do the yneed to be queried regardless if they are used or not?

gusty comet
#

Thats what I was trying to figure out

#

Don't think you can do it i n entities.foreach

#

The issue I am having now is

celest wraith
#

Ahhhh didn't get that from your writing sorry πŸ˜„

gusty comet
#

The query doesn't update till the next update cycle

#

if its changed at all

celest wraith
#

Woke up from a nap just right now and thought I'd chime in

gusty comet
#

So if you're querying to see how many things are spawned then spawn x amount if its less than a desired value

#

you wind up with extras

ocean tundra
#

you need to plan in 'frame' delays

celest wraith
#

Is the difference neglible of having 6 (or more) queries and nativearrays compared to like only 2 that are needed?

gusty comet
#

I thinnk as long as you create the queries at init and not runtime it would be fine

#

idk tho

ocean tundra
#

as the update cycle works like this:
OnUpdate, - all code runs, but any Jobs or ForEachs DONT run then (unless they are .run)
Then any Jobs/Foreachs run

celest wraith
#

For example I have a query for my characters hand position, but I only need it if I am going to spawn an item there. So if the system doesn't need to spawn there it still queries it but doesn't need it.

gusty comet
#

I think you're fine just creating the query at startup and not using it till its needed

#

could be wrong

celest wraith
#

I think so too so it shall stay that way. If it works, don't touch it πŸ˜„

#

Anyone has any experience from spawning entities from xml or json?

ocean tundra
#

@celest wraith kinda, I was loading up data json files

#

not really spawning entities tho, i would create a prefab of the data type (eg unit, building) then load in all the simple values

#

dynamic stuff was much harder, as you have to add components with its actual type, cant really use refelection or anything fancy to create the components

celest wraith
#

Can you even create a new component from a name (string) and give it value? For example in pseudocode:
String compName = *string from json*
Var xComponent = *new Component from name*

ocean tundra
#

Honestly no

#

was a pain

#

the trick was to reverse that adding of compoents

#

like this...

#

Type typeToAdd = FIND TYPE FROM JSON
typeToAdd.FIND STATIC METHOD
STATIC METHOD = (JSONDATA data, ENTITYMANAGER em, ENTITY e)
inside the static method you do entity manager add your type and set values

#

its not pure dynamic but its closeish

#

so you never dynamicly create Components

gusty comet
#

Can't you just use reflection?

ocean tundra
#

yea but not to directly create a IComponent

gusty comet
#

Activator.CreateInstance ?

ocean tundra
#

you can but the issue is with entity manager

#

what do you store the result from CreateInstance as?

gusty comet
#

it has a generic type argument

#

so if you have a Spawn component

ocean tundra
#

a object would make it a reference type and the entitymanager add component wont accept that

#

generics are a compile time thing, not runtime/refelction

gusty comet
#

CreateInstace<Spawn>

ocean tundra
#

but spawn is dynamic

#

The issue here is when you are trying to add components completly dynamicly, eg from a user list of string type names

gusty comet
#

oh

ocean tundra
#

if you have a list of X types that you allow you can just make a switch

gusty comet
#

you could make a class

#

string key
IComponentData value

#

but

ocean tundra
#

yup, but thats again just a nicer switch

gusty comet
#

then it wouldn't be dynamic to the user

ocean tundra
#

well way better then a switch

#

but same core issue, not pure dynamic

#

my goal was to allow the users to add new IComponents, eg via dynamic c# code compiling

gusty comet
#

That should be possible though no?

ocean tundra
#

yea the way i said earlier

#

you need a static method on the componet, that takes a entity manager, and the user has to code em.AddComponent<TheirType>()

gusty comet
#

this is where lua would come in handy

ocean tundra
#

maybe

#

but i think the lua bridge would be way too expensive

#

performance wise

gusty comet
#

Yeah definately, I tried to use a bridge to the pawn language in c# and it was unusable

#

I had to create the abstract machine in a c++ app then use a memory map file to perform ipc to make it at all usable

ocean tundra
#

πŸ˜›

#

that sounds crazy

gusty comet
#

I wound up abandoning that and just having the host app in c++ host a netcore dll

#

so would something like a behaviortree work good with ecs?

#

I've made thhem before but they rely so heavy on things we can't use in ecs like delegates and inheritance i don't see how it would work

ocean tundra
#

OOo thats tough

#

pure ecs i would say no

#

but you should probably hybrid it somehow

#

have your tree object graph

#

that you construct and cache

#

then run like X number per frame that needs updating

#

not every one

gusty comet
#

Might just make it so

ocean tundra
#

my initail attempt at ai was rough

#

soooo many components

#

to indicate state

gusty comet
#

yep

ocean tundra
#

however you should look at the new AI planner

#

again its very alpha

#

but its all DOTs under the hood

gusty comet
#

awesome

#

this will make life much easier

ocean tundra
#

πŸ˜›

#

one day

#

i think its current state will be a pain to use

#

looks awesome tho

gusty comet
#

Have you tried out the animation package yet btw?

ocean tundra
#

not recently

#

i tryed it liek 6 months ago

#

couldnt get it going then

gusty comet
#

I might give it a try

#

it seems super early still though

ocean tundra
#

yea

#

it looks better now

#

and theres a specific sub fourm for it

#

but i usualy just leave my units in a T pose

#

πŸ˜›

gusty comet
#

is it a bad idea to have methods in your components?

slim nebula
#

I wouldn't put too much logic into functions on your components, but if it's just like converting the data a bit for use, I think it belongs on the component.

#

anyone want to venture a guess to why my breakpoint isn't being hit?

#

(top screenshot is in "CharacterControllerInitAndCleanupSystem")

#

if I make a breakpoint on the "Entities" line it hits it. just the query never returns anything. any ideas?

#

(bottom screenshot is the entire entity, there's nothing else on it)

#

@zenith wyvern sorry to bug you again but ur so smart and helpful πŸ˜„

north bay
#

I assume you have burst disabled when trying to debug.
Entities.ForEach is known to not trigger breakpoints. In my experience it seems rather random if breakpoints inside them actually trigger

slim nebula
#

so I've assumed it's okay to have multiple entity queries in the same system. is that okay? let me check burst....

#

ok turned off burst... it runs once but doesn't actually remove the component....

#

the entity is still there... what the heccc

#

is there like a special way to remove system components?

#

or does remove component not work if the entity is in the destruction process or something?

north bay
#

Ehhh

#

It should work

#

Your ForEach looks correct to me

slim nebula
#
            Entities
                .WithNone<CharacterControllerComponentData>()
                .ForEach((Entity e, ref CharacterControllerCollider collider) =>
                {
                    collider.Collider.Dispose();
                    for (int i = 0; i < 10000; ++i)
                    {
                        ecb.RemoveComponent<CharacterControllerCollider>(e);
                    }
                }).Run();``` i got nuthin
#

it wont work

deft stump
#

@slim nebula are you sure the system is able to find your entity?

slim nebula
#

it does run once. I guess I should check the entity index/version...

#

wait no these are different entities wtf

light mason
#

Anyone have examples in tiny how to click and spawn game object. I have no idea where to start

slim nebula
#

I think I have some direction now. thanks guys

#

@light mason right click in project folder, create > input actions. Add things and generate. Create a variable of the generated type on a system. reference said variable in OnUpdate: if (InputSystem.inputMaster.Player.Use.ReadValue<float>() > 0) for example, then create an entity with EntityManager

#

I dunno if you need any special packages for it tho

warped coral
#

how to check if entity has buffer from entitymanager?

light mason
#

@slim nebula ok thanks you let me try it out

slim nebula
#

@warped coral I'm pretty sure you just use HasComponent, but you can test it to be 100% sure

warped coral
#

oh ok. i tried using hascomponentdata and didnt realize that only accepted icomponentdata

light mason
#

Do I need the new input system ?

slim nebula
#

uhh yeah I think what I"m using is the new input system. I dunno how to use the old one

#

I think in the options you need to have both enabled

#

I think there's still some backend unity junk that doesn't support the new stuff just yet

#

i forget what tho

light mason
#

Ok I will shoot from the hip and see what happens

karmic basin
#

cant have both input system enabled. Have to chose one

warped coral
#

will unity be the best engine cuz of dots

karmic basin
#

there's no absolute best engine. More like one or two that better suits your needs, and that can change with each new project.

zenith wyvern
deft stump
slim nebula
#

ohhh

#

so maybe it's throwing some exception?

zenith wyvern
#

Unity will absorb all other engines and become the Ur Engine

slim nebula
#

err well I disabled burst in the menu too

zenith wyvern
#

Hail the giga engine, well all say

deft stump
#

so unity's plan was world domination all along

zenith wyvern
#

Yeah it will probably break of you enable burst I would think

slim nebula
#

ok

#

thanks for the tip

light mason
#

Ok so tiny has Tiny.Input?

#

Whats the catch here

#

Is seem to just work

#

Wait ... does ECS have a pure dots input too?

zenith wyvern
#

No

#

Also Tiny input is kind of terrible compared to the new input system. I love tiny - or did before i hit a bug that killed my project. But the input system is just the bare minimum they could do. Which is fine, it's still early

light mason
#

All I need is click to create distort and connect

zenith wyvern
#

Also I don't think it's really ECS at all is it? You're just calling into a system

light mason
#

I’m not sure for some reason to can’t find the system file

#

Never mind was in the wrong ide

#

Ok looks like it has all I need does all the basics

#

If I author entity in the editor how do I respawed that entity archetype. I want to build the library of different antitu and have a way to create many of a certain type in a system

#

I’m not really clear on the workflow here

slim nebula
#

you create a prefab, then you drag it onto the field in the editor for your authoring component

#

then you can reference that prefab in code and instantiate it with entitymanager

light mason
#

Do you know where I can see an example

slim nebula
#

βœ… Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=pk-C_h0WJZs
Let's check out how we can build Game Object Prefabs and Convert them into Entity Prefabs that we can then Instantiate.

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

Getting Started with ECS
https:/...

β–Ά Play video
light mason
#

Ah thank you , man you guys deserve a beer or something

slim nebula
deft stump
light mason
#

In that code monkey video he used static field, I’m to so keen on that. Do I need library entity ?

zenith wyvern
#

That example is basically how I do all my authoring

light mason
#

I guess what I’m struggling with is what’s the best way to store them for later using in a system

#

Like a library of trees to spawn

zenith wyvern
#

In my game I just store the entity prefabs on a component and attach it to my map

light mason
#

I see

#

Are u don’t that in a conversionSystem

light mason
#

Ah awesome thank you going to read through this

rugged lark
#

Obligatory "I'm new here", but you typically only have one EntityManager per World, right? Can you access/render from multiple worlds at the same time? The reason I ask is that I want to make my tiles entities, because I want to play with dynamic terrain systems. It seems very foreign to have my tile "entities" lumped in with my entity "entities". I assume that is the standard solution, and then just handling it with components. I just don't expect there to be many or any overlapping systems between what will be run against the entity entities and the tile entities. Would it be beneficial or detrimental to create a second World, and a second EntityManager, to handle my tiles? Or am I an insane person.

zenith wyvern
#

I'm not sure what the benefit of having a separate world is, it seems like it would make it hard to read your terrain data from your normal world

rugged lark
#

I assumed I was overthinking it.

zenith wyvern
#

AFAIK worlds are generally meant to be completely self contained, typically the only interaction between them is to copy entities over from one to another

#

So they're good for staging entities and stuff. And netcode uses them to separate client and server logic

rugged lark
#

Thanks. The only reason I asked was because I had read something alluding to the benefit of multiple worlds in cases of rendering and netcode

#

But I'm inventing problems I don't need to solve so I'll just go do the obvious thing.

zenith wyvern
#

Using a separate world for rendering is interesting, I wouldn't know how to do it personally

rugged lark
zenith wyvern
#

Yeah but in order to render in the rendering world wouldn't you just have to copy over all your data from the sim world and re-interpret it for rendering?

rugged lark
#

You can see why I'm asking questions in here.

zenith wyvern
#

I can think of ways to do it but it's complicated (from what I know of communcating between worlds which isn't much) and I'm not sure what the gain is

rugged lark
#

Well right now it was a shiny engineering question to distract me from actually writing substantial code. And I need to start tinkering or I'm never going to learn anything.

hollow sorrel
#

@rugged lark yea you can
one benefit of using seperate world is that it has its own sync points so they don't have to wait on eachother
and if you're doing things like deterministic simulation for rollback you pretty much need seperate worlds
but other than that, most things you can do with seperate you can also do in a single world e.g. you can still use seperate 'logic' and 'render' entities in 1 world and things are a lot simpler

zenith wyvern
#

I'm just starting to mess with physics. As I understand it if I want to do an overlap test I get the CollisionWorld on the main thread, pass it in, and the overlap gives me indices in to the array of all dynamic bodies. Can I affect that list of bodies - like restrict it to a certain query of entities?

#

Using HasComponent/GetComponent/SetComponent for every entity in my overlap seems like it would be horribly slow

ocean tundra
#

so from memory physics didnt really interact right with ECS

#

it still has Layers

#

and your meant to use layers (and layer masks) to define possible collisions and pass in target layers to the physics querys

#

it dosnt use any of your component types for any querys

#

kinda sucky i think, they could remove layers and use the compoent type index instead

zenith wyvern
#

Yeah my idea would be to grab an array of my components and pass it into the overlap job. But I'm not sure how to match up the indices from the overlap into my components array

#

Even using filters I would need to use HasComponent/SetComponent which I want to avoid

ocean tundra
#

umm again all from old memory, you get back indexs to the bodys array, bodies array has a entity field somewhere

#

that will get you to the main entity

#

where you can do your own extra collision stuff

#

for me i found a collision job callback thing, that would take all collisions and turn it into a dynamic buffer

#

and i could query that buffer (with change filter) instead to handle collisions

zenith wyvern
#

This isn't for collision handling, but rather to just grab a group of entities in an area around eachother and affect velocity. It's for flow fields. And yeah I know I can get the entities from the bodies array but again I'm trying to avoid the random access if possible

ocean tundra
#

hmm i see

#

i fell like no matter what with physics your gona have random access

#

goal would be to minimise it

#

maybe get a native array of entitys (overlaps) and batch add component to them?

#

that way your next system can quickly loop over them

#

depends on if you need to work with them all together or not

zenith wyvern
#

I need to affect every single entity based on the data of N entities in an area around it. I guess I could use some kind of spatial partition container and push into that from the overlap tests to be used in the next job

#

Would still need to do radius tests per bucket but it should reduce the work

#

If I understand it correctly anyways

#

Ehh but then I still have no way to translate from the dynamic bodies array to my components array

#

Unless I just make sure there are no bodies in existence that don't relate to my overlap test so the component array would match up to the bodies array, since they would use the same query...

#

Surely all the physics lords on here have some kind of solution

ocean tundra
#

oh i really dont think the bodies array order would match your entities order

#

physics is this weird black box that kinda breaks ecs

#

i would fully expect it to do something really annoying like reorder the bodies array

zenith wyvern
#

This is the query that builds the bodies array:

            DynamicEntityGroup = GetEntityQuery(new EntityQueryDesc
            {
                All = new ComponentType[]
                {
                    typeof(PhysicsVelocity),
                    typeof(Translation),
                    typeof(Rotation)
                },
                None = new ComponentType[]
                {
                    typeof(PhysicsExclude)
                }
            });
#

From the source

#

Annoying to make my own entities match up to it but not impossible

ocean tundra
#

yea i remember messing with that

zenith wyvern
#

But yeah I guess I have no guarantee they don't shuffle it around, now that you mention it

ocean tundra
#

i hacked it to not destory parents and childen

#

it was ruining the transforms and driving me crazy

#

also excludes you from updates

#

not a big deal but still

#

so bring it back to its core

#

you have a grid?? of entities and you need to do a overlap?

zenith wyvern
#

The entities themselves aren't on any kind of grid really. That's why I was hoping to use physics for this, to avoid having to build some kind of fancy spatial partitioning system myself

ocean tundra
#

yea makes sense

zenith wyvern
#

Plus they are already physics entities so I figured why not use it if it's there already

ocean tundra
#

maybe triggers?

#

actuually i think thats just looping back to the same problem

#

:/

zenith wyvern
#

I think I'll just try it out with HasComponent/SetComponent and see how slow it is. Maybe it will surprise me

ocean tundra
#

good luck

#

sorry i couldnt help more, havnt used physics in ages

zenith wyvern
#

No worries, I appreciate the advice

zenith wyvern
#

Oh, hahah, the hit data you get back from the overlap already includes position data, so that solves the problem right there

amber flicker
stiff skiff
#

If only we could have some sort of roadmap

#

With them moving the Graphics packages into Core due to so many things relying on it. I wonder if they will be moving DOTS/Entities into core

#

Or something similar to Tiny, make it it's own "engine" entirely

amber flicker
#

pretty sure that's always been the plan - to move dots/ecs into core... I guess burst & jobs may be quite soon.. entities.. 202...5? πŸ€”

deft stump
#

if it moves into core then would classic be replaced by dots?

amber flicker
stiff skiff
#

How so? It's not like ECS is a solution for all problems, far from it

ruby frigate
#

Anyone get a feeling for what the vibe is regarding DOTS within the Unity org? AFAIK it's always been the CTO's baby, is he still as bullish as ever now that he's seen what it looks like in practice?

ruby frigate
#

thanks!

#

definitely still seems very bullish about DOTS

#

And CTO gets what CTO wants, so that's where things are gonna keep moving

#

Did the .NET Core DOTS server runtime end up happening? I'd love to use DOTS more extensively in my project, but my gameplay code has to run in the cloud for multiplayer reasons so I can't depend on the full runtime. My main gameplay assembly doesn't even link Unity .dll's at the moment.

#

Joachim mentioned ".NET Core based DOTS runtime later this year" in 2019 >_>

#

That's exactly what our game needs, and I can't find anything more recent about it.

north bay
#

Somehow the more recent versions are missing the manual idk what's up with that

ruby frigate
#

Not really. Project Tiny still includes a bunch of Unity stuff. What I'm looking for is the ability to deploy DOTS by itself in a barebones .NET Core environment.

pulsar jay
#

How do you handle VFX with DOTS atm? I have several approaches but nothing feels quite right. I think it should be systems separate from the game logic. But should those systems create and destroy converted VFX objects? And how would they know when to spawn/destroy them without such a thing as an event?

north bay
#

I'm currently using a EffectCommandBuffer that supports playing sound or creating particle systems. Those command buffers are processed by a effect system which handles pooling, etc.

When creating a sound or particle system the command buffer returns me a handle to the effect which I can later use to check if the effect is still playing or to modify other stuff related to it.

#

This has worked pretty good for me for the past year

pulsar jay
#

That sounds pretty solid. Is the EffectCommandBuffer an EntityBuffer or a custom thing you built yourself?

north bay
#

That's a custom thing

#

The logic and chaining of commands looks like the EntityCommandBuffer

#

Just with custom actions/commands

pulsar jay
#

Thats a good starting point I guess. And how do you spawn the effects from the Effect system? Is it just a system running on Main Thread spawning GameObjects or do you convert the effects to DOTS somehow?

north bay
#

The system runs on the main thread and uses standard game objects

#

I also have a really old effect system that supports VFX graphs from the FPS sample...

pulsar jay
#

sounds reasonable

#

I just took a look at the EntityCommandBuffer. Sadly its a lot more complicated that I anticipated 😬

karmic basin
#

@zenith wyvern Out of curiosity, why not a collision query or overlap query ?

zenith wyvern
#

What do you mean? I am doing an overlap query

karmic basin
#

Oh ok, I misread then

#

yeah you literally wrote it, my bad

zenith wyvern
#

No worries

karmic basin
#

My brain stopped at the part where you were looking for a spatial query

north bay
pulsar jay
#

@north bay wow thats great. Thx πŸ™‚

zenith wyvern
#

Can someone explain how the category names filters work? I assumed this would map to (Actor == 1 << 0) (Wall == 1 << 1)

#

Basically if I'm writing a filter in code for an overlap test I need to know how to match against the filter I set in the editor

#

I figured it out. I had normal monobehaviour collider components attached to my gameobjects alongside my physics shape/physics body scripts. Apparently the conversion system accounts for both of these and creates a compound collider

#

So I was getting the weird filter from conversion combining the built in gameobject layers and my own custom layers

#

Very annoying to figure out

north bay
#

I remember reading something on the physics forum about exactly that issue

zenith wyvern
#

Yeah I just posted in a forum thread I found about it, hopefully they will add a warning message or something in the inspector

karmic basin
#

If I remember well they specify it in the docs that it's a really bad idea to have both legacy & new physics stuff

#

but yeah a warning in editor would be nice

light mason
#

I’m a little stuck, I have a dynamic buffer on an entry, the buffer contains prefab entities

#

How do I Instanciate in entities for each

#

Should this not work

pliant pike
#

you can't use the EntityManager in a job, you have to use an EntityCommandBuffer

light mason
#

Sorry I had run()

#

But still no luck

#

Is says I have to use ECB in forEach ?

pliant pike
#

well if you want burst(which you do) then yeah

light mason
#

Ok let me do that , thank you

pliant pike
#

one thing you might want to check though is if instantiate inside a job is actually faster though

#

there's a slight possibility using a simple for loop may be faster(though maybe in later version now its not)

light mason
#

Really , ok thanks for the tip

#

O yea it’s faster πŸ’ͺ

warped coral
#

how to use multidimensional arrays with jobs? is there an alternative to flattening them?

light mason
#

I’m testing GetWorldInputPosition in tiny.input but it always returns 0

deft stump
light mason
#

That method is a TranslateScreenToWorls(GetInputPosition())

warped coral
#

oh ok, thanks

light mason
#

The getInputPosition is returning my screen pod

#

Pod

#

Pos

light mason
#

Wait it just returns 0 in translateToWS .. what am I missing here

robust scaffold
# warped coral how to use multidimensional arrays with jobs? is there an alternative to flatten...

You technically can. NativeArray<UnsafeList<UnsafeHashMap<int, UnsafeMultiHashMap<int, UnsafeArray<int>>>> works as unsafe arrays are implemented as a integer pointer. However, accessing this will wreck your cache access and murder performance. If you really need to and dont care about performance, you can use this. Well, not this deep of a hierarchy. I've used NativeArrays<UnsafeHashSet<int>> before in loading to get a true Multiple HashMap with unique keys (index) and values.

celest wraith
#

I was wondering referring to earlier to earlier discussion about spawning entities from xml, is it feasible to create a new world for creating entities from xml there and then instantiate them from there to the defaultworld? or is it better to have them straight in the default world?

hollow sorrel
#

@celest wraith yeah that's basically also what subscenes/conversion workflow does
that way you prevent sync points in one world affecting the other

ionic sierra
#

Any up to date guides on how to use DOTS?

gusty comet
karmic basin
#

and Unity samples

ionic sierra
#

I see. Is it relatively simple to make 1000 blocks with triggers, and they interact with the player etc. I know DOTS is preview, how does it work with materials and shaders?

hollow sorrel
#

@gusty comet what are the main differences with fholm's?

gusty comet
#

Extended API, fixes, performance, more collections

hollow sorrel
#

o nice

gusty comet
#

And the entire Native namespace models the collections after the .Net API

hollow sorrel
#

as in extensions for unity's native collections? or your own version of native collections

#

nvm just looked into it, they're wrappers for the unsafe versions right?

gusty comet
#

Yes, they are. Passable by value and strong typed

hollow sorrel
#

i'd try to avoid the naming conflict if you're targeting unity devs but other than that seems nice πŸ‘

gusty comet
#

Cheers!

ivory wagon
#

Any advice in rendering sprites with DOTS?

karmic basin
#

You gonna lack other basic Unity API stuff though, do your homework and check every DOTS package you need before committing for a real project. If it's for trying or learning, then go ahead right now, it's already fun (though a lot of frustrations with each update)

ionic sierra
#

Cool. What about the 2d...project tiny...is that ready to go

#

I heard that was all ecs

amber flicker
#

has anyone had any luck using GetOrCreateUnmanagedSystem within a SystemBase ?

coarse turtle
#

Yeah

#

because SystemRef is a ref struct it can only exist on the stack

#

so you just keep fetching it in OnUpdate()

amber flicker
#

ooooh... cool.. lemme give that a go - that rings a bell you already mentioned that actually

coarse turtle
#

You can do like a ref getter but I haven't really looked into that haha πŸ€”

amber flicker
#

hmm.. what I actually want to do is get a reference to some NHMs. I want to reference those NHMs from both SystemBases and ISystemBases. I was thinking I could put the NHMs in an ISB then have an SB that OnCreate set it's NHMs to the ISB ones - then GetSystem<SB> or GetSystem<ISB> depending on whether I'm in managed or unmanged land. I have no idea if any of that makes sense

coarse turtle
# amber flicker hmm.. what I actually want to do is get a reference to some NHMs. I want to refe...

I get what you mean, I had a similar situation in wanting to a store a spatial map. So what I had was a pointer to an UnsafeHashMap in the ISB and I just grab the pointer in other ISBs.

struct SomeSystemA : ISystemBase {
  public UnsafeHashMap<T, U>* Container;
  ...
}

struct SomeSystemB : ISystemBase {
  public void OnUpdate(ref SystemState state) {
    var refState = state.worldUnamanaged.GetorCreateUnmanagedSystem<V>();
    unsafe {
      UNsafeHashMap<T, U>* ptr = refState.Struct.Container; <- I just reference like so
    }
  }
}
#

dunno of any other ways, I just iterate πŸ€”

amber flicker
coarse turtle
#

pretty sure you can do it the same way

#

i think it's World.Unmanaged.GetOrCreateUnmanagedSystem<T>()

deft stump
#

question:
is it possible to use Unity ECS for architectural reasons rather than what it's intended for?

amber flicker
deft stump
#

i.e. keep using monobehaviour stuff and classic physics

#

but also have the ability to use SystemBase to loop through monobehaviour components.

#

I could use entitas tbh, but I'm too damn lazy

coarse turtle
deft stump
#

I mean you can use Hybrid

#

but would those entities be affected by classic physics?

coarse turtle
#

I think only with ConvertAndInject

#

defintely not Hybrid Companion Objects

deft stump
#

what's the downside of ConvertAndInject?

coarse turtle
#

you pay for the conversion cost on runtime generally, so it gets more expensive the more objects you need to convert during runtime iirc πŸ€”

deft stump
#

but after that? would it equal to having 2 of the same object though?

#

so meaning more stuff to process
(jesus i'm drunk more processing power to process, wtf was that?)

coarse turtle
#

I'm not sure what you mean by

would it equal to having 2 of the same object though?

deft stump
#

well afaik, convert and inject basically has 2 version of the same object. 1 as an entity and 1 as go

coarse turtle
#

Oh, does it? I haven't used convert and inject in a long time. I'm not too sure tbh

north bay
#

Huh as far as I know convert and inject only creates an entity that references the objects not create additional ones

deft stump
#

well I'll try it now

#

maybe it changed

safe lintel
#

imo you can use it just fine for looping through gameobjects, but you will always have that kind of duality that could make things a bit confusing if you need to dip into entities and back to gameobjects

fluid kiln
#

How is one meant to handle NPC movement in NetCode? When the movement is simulated on the server only it's not smooth on the client, and it can't really be ghost simulated because the client doesn't own it.

north bay
#

Are you talking about the interpolation not being smooth?

fluid kiln
#

Ish. LEt me get you a clip. I use destination type movement

deft stump
safe lintel
#

the confusing bit will be you will obviously need to rely on monobehaviours for their event stuff like OnTriggerEnter OnCollision, possibly fixedupdate etc so you sorta cant make a clean break and just use systems for logic

fluid kiln
#

I don't know if it's visible on video

north bay
#

How are you handling the NPC movement? Are you just moving them on the server and the client only interpolates?

deft stump
safe lintel
#

no idea how entitas works, i found it confusing πŸ˜„

deft stump
#

yeah I find it confusing too

fluid kiln
north bay
#

Are you seeing small jitters in the movement or is more extreme?

fluid kiln
#

Quite small. It's not much of a problem but I'd like it to be as smooth as client predicted movement

north bay
fluid kiln
#

Is there an alternative atm? Like maybe I can simulate its movement both on the server and client

north bay
#

I sadly do not have a version for 0.6 yet since I'm not using it

north bay
fluid kiln
#

NPC movement in most games is just interpolation right?

#

You're saying it's NetCode's implementation that causes the jitter?

north bay
#

Yes I do

fluid kiln
#

Okay then we can probably expect that to be fixed in the future? So I won't bother with it too much for now. THanks!

north bay
#

We are fighting since October to get attention on that problem...

fluid kiln
#

Can I offer support somewhere? ^^

north bay
#

Probably not, they are aware of it but they are not giving it priority.

fluid kiln
#

Ha okay

north bay
#

The snippet I've sent works pretty good for us tho

fluid kiln
#

I don't know if I'm comfortable enough to use my own implementation of network time :/

north bay
#

Understandable

#

That's why I waited till December before touching it myself

fluid kiln
#

I'll wait a bit and if I become desperate I'll look into it πŸ˜‰

deft stump
#

so I was right

#

Convert and Inject doesn't destroy the GO when the entity was made

#

fuck

coarse turtle
#

It looks like you're using hybrid renderer too?

#

So it's going to convert that injected gameobject to be subjected to a hybrid renderer

light mason
#

Is there a way in tiny to get a world position with mouse click. Is this something I need to do with tiny physics ?

fluid kiln
#

Is using non burst systems the best way to handle UI in DOTS?

ocean tundra
#

@light mason if its a pure 2d game you can do some maths ( i dont know it) to get world pos

#

same maths as in normal 2d unity i would guess

#

but if its 3d then you would likely need to use physics to do a ray cast

#

@fluid kiln yea thats what i would do, often i wouldnt even have a entities foreach
eg for my selected units (rts) i would have a entityquery and use toEntityArray and component array to extract all the data and then send it to UI

#

it wasnt very optmized tho, i could probably have used change filters and run that system at a lower update frequency

fluid kiln
#

Thanks I'll look into it!

ocean tundra
#

i wasnt sure what to do about world UI tho

fluid kiln
#

World UI? Wouldn't it remain GOs?

ocean tundra
#

the 'selected' outline was a entity i would spawn and attach to each selected entity

#

but things like heath

#

yea it would likely need to be a GO, but if you selected like 1000 units,,, it would probably die from all that GO creating/linking/updating

deft stump
#

but would using hybrid component on the entity make it be affected by the classic physics?

light mason
#

Tiny camera question, so I don’t see a camera entity in the tiny3D example or a conversion, tryin got query it also doesn’t exists,

#

How is this working ?

coarse turtle
#

if they solely rely on IConvertGameObjectToEntity and you don't attach those authoring components to the GameObject - then no.

deft stump
#

I don't plan on using DOTS physics though

coarse turtle
#

yeah if you dont have the package installed, then it wouldn't be subjected

deft stump
#

aaaaaaaaah.
hrmmmmmm...
so at best, I can probably make an authoring and hybrid the rigidbody...

#

weeeelp

#

so Hybrid RigidBody doesn't work out of the box

coarse turtle
#

yeah - Hybrid Companion Objects are entity driven

deft stump
#

other than Entitas

#

what other ECS architecture for Unity out there?

#

Unity ECS is literally in it's own world

#

and trying to mesh them is gonna give me lots of headaches

coarse turtle
deft stump
#

nice which one do you recommend me first diving into?

coarse turtle
#

sebas is pretty active on the Svelto C# Framework Discord - so you can ask there for help.

#

I've honestly only found DefaultEcs today from a post by sebas in his discord server so I haven't looked at it. I've messed a bit with svelto, but haven't dived into it too deeply

#

so my bias is towards Svelto.ECS, but again can't say too much about it - he has some examples you can comb through via github