#archived-dots

1 messages Β· Page 7 of 1

robust scaffold
#

C# types are reference types. Dont use typeof?

rustic rain
#

that's why I don't really favour your style

#

xD

safe lintel
#

im not!

robust scaffold
rustic rain
robust scaffold
safe lintel
#

its a struct

robust scaffold
rustic rain
#

oh

safe lintel
robust scaffold
# safe lintel

Maybe try instead making this camera position job a IJobEntityBatch where the query will require ComponentType.ReadOnly<MainCamera>(), and ReadOnly<LocalToWorld>(). Then in execute write to CameraLtW[0] the only value in the batch?

safe lintel
#

thats a good idea

robust scaffold
# safe lintel

Wait. GetSingletonEntity from state can not be burst compiled.

robust scaffold
# safe lintel

You must first create a query in OnCreate then use the query to get singleton entity, not use the state's version.

#

There are todos in the entities code that indicate they want to make entity query creation burst compiled, so everything from OnCreate to OnUpdate to OnDestroy all bursted.

#

This new project of mine with now 4 assembly definitions is possibly the best organized project I've ever made to date

solemn hollow
#

how do i call createadditionalentity inside a conversionsystem?
Do i need to get the GameObjectConversionSystem from World?

safe lintel
#

var springEntity = CreateAdditionalEntity(gameObject);

#

its just a method in the conversionsystem

solemn hollow
#

oh man im so stupid sry. my conversionsystem inherited from systembase

safe lintel
#

@robust scaffold ok so still had that error pop up with using cached not state query, but using the IJEB was a good workaround.

feral minnow
#

Hi, I am a beginner in ECS and DOTS world. Everywhere I see I am being marketed with high performance. However, I see different results than in YouTube videos. For instance we have the following video by Code Monkey: https://youtu.be/ILfUuBLfzGI

However, the results that I get are:
200 FPS in an empty project;
Only one Entity;
Burst - enabled;
Script: https://pastie.io/mqbouz.cs

What am I doing wrong?

rustic rain
#

There are quite too many checks in unity ECS

#

200 fps in Editor = 1500 fps in Build (at least for me)

feral minnow
#

Got it πŸ™‚ I have another question, seeing the same script that I pasted, why I don't see 3d object in a world?

feral minnow
#

It's a blank URP project

robust scaffold
#

Do you have the hybrid renderer package?

feral minnow
rustic rain
#

that's a package

feral minnow
#

Yup, I see it there

viral sonnet
#

just from assembly i can't see that the value is read from stack, right? like cmp byte ptr [rsp+B4h], 0h

#

or does the register type tell me something?

#

from my understanding this would be a value read from stack.

#

but this one isn't vmovss xmm1, dword ptr [r13+20h]. correct?

#

this is why i'm asking. globalCooldown is a ref variable and a comp on the current entity

#

pretty huge spike here

robust scaffold
#

Is it a random access write? Because it might be a cache miss and the CPU is stalled trying to find the variable in memory

viral sonnet
#

it's a ref from this var globalCooldowns = (GlobalCooldown*)chunk.GetComponentDataPtrRO(ref GlobalCooldown_WriteHandle); so, shouldn't be random

#

tick is an uint and a job parameter. maybe that's the issue

#

i'll just test it out πŸ˜„

robust scaffold
viral sonnet
#

execute calls private void MethodNew(ArchetypeChunk chunk) - shouldn't be an issue but hm, it's weird. maybe the measurement is off.

robust scaffold
#

That might be the issue here

viral sonnet
#

hm, can't make it static. so next best thing, using no method at all?

robust scaffold
#

Yea

viral sonnet
#

ok, let's see πŸ™‚

#

from the profiler timeline alone it didn't change anything. what it did change is that i can't see the code anymore in the profiler :/ only ExecuteInternal is visible

robust scaffold
viral sonnet
#

yeah, i dunno. it's a weird quirk of profilers. i have seen the same thing in vtune, VS and superluminal now

eager pawn
#

why use the entitymanager and methods like setcomponentdata in a conversionsystem instead of skipping the authoring component and just use the entitymanager within a regular system? like a spawnersystem or w/e

robust scaffold
#

Well, build time. Not compile time.

eager pawn
#

thanks! :DD

robust scaffold
#

It's like EarlyUpdate vs Update vs LateUpdate vs PostCameraRender methods in a monobehavior.

robust scaffold
#

ugh, get singleton results in a sync point

rotund token
#

Yes of course, you need to complete anything that could write to it

#

Get singleton entity doesn't

#

And getting the data on a job

rustic rain
#

@rotund tokensir, could you tip me what API did you use to create mega mesh for your graphics system?

rotund token
#

Do you mean my terrain?

rustic rain
#

I mean bursted creation of mesh

#

I realised I can make a 2d renderer like this

#

and I'm already half way through xD

rotund token
#

I just use the new meshdata api

#

You still need to call ApplyAndDisposeWritableMeshData on main thread at some point

#

But you can setup all the data in jobs

#

If you mean my drawer for lines, I just used CommandBuffer (not entities) and built nativelists in job and passed them to this

rustic rain
#

during conversion I create large RenderSprite shared comps

#

which contain material and large arrays of vertices, uvs and triangles

#

and per entity I simply add index of sprite

#

so during presentation foreach shared comp I grab indices for sprites

#
  • their ltws
#

and then create a huge mesh

#

through burst job

#

and then I draw it all in one call

#

so basically meant to be: 1 atlas = 1 call

robust scaffold
#

Oh my god unity, why did they abandon 2d dots...

#

i am staring at the source code of physics and ughhhh, this is pain

rotund token
#

you'd be so bored if you had a full working 2d engine

#

what would you even work on!?

#

the actual game?!

robust scaffold
#

3d privilege, smh.

viral sonnet
#

oh wow, check your struct layouts. i just optimized a 64 byte struct to 56 and gained a bunch of free performance

rotund token
#

bad ordering of fields?

viral sonnet
#

i thought rearranging fields was a thing?

rotund token
#

got to group those bools/bytes!

rotund token
viral sonnet
#
    {
        public SpellOwner spellOwner;               // size: 16 bytes -> 4 ints
        
        public float* snapshotSpellStats;           // size: 8 bytes
        public float* spellStatsPtr;                // size: 8 bytes
        public void* spellBlob;                     // size: 8 bytes
        
        public TargetInfo targetInfo;               // size: 12 bytes
        public byte sourceTeamId;                   // size: 1 byte
        public AttackResult forceSpellResultHit;    // size: 1 byte
        public bool fromMainEffect;                 // size: 1 byte
    }``` i have this now
#

best layout?

rotund token
#

yes

#

just make sure bytes/bools are grouped - really only thing you need to care about

viral sonnet
#

yeah got it.

#

do i misremember this that the compiler handles such a thing unless you have sequential or smth?

rotund token
#

sequential is c# default

#

if you don't do anything

viral sonnet
#

oh i see thanks

robust scaffold
rotund token
#

C#, Visual Basic, and C++ compilers apply the Sequential layout value to structures by default. For classes, you must apply the LayoutKind.Sequential value explicitly.

#

you're probably thinking about classes?

viral sonnet
#

yeah, guess so. so this is not a thing. damn πŸ˜„

rotund token
#

that said, i didnt even know you could apply layout to classes

#

considering it's called structlayout ^_^'

#

but seems like you can

Remarks
You can apply this attribute to classes or structures.

#

side note you should probably ask your question in burst forum not entities

#

much more likely to get a response from them

#

(that said they've been a bit less active recently though i think they were on holiday)

robust scaffold
rotund token
#

psh imagine not having paid vacations

#

i should take some, have like 3 months saved up =\

viral sonnet
viral sonnet
balmy thistle
robust scaffold
viral sonnet
#

that is a sad thread 😦

robust scaffold
#

It really is. Really really is.

rotund token
#

tldr: our priority partners do not care, only personal plebs use 2D /s

viral sonnet
#

i personally have no stake in it. my observation is just, there are a LOT of unity 2d games

#

can we blame richitello?

robust scaffold
#

A lot of shovelware sure. Not a lot of big budget money to unity licensed games

rotund token
#

as much as i like dots i do think this is somewhat of a valid point

it's hard to advocate internally for 2D + dots specific stuff, because it's less common for 2D games to have as serious scaling/speed issues

rotund token
viral sonnet
#

and that's a weird take. i think someone down the line made the point that dots mainly speeds up simulation and not just rendering

rotund token
#

you don't see many large scale blockbuster 3d games

#

sigh - that feeling when you are testing the build for company playtest and notice a bug that you introduced

viral sonnet
#

already out or what? hotfix dat sheeet

robust scaffold
rotund token
#

i am writing a fix atm before anyone else wakes up

viral sonnet
#

what a chad

rotund token
#

well i am kind of responsible for this build so just my job

viral sonnet
#

well, let's say i have worked with people who rather blame the alignment of the moon than fixing something asap

#

ok i have gone through every struct now. it's kind of embarrassing, i have made up like 0.5ms. down to 2.6ms now

rotund token
#

someone wrote a tool in like 2018 early dots

#

to just check every struct in your project if it's optimal

viral sonnet
#

now i hope i find some more. lol, easiest optimization i ever did

balmy thistle
viral sonnet
#

i've structured this pretty well. think i got every struct

rotund token
viral sonnet
#

would still be nice to have πŸ™‚

#

very cool thanks

rotund token
#

from memory it has a bit of an issue with nested structs

#

i remember duplicating this a while ago and redoing it to try fix this

#

otherwise it has false positives

robust scaffold
safe lintel
#

I like viewing whats on the roadmap with that thing but I really hate the idea of typing up some sort of request that will most likely just be quickly viewed and dismissed

robust scaffold
viral sonnet
#

already helped me on some structs I missed πŸ˜„ it has issues with enums that are assumed as byte but needs an int because of flags. still, very valuable tool

rotund token
#

ah yeah that was another of the issues

safe lintel
#

besides writing a request for an entire product feature like animation feels dumb πŸ˜‚

hello yes, I'd like to request ecs animation please because I dunno its like a pillar of modern game design these days

balmy thistle
balmy thistle
viral sonnet
#

sometimes i'm just amazed what some devs are able to do. dreaming makes an animation package, this one guy writes some form of nanite in unity

safe lintel
#

oh yeah and the guy that made a visual editor for dreaming's animation package like a week later

viral sonnet
#

that's also pretty sick

#

i would really like to use that animation package for my actual game but i'm also targeting mobile so, not an option with compute buffers as requirement 😦

coarse turtle
robust scaffold
coarse turtle
#

Yea that's what I did lol

robust scaffold
#

300 lines just to update AABBs

coarse turtle
#

once 1.0 comes out I want to take a stab at writing an animation tree system for 2d

#

since I can roll onto 2022

viral sonnet
#

hope the 1.0 preview is around the corner πŸ˜„

#

if not, < 4 months

coarse turtle
#

yea lol

rotund token
#

unite is nov 2nd?

#

i hope something is shown then

safe lintel
#

There’s a unite?

rotund token
#

i think so?

Get ready for it – Unite is back and free for everyone. On November 1–2, join your fellow game developers and others from the Unity community for two full days of inspiration, learning, and connecting.

robust scaffold
#

Wow, unity purged all references to hybrid components in 0.50. I just now am looking into it and it's mentioned twice in conversion and thats it.

#

They did want to delete it in 1.0 but it might the only way I can convert a tilemap.

#

Nevermind, it's dead in 0.50

viral sonnet
#

any chance to simd this? ```[MethodImpl(MethodImplOptions.NoInlining)]
private void CalculateBuckets()
{
//Debug.Log($"CalculateBuckets with length {allocatedIndexLength} nextCap: {next->Capacity} bucketsCap: {buckets->Capacity}");

        TValue* keyArrayPtr = (TValue*) (Values + keyOffset);
        
        for (int i = 0; i < allocatedIndexLength; i++)
        {
            //var bucketIndex = GetKey(i).GetHashCode() & bucketCapacityMask;
            var bucketIndex = UnsafeUtility.As<TValue, TKey>(ref keyArrayPtr[i]).GetHashCode() & bucketCapacityMask;
            
            (*next)[i] = (*buckets)[bucketIndex];
            (*buckets)[bucketIndex] = i;
        }
    }```
#

seems unlikely but i want to ask

rotund token
#

not really because i+1 could use the same bucketindex as i

#

best you could probably do is simd the index into an intermediate array

viral sonnet
#

yeah, hm, the allocation might not be worth it though. maybe i need to try the new update allocator. from what i read it's faster because it's buffered, is that right?

robust scaffold
rotund token
#

it doesn't actually dispose

#

there are 64 (or 32?) pools of memory

#

it tracks per frame memory requests and only releases memory if recent frames aren't using as much memory

#

i.e. if you request 2GB in a single frame it will release it shortly but if you reliably only request say 100mb/frame consistently it'll just re-use the same blocks every frame

#
        /// <summary>
        /// Rewind the allocator; invalidate all allocations made from it, and potentially also free memory blocks
        /// it has allocated from the system.
        /// </summary>
        public void Rewind()
        {
            if (JobsUtility.IsExecutingJob)
                throw new InvalidOperationException("You cannot Rewind a RewindableAllocator from a Job.");
            m_handle.Rewind(); // bump the allocator handle version, invalidate all dependents
            while (m_last > m_used) // *delete* all blocks we didn't even allocate from this time around.
                m_block[m_last--].Dispose();
            while (m_used > 0) // simply *rewind* all blocks we used in this update, to avoid allocating again, every update.
                m_block[m_used--].Rewind();
            m_block[0].Rewind();
        }```
#

blocks not used this frame are disposed
blocks used this frame are just rewound for next frame

viral sonnet
#

thanks! yeah i have to give this a try. maybe not for this but i think i have several other places

robust scaffold
#

The absolute worst feeling is closing a subscene and getting an import error

#

basically gotta delete the subscene then attempt to recreate it all

viral sonnet
#

what? no, just clear the entity cache

robust scaffold
robust scaffold
robust scaffold
#

@safe lintel Seems like IJob scheduling can not be burst compiled.

drowsy pagoda
#

Is there a way in query to exclude a type of dynamic buffer? Is it enough to just .WithNone<LinkedEntityGroup>()?

rustic rain
#

yeah

drowsy pagoda
#

awesome

rustic rain
#
                vertices.AddRange(((IntPtr*)curAtlas.vertices.GetUnsafePtr() + curOffset.verts.start * Float2Size),
                    curOffset.verts.count);

can anyone tip if my math is correct?

#

curAtlas.vertices is a large array

#

of float2

#

I have start index and count

#

of part of that array I need to copy

#

which is in curOffset

#

start and count respectively

robust scaffold
rustic rain
#

I get pointer of it

robust scaffold
#

You probably want (float2*)curAtlas.vertices.GetUnsafePtr().

#

IntPtr is the "safe" version for a random void*

rustic rain
#

yeah, but how am I supposed to add memory offset to it?

robust scaffold
#

You can add to a pointer. Check C# docs

rustic rain
#

uuuuhm

robust scaffold
#

You might want to directly apply the add range using an ResizeUninitialized() on the array then UnsafeUtility.MemCopy into it.

rustic rain
#

@rotund token sir, could you assist me a bit?

            var vertices = new NativeList<float2>(Allocator.Temp);
            var uvs = new NativeList<float2>(Allocator.Temp);
            var triangles = new NativeList<ushort>(Allocator.Temp);

Here's what I have + meshData
Not sure how to correctly construct mesh out of that

#

meanwhile manual is doing some kind of weird stuff

#
        // Tetrahedron vertices with positions and normals.
        // 4 faces with 3 unique vertices in each -- the faces
        // don't share the vertices since normals have to be
        // different for each face.
        data.SetVertexBufferParams(12,
            new VertexAttributeDescriptor(VertexAttribute.Position),
            new VertexAttributeDescriptor(VertexAttribute.Normal, stream: 1));
rotund token
#

new VertexAttributeDescriptor(VertexAttribute.Position),
this defaults to float3 i think? going to have to give it a smaller size

#

VertexAttributeFormat.Float16

#

assume position even supports that

rustic rain
#

shoudln't it be float8?

#

but tbh, I do need float3

#

anyway

#

right now I have vertices, uvs, triangles

#

and array of offsets

#

which contains starts of arrays (index) and count of how much data belongs to them

#

each entity contains index of that array of offsets

#

meanwhile I also need to apply float4x4 matrix

#

to those values

#

and this is where I'm lost

rotund token
#

should be Float32, 2

rustic rain
#

ah, yes

robust scaffold
#

Here's my ultra simple circle and box sprite renderer.

#

Takes in a float2x3 for object to world matrix and a float4 for color. The A in color determines whether it's a box or circle.

#

You can probably do more fancy things with the vertex but mine's just quad

rustic rain
#

oh god

#

I forgot about color

#

oh man, this is probably some next level headache

robust scaffold
#

If this is your first dive into a SRP, you chose a wild topic.

rustic rain
#

ah, to hell with this

#

I'll just use default HR solution = companion links

#

xD

robust scaffold
rustic rain
#

nah

#

works

robust scaffold
#

What's it called now?

rustic rain
#

it hasn't changed

#

it's default HR behaviour

robust scaffold
#

But hybrid components is dead

rustic rain
#

with sprites

#

wdym dead?

#

they are just called ComponentObjects now

robust scaffold
#

ohhhhh

#

oh my god, maybe I can "convert" my tilemaprenderer

#

because I am not going to roll my own tilemap.

#

hrmmmm, i guess it's not as easy as just adding it as a componentobject to an entity

robust scaffold
#

Damn, guess this just doesnt work. GetComponentObject returns null regardless of what I do.

rotund token
rotund token
#

oh yeah

robust scaffold
#

True for == null

rotund token
#

you can add it if you dont mind editing entities package

robust scaffold
#

the check is done runtime system

robust scaffold
#

This is basic transform, the fundamental component that should be able to be added.

rotund token
#

CompanionComponentSupportedTypes

#

just add it πŸ˜„

robust scaffold
#

add it to?

rotund token
#

add your Tilemap to the list

#

and it'll work like a hybrid component

#

that said, good chance this breaks in 1.0

robust scaffold
#

oh, thats stupid

#

unity what the fuck is this

#

I'm gonna have to copy the entire package arn't I

rotund token
#

i personally just use a class based IComponentData then have a system that handles this life cycle mangaement for me

#

due to concerns about 1.0 and this feature going

robust scaffold
#

Can class based component data be baked on conversion?

#

Yea, im not gonna touch this for now. Tilemap conversion would be nice but not entirely necessary as I just need to pull collider vertex data from it

rustic rain
#

em.AddComponentObject(e, object);

#

it'll add any class

#

Adding MonoBehaviours does weird results though

#

normal unityengine objects are fine though

dire ingot
#

what would be the easiest way to disable and reenable entity in runtime? What i need is to disable mesh and collider if switch is pressed and then enable them when it is pressed again.
I'm doing it with triggers and when I used EntityManager.SetEnabled(), i'm having " Entities.ForEach Lambda expression makes a structural change.", when I add WIthStructuralChanges to ForEach, unity spams errors on swith because i have dynamic buffer (i'm using statefuls from the physics example)

rustic rain
#

if you want to disable rendering use

#

DisableRendering

#

to disable physics you need to remove component of simulation index

solemn hollow
dire ingot
#

Just read about that Disabled tag, trying it now

rustic rain
#

Disabled fully excludes entity from all systems

#

all queries*

#

unless specified otherwise

heady vortex
#

Can someone help me wrap my mind around the jobs system?
Basically I want to compress a bunch of data (without any heap allocations happening if possible). Would I need to create a new job for each integer/float that I want to compress and schedule them one after the other? Or how should this be structured? I already wrote all of the compression code and everything, I just have no clue how jobs is supposed to work, even after looking at examples.

dire ingot
#

it works with with command buffer, thanks. But now i have other problem, i have another trigger event connected to that trigger collider that kills the entity entering. Sometimes the switch triggers, sometimes not. I think it is due to kill happening first. I put [UpdateBefore(typeof(ThatKillSystem))] on the SwitchSystem, but it's still happening.

rustic rain
#

you give it input data

#

it does it's magic

#

you get back your output data

#

jobs (bursted and threaded ones) work only with unmanaged types

#

value types

#

for collections use Collections package

#

it'd be best if you initially kept your data unmanaged

#

so you won't need any GC during job init

solemn hollow
rustic rain
#

IJobParallelFor

#

you don't know how it's iterated internally

#

you only know what happens in Execute

#

that's why I think of it as black box with magic

#

kek

#

(allthough you do know if you look at sources)

#

xD

solemn hollow
#

okay by that logic all of unity is a blackbox though. ^^

rustic rain
#

engine magic

#

πŸ˜…

solemn hollow
solemn hollow
#

for example i do chunk move operations in BeginInitCommandBuffer and destroy commands are happening at EndInitCommandBuffer. this way i make sure all commands that need the entity to exist run first. that way i wont get errors telling me an entity is already destroyed when i want to remove a component from a destroyed entity.

zenith walrus
#

Hi there! Guys Is there any asset or library to draw debug lines for dots? Built-in unity system is too slow

rotund token
#

If you're willing to fork a tiny bit of cash check out aline on the asset store

#

It can draw from burst and is magnitudes faster

#

Otherwise it's not that hard to roll your own solution with basic functionality

queen dome
#

Hello all, is this the channel where things about Burst should be asked?

viral sonnet
#

yes

queen dome
#

I am trying to upgrade Kinematic package to latest unity (2022) and I am having trouble with some of the burst compilation.

D:\Work\Inci_CharController\Packages\UnityKinematicaX\Runtime\Synthesizer\Synthesizer.Marker.cs(91,25): Burst error BC1063: Unsupported parameter `ref Unity.Kinematica.MotionSynthesizer` `synthesizer` in function `Unity.Kinematica.MotionSynthesizer.TraitExecuteFunc.Invoke(ref Unity.Kinematica.MotionSynthesizer.Any explicitThis, ref Unity.Kinematica.MotionSynthesizer synthesizer)`: Field `MotionSynthesizer.readDebugMemory.costRecords.m_DisposeSentinel` of type `Unity.Collections.LowLevel.Unsafe.DisposeSentinel` is not blittable. When compiling a method for use as a function pointer, only blittable types can be used in the method signature, including parameters and return type. To fix this issue, replace the non-blittable type with a blittable type. Blittable types include: void, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, UIntPtr, IntPtr, pointers, and blittable structs (i.e. structs containing only blittable types). Alternatively, use a pointer - `Unity.Kinematica.MotionSynthesizer*` - instead of ref - `ref Unity.Kinematica.MotionSynthesizer` - for this struct parameter.

"Unity.Collections.LowLevel.Unsafe.DisposeSentinel" is not blittable. is the problem. It is a class that comes from the new native collections.

#

As it is a class it is not blittable

#

The code is wrapped in ENABLE_UNITY_COLLECTIONS_CHECKS defines. Does anyone know where and how I can enable unity collections checks?

#

Actually the problem comes from NativeList which has DisposeSentinel inside.

solemn hollow
#

Anyone got any idea why adding to an unsafe list (which is inside a NativeList)would not actually add to it?
i am adding and right after i am checking the length. length is always 0.

pliant pike
#

maybe because its a copy

#

I think I remember having to do something where you have to add to the list and then add the assign the whole thing back too

solemn hollow
#

dataStructure.someNativeList[index].unsafeList.Add(element);
so this creates a new unsafelist which i need to assign back to someNativeList[index]?

pliant pike
#

I guess your already creating the new unsafelist inside the nativelist

#

it can get kind of confusing

solemn hollow
pliant pike
#

yeah something like that

viral sonnet
#

try to get the unsafelist by ref. this should work 100%. cant look up code right now. it's also very likely that the unsafelist in nativelist isn't actually a pointer. so you access it by value

#
        internal UnsafeList<T>* m_ListData;``` ok it's a pointer.  hm, not plausible to me right now what's going wrong. length is in unsafelist which should be incremented at the right memory space. the only thing that seems weird to me is that you access the unsafelist via . and not ->
#

what's your actual data layout? m_ListData is internal so you must have some other form which could explain the by value access again

robust scaffold
#

Documentation is so bad sometimes

#

The second destination should be source

balmy thistle
#

Oof that does look wrong

viral sonnet
#

hm, what's the actual optimization to doing it manually?

#

doesn't seem there's much to optimize

robust scaffold
viral sonnet
#

just writing out the loop

robust scaffold
#

I assume unity pads out the lesser sized component and then runs a single memcopy over the entire array.

viral sonnet
#

whelp, can't see the actual assembly of it :/

robust scaffold
#

Yea, it's an external call so who knows.

gusty comet
#

Angry Stallman noises

viral sonnet
rotund token
#

It's much faster the doing a loop

viral sonnet
#

yeah

rotund token
#

It's not as fast as memcpy but it's close

viral sonnet
#

do you know if nativeslice is also faster than manual?

rotund token
#

Not sure about that, probably depends what you're doing with it

#

It is handy though

#

Took me way too long to get my head around memcpystride

#

Always get it wrong

robust scaffold
rotund token
#

it's not that hard to use, i just always mix up the variables

balmy thistle
#

there are a lot of them to be sure

viral sonnet
#

i optimized a key array away in a hashmap with a manual nativeslice. wasn't useful when the key is also in the data that is indexed.

robust scaffold
#

Im wondering why unity hasnt done so already personally

viral sonnet
#

that said, i'm not the biggest fan of memcpying existing data. it never worked out in my favor

#

isnt span just the fancy version of stackalloc?

eager pawn
#

so i played around a bit with the different forms of conversion. first of all, i have 2 conversion systems, one of them is just declaring refs with [UpdateInGroup(typeof(GameObjectDeclareReferencedObjectsGroup))]

the other class does the DstEntityManager stuff. Also, im using the inheritance method where you extend GameObjectConversionSystem instead of using IConvertGameObjectToEntity.. i suppose a custom system is best for assigning (authoring????) variables during conversion

robust scaffold
eager pawn
#

also, i would need to make a new system per gameobject?

viral sonnet
#

hm, i've only tested stackalloc in combination of memcpying a foreign native array

robust scaffold
#

The issue is of course the extra int designating length for spans.

robust scaffold
eager pawn
#

good!

robust scaffold
eager pawn
#
class BerryConversionSystem : GameObjectConversionSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((PrefabReference prefabReference) =>
        {
            //DeclareReferencedPrefab(prefabReference.PrefabGameObject);
            Entity prefab = GetPrimaryEntity(prefabReference.PrefabGameObject);

            Debug.Log(prefab);
            //DstEntityManager.Instantiate(prefab);

            DstEntityManager.AddComponentData(prefab, new Berry {
                Id = 1
            });
        });
    }
}

[UpdateInGroup(typeof(GameObjectDeclareReferencedObjectsGroup))]
class PrefabConverterDeclare : GameObjectConversionSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((PrefabReference prefabReference) =>
        {
            DeclareReferencedPrefab(prefabReference.PrefabGameObject);
        });
    }
}
#

it's a bit messy still

robust scaffold
#

Wait, the prefab game object

viral sonnet
robust scaffold
#

yea, that's how ya do it.

robust scaffold
eager pawn
#

thanks for all your responses and help kornflaks (:

rotund token
viral sonnet
#

i actually have no idea what you're trying to do with this conversion

eager pawn
#

u really helped

robust scaffold
rotund token
#

oh yep ok

robust scaffold
eager pawn
viral sonnet
#

i'd start with a IConvertGameObjectToEntity conversion first

eager pawn
#

i still have that code too

#

i did both versions actually

viral sonnet
#

are both not working?

eager pawn
#

i just thought custom conversion systems would be better if i wanted to assign variables during conversion, but perhaps both work

viral sonnet
#

i have some pretty complex authoring setups and i never needed GameObjectConversionSystem

robust scaffold
#

I use GOCS exclusively. I dont want to slap on a ICGOTE on every GO i'm converting. One GOCS is good for all the lights i'm rendering for example.

#

I cant wait for baker so we dont need to use all these acronyms

viral sonnet
#

what's the difference, both work on 1 comp, right?

#

the power of a GameObjectConversionSystem is that you can run more complex queries and over multiple comps

eager pawn
#

yeah idrk how to make a GOCS for many components, haven't gotten to that part yet

#

right now it assumes a Berry

robust scaffold
eager pawn
#

i just filter with entities.foreach?

robust scaffold
#

Just add more Entity.ForEach() for every component you're converting.

eager pawn
#

kk

#

easy

robust scaffold
#

It's a different .ForEach than the one in SystemBase. It's the ancient lambda version

#

doesnt have filtering, cant do more than 1 component.

viral sonnet
#

i worded that wrong, you are just using one light comp is what i mean

robust scaffold
viral sonnet
#

you can get the MB comps in a IConv too πŸ™‚

robust scaffold
#

Yea, but then you have to link them in the inspector. Or use GetComponent<>() which might result in null errors.

balmy thistle
#

these acronyms are getting out of hand

robust scaffold
balmy thistle
viral sonnet
#

thrown a requirecomp tag on it. that said, i've moved to completely seperate full authoring comps now. adding all these little comps was getting stupid

robust scaffold
#

The tags are annoying. I might make a component with a flag enum to toggle on the flags added during conversion

viral sonnet
#

2 tag comps, ewww πŸ˜„

robust scaffold
#

I got an entire GO dedicated to system enable tags and singleton data

gusty comet
#

How do I accept DOTS as my personal lord an savior?

robust scaffold
gusty comet
#

Become one with nothing, got it.

robust scaffold
gusty comet
#

LetΒ΄s go

robust scaffold
#

Three: Get an IDE that lets you "Go to declaration" of a method. DOTS is fully open source but with shit documentation. You'll need to read the actual source to figure out what's going on.

gusty comet
#

Reverse engineering is my first second and third name now.

robust scaffold
#

Four: You know have accepted DOTS into your life. Go out and preach the glory that is ECS. Burn the OOS coders at the stake.

rotund token
#

the actual code is pretty well documented (doubling your point)

robust scaffold
#

The code has quite a bit of comments at the surface to mid level. Deep in it gets a little sparse but with the previous comments, it can be easily understood.

devout prairie
#

I think it's safe to say that, all of the things that make OOP and managed code so easy and quick to work with ( and are also their performance achillies heel ), must be thrown out and forgotten about

#

although, some stuff is in some ways quicker and easier in DoD/ECS which is nice in it's way

rotund token
#

at work, we're at a point where dots holdouts are finally realizing how easy it is to add new content to an advanced project

#

compared to oop

gusty comet
#

"-uses ScheduleParallel to schedule the lambda to run on multiple worker threads..." Sure?

robust scaffold
#

Yea, DOTS is a lot more modular.

robust scaffold
gusty comet
#

Roger that.

devout prairie
#

i guess technical debt is less of a problem with ECS arguably

robust scaffold
devout prairie
#

there's definitely costs associated with learning ECS and changing over though

robust scaffold
#

The initial curve is hard yea. Cant really teach the 10yo kiddies how to think data oriented. If they only recently evolved object persistence.

devout prairie
#

and i'd say 100% it's easier to rapidly prototype in for example classic unity oop

devout prairie
#

compared to doing like for like in DOTS

rotund token
#

i have a theory if you never learned OOP you'd have a lot easier of a time

balmy thistle
#

tough to tell, given it's the dominant model

robust scaffold
rotund token
#

i can remember! i was making choose your own adventure games in vb6

robust scaffold
#

You can show a kid that an apple has a property color of red. But can you really imprint upon them that while this apple has a color red, another apple has a color green and that both apples can be represented by a single entity indicating their unique identifier with a common component containing the property color.

gusty comet
#

(input-parameters) => expression It makes sense but how?

devout prairie
robust scaffold
#

That too. Kids are on natural crack most of the time.

devout prairie
#

also these days they're literally on the crack that is social media, which is really consuming a lot of their energy i feel

#

insta/tiktok/youtube/etc, it's almost like a drug addiction

robust scaffold
#

God i am so glad to have been born before smartphones really infiltrated the classroom of grade school.

rotund token
#

Didn't get my first phone to year 10. I was born right on the transition

devout prairie
#

it's definitely interesting that, there are two or three generations right now that were born around that time where, they sortof have one foot in the old world and one in the new

#

pretty significant in a lot of ways because the 'new' world is so insanely pervasive, and insidious in a lot of ways

rotund token
#

I would have been a really early Facebook user but these days don't use anything (except if you count YouTube I guess)

#

They say parents killed Facebook, I agree

safe lintel
#

navigating the world without a phone were good times

#

bus maps were my bane

robust scaffold
#

Bus maps these days are also pretty bad. If you use the official app or whatever they provide.

#

Google maps is a god send on that front

rotund token
#

Does anyone just not use Google maps for this?

#

I do use the tram app just because it has real time tracking so I can see if it's late

#

And that data isn't in Google yet for us

#

Though buses recently were added

gusty comet
#

Only way I get anything done is to lock the phone for days.

robust scaffold
#

I still have the ancient continental US atlas in the back seat of my car.

#

I hate tictok and short form video. Glad I never get distracted on those at least.

rotund token
#

The only reason up upgraded from my s8 was because i ran out of battery trying to get home and it had my ticket on it

robust scaffold
#

My S8's running strong. Probably another year or two before i upgrade. Dont use it much except for reading fanfiction...

devout prairie
#

haha s8 here too

rotund token
#

I really don't use my phone except to chat in here on public transport

devout prairie
#

camera is pretty decent tbf

rotund token
#

Which I'm doing atm

robust scaffold
#

Battery life aint good anymore but I bought a 15 foot USB-C cable and it never leaves the charger.

devout prairie
#

definitely i'd say there's good and bad sides to the tech we now have, definitely a ton of benefits to it, and a lot of bad stuff also

rotund token
#

We're all evil mobile developers feeding on addiction right

safe lintel
#

ill be honest, I loved my note2 & 5 but after switching to apple(because I constantly had issues where text messages only went through half the time to other iphones), the experience is way better

devout prairie
#

a lot of kids are way more tech savvy whether through progressing to modding games or even writing games, hacking, etc etc

gusty comet
#

Imagine having money to buy an Iphone.

robust scaffold
rotund token
#

Richy Rich over here guys

#

Can you fund my super awesome unique mmorpg game

safe lintel
#

my monocle just popped out

robust scaffold
#

mobile has been the pioneers for the worst gaming industry practices. Microtransactions, Macrotransactions, pay to wait, whale hunting, etc

rotund token
#

Pay to win

#

Yet people eat it up =(

safe lintel
#

also the whole upgrade phone addiction/cycle

robust scaffold
#

I get upgrading a computer but damn, my little handsized metal brick cost nearly as much as my 17" development laptop.

rotund token
#

I feel like that's wearing off a little?

#

There's been very little to be excited about in recent phone generations

#

New camera is about all that is advertised

#

The only thing interesting recently are the folds

robust scaffold
#

I go 3 maybe 4 years before upgrading laptops because there has been noticable and significant advancements in computing power. Phones? Uhhh, more cameras.

rotund token
#

Which I would actually consider getting if I could justify the price

#

Love they brought back flip phones

robust scaffold
#

Cant bring a flip/fold into the shower. Instant no buy for me.

rotund token
#

Well haven't owned a laptop since uni

#

Loved it, hybrid was great for note taking

robust scaffold
rotund token
#

I went back and spent 30k to do a masters for no reason

#

Just boredom

robust scaffold
#

At least I'm funded with only undergrad loans. Poor souls are stuck here self funded.

rotund token
#

Yeah not greatest idea

#

Oh we have government loans tied to price index

#

And undergrad is 50% covered

robust scaffold
#

Oh yea, my loans are not linked to interest which is nice. Recent inflation has been steadily decreasing my loans without having to even pay it.

rotund token
#

Well that's nice

#

During covid it was like 0.2%,last year like 3.7% πŸ’©

devout prairie
#

i guess salary has to increase with inflation for that to work though right

#

so any word on entities 1.0 being still on track for release

robust scaffold
rotund token
robust scaffold
#

Like SystemAPI.Query<>()? Come on.

devout prairie
#

i'm guessing conversion workflow will take the biggest hit for people not using subscenes etc possibly.. i noticed it does say in the docs that for example GameObjectConversionUtility for converting on the fly will be dropped

gusty comet
#

Channel is surprisingly based in economics.

rotund token
#

SystemCodeGenJobApi.QueryEntitiesWithComponents<>

#

Is what you're looking for right

rotund token
#

But still under discussion

robust scaffold
devout prairie
#

i think possibly also IConvertGameObjectToEntity for mono's might be dropped, not sure though

#

conversion is still for me a bit messy and unsure

robust scaffold
#

Everything merged under a single Baker. Does seem like it in the training. I see no examples using other conversion methods other than a single baker.

devout prairie
#

docs are a bit sparse on it also, the examples leave me thinking 'but what about this or that etc'

#

loading up samples and trawling through how they've did it is kinda painful also

robust scaffold
#

Once you get it nailed down, it doesnt seem that difficult or confusing.

devout prairie
#

so yeah i think a single unified approach with maybe some alternatives for exceptions/caveats will be useful

devout prairie
#

referenced prefabs is still a little bit of a grey area ( although i do understand and have a workflow for it )

#

and also for example conversion of stuff like joints and things that aren't created or initialized until later in the conversion pipeline

#

so potentially you might need different conversion systems running at different points in the pipeline to handle this stuff

robust scaffold
#

Yea. I have no clue how to link together hybrid game objects properly. Tilemaps for example. Tried last night but then ran into the issue where I'll need to modify the entities package to allow for conversion of tilemap renderer and such. So I have a temporary solution of authoring the data I need at runtime OnCreate which is not ideal.

devout prairie
#

they've said they intend to lean towards supporting a hybrid workflow so i'm guessing there will be a few things that will basically just have to be hybrid, until they build in support for them

#

i kinda wish they'd said 'screw hybrid' and went/focused on full tilt dots tbh πŸ˜›

robust scaffold
#

Converting everything done currently for GOs to DOTS will probably take years

#

Even more so than what it has taken so far to even make DOTS (development hell)

devout prairie
#

yeah i guess.. tbh i think they've done so well with entities/burst/etc, it almost feels like it would be harder and more messy to support a hybrid approach

#

but i guess in many cases it's easier to just, create a bridge for hybrid stuff, and that's that

gusty comet
#

Is there not always the option to migrate to Unreals ECS or what ever they call it?

robust scaffold
#

Unreal's ECS is extremely barebones and new.

#

Despite everything, the years in development hell for unity DOTS have really solidified the ECS structure and style of the code.

devout prairie
#

kinda hilarious when you see like, the guy that created flecs for example, just doing it alone, in less time

#

you wonder what takes unity so long to do similar things

robust scaffold
devout prairie
#

yeah

robust scaffold
#

9 mothers cant produce a baby in 1 month. Just 9 babies. Is DOTS the equivalent of 9 babies? Maybe, there's definitely some loss in efficiency with the scale unity has been chucking at this project now.

#

What they've done with Burst and making C# code equivalent to C++ is extraordinary though.

devout prairie
#

stuff like jobs and burst, are a revelation in what they offer and can do for the platform, ecs also, but you do wonder, why take so long

robust scaffold
#

Building from that foundation though is where Unity has definitely tripped and tumbled down the stairs a bit.

devout prairie
#

probably the requirement to integrate everything with the existing api's/enginecode, and also the UI has been a big part of that

robust scaffold
#

UI hasnt been the bottleneck though. They had this interface solidified within weeks following 0.17 release if you read between the lines back before they went complete radio silence.

devout prairie
#

so i guess in a way bureaucracy just as a function of being a large organization has held it back

#

i wonder how many of the huge leaps have been rapid advances by a few talented individuals vs many drawn out periods of small incremental changes/updates by the wider organization

robust scaffold
#

That's typically why research labs are structured very hierarchically. One or two lead researchers driving a group forward, determining what's the goals, what's the deliverables, what's the data required, and the lab scientist do the data gathering, the confirmation, a bit of the analysis.

#

Issue is with coding, it's very hands on. Lead researchers dont typically actually do the data gathering manually whereas coding, yea one brilliant coder with a vision can singlehandedly do the entire work.

viral sonnet
#

one has only to look at the code of cinemachine. working with lots of people also means the code can be monolithic and full of weird decisions. then this whole thing about codegen, Entities.ForEach lambda, etc... it's a lot of overhead and pretty complicated to solve it all

gusty comet
#

Economics is a science, a soft science like sociology but science none the less. The term for this is diseconomies of scale if you want to sound like a prick.

robust scaffold
#

And coding is as much a creative art than it is procedural science. You can have collaborative artwork but it together very rarely looks as good or superior to one great artist's work.

devout prairie
#

anybody know how many devs are actually assigned to any of the dots systems

viral sonnet
#

talk was around 50 are in the dots team

robust scaffold
devout prairie
#

i wonder if that includes like burst for example, which you could maybe say is mostly done except for incremental upgrades

#

does it include stuff like Animation

#

i guess everything under the namespaces

robust scaffold
#

burst seems like a very small specialized team. I've only seen 3 unique unity employee names responding to questions and bugs on the forums relating purely to burst issues.

gusty comet
#

I can imagine there is a 5 to 1 ratio of social and less social people on that team. Surely a company as large as Unity Technologies can not have a 5 man tea, running this show? (!hend Selp ran out of Lager at 2 am! How can I now forget how to program?)

robust scaffold
#

Ya know, I'm starting like like stackalloc. It allows for some really nice burst optimizations in loops:

#

Makes reading and understanding what's going on a lot harder though

gusty comet
#

Some day I will get the meaning of this.

robust scaffold
rotund token
#

Stackalloc is great if you have small known or calculatable max values

#

You can speed it up a tiny bit more turning off its memclear on allocation as well

#

If you really want to optimise

#

You do have a limited stack size though

robust scaffold
robust scaffold
rotund token
#

Yeah that's perfect here

robust scaffold
#

I got plenty of space, stackalloc is only at uhhh, 40ish

rotund token
#

I've just seen some people use it on like entity count or something silly

robust scaffold
#

.seh_stackalloc 56

viral sonnet
#

what? not even on the chunk entity count but whole query?

rotund token
#

yeah passed in a query.ToEntiyArrayAsync thingy (wiht some data)

#

and were doing iterations of them

timber ivy
#

so if i have one scene with 1k subscenes is that gonna be a problem?

rotund token
#

probably not?

robust scaffold
rotund token
robust scaffold
timber ivy
rotund token
#

if you open every subscene at once its probably going to take a while

rotund token
#

but subscenes are designed to handle large open worlds with a lot of them, and just streaming them in as needed

timber ivy
#

alright

robust scaffold
#

Runtime loading depends on scene streaming loading speed. Aka reading from the scene byte compressed file.

timber ivy
#

thats what I am using them for

robust scaffold
#

If you have a 1000 of identical scenes, the speed will be very quick as it just needs to load 1 scene and and then multiply that 1000 times.

#

If you have 1000 different scenes loading at once, that's gonna take a while.

#

it'll pop in one after another since scene loading is asynchronous. So the game will slowly pop in unless you write a loading scene that waits for all scenes to completely load in.

timber ivy
#

my plan is to split the world in 100x100 chunks each 100x100 area of the map will get its own subscene

#

each area of the map has unique vehilces and pedestrian models

rotund token
#

if you're curious about real world situation

#

v-rising has 872 subscenes

#

that's how they split their world up

robust scaffold
timber ivy
#

would I be better off just leaving the vehicles/peds in bundles or would each ped/vehiclce having its own subscene that I load when I need be a bad idea?

rotund token
#

yes

#

first published dots game i've seen use subscenes

#

all the others were started before they were really a thing

robust scaffold
#

if a vehicle is just 1 entity, ya dont need to make it a subscene. If it's multiple entities working together, one subscene should group them together and you add that as the vehicle.

#

I think with 1.0, subscene UI is getting a brush up. The UI preview presentation on youtube was really focused on subscenes and their interactions / conversions.

#

Right now it's a little uh barren. But it functions.

devout prairie
#

what approach do you guys have to enemy in range / detection.. can never decide whether do use a custom system that stores all current positions and loops over each doing a distance check, or just use large colliders with trigger events

timber ivy
robust scaffold
robust scaffold
#

otherwise, pre-load it beforehand or get a SSD.

devout prairie
robust scaffold
timber ivy
# robust scaffold otherwise, pre-load it beforehand or get a SSD.

I have an m2 the async calls are just really delayed. It doesn't stall my fps just takes ages for them to load. and there isn't really anything to wait on. If I decided to update the vehicle pool so new vehicles are added to it it just takes forever to do in the background.

rotund token
#

unity's bvh is pretty re-usable as well

robust scaffold
timber ivy
#

spatial hash built around Rect works best for this imo

rotund token
#

i was about to say my spatial hash is something like 4x faster for finding nearest neighbours for my orca system

viral sonnet
rotund token
#

but it's very specialized and can do a lot less than the bvh

#

but having a collection of nearest targets is very useful

devout prairie
#

i'm already driving the units via forces so i'm currently just adding an additional trigger collider and looking to capture it in my stateful event code, so yeah i'll probs do that

timber ivy
rotund token
#

a lot of systems ends up using the same type of data

rotund token
#

whether for targeting, local avoidance etc

devout prairie
#

tbh the stateful event system i've lifted from the physics samples is hella slow when there's a lot of collisions.. uses buffers on the entities etc

viral sonnet
#

i didn't say it's the fastest. it's the fastest when using dots physics though

#

eh, you get the meaning. i did say that haha πŸ˜„

rotund token
#

and you have to basically sort the data to do any parallel work on it

#

triggers are best left for rare events imo - entering specific areas etc

#

if you're querying every frame find something else

devout prairie
#

what then would you say is the optimal approach?

robust scaffold
#

If you need a raycast, and you need 4million of them per frame, BVH all the way.

timber ivy
rotund token
#

i have not found anything faster than a spatial hashmap for nearest neighbours - if you find something let me know

devout prairie
timber ivy
#

then use a spatial hash

#

if they are stationary

#

use a quadtree

devout prairie
#

any good implementations you can point to?

#

to save remaking the wheel

robust scaffold
timber ivy
#

I haven't tested this

devout prairie
#

i did actually write one for this for my previous dots project, but always looking for good recommendations

timber ivy
#

but this is how I do it

#

i like to use rect.overlaps

#

that way you dont have to add the whole cells collection when you query it

viral sonnet
#

the problem i see in 3d space. nearest neighbour is only half of what you'd need. typically you also need a raycast.

devout prairie
#

i think yeah you could call spacial hash a broadphase and then you have a narrower list of entities to poll for raycast

viral sonnet
#

i haven't figured out to make dots physics work selectively. all colliders are built

viral sonnet
#

so you have the bvh and spatial hash to build. not really optimal

timber ivy
devout prairie
rotund token
#

this is how long it takes to build my spatial map every frame for 200,000 entities

viral sonnet
rotund token
#

the single job is because i found batch adding to the hashmap to be significantly faster than doing it in parallel and only uses 1 thread

timber ivy
devout prairie
rotund token
#

this is for my orca implementation (actor avoidance) so there are no static objects

viral sonnet
#

can you implement some change filter?

timber ivy
rotund token
#

let me grab it

#

very simple actually

timber ivy
#

awesome thanks

rotund token
#

i havent looked at it in a year so there's a 50% chance i notice something straight away i want to improve πŸ˜„

timber ivy
#

haha

#

thats usually how it works

rotund token
#
        private struct QuantizeJob : IJobFor
        {
            [ReadOnly]
            public NativeArray<ORCAAgentState> Agents;

            [WriteOnly]
            public NativeArray<int> Keys;

            [WriteOnly]
            public NativeArray<int> Values;

            public float QuantizeStep;
            public int QuantizeWidth;
            public int2 HalfSize;

            public void Execute(int entityInQueryIndex)
            {
                this.Keys[entityInQueryIndex] = Hash(Quantized(this.Agents[entityInQueryIndex].Position, this.QuantizeStep, this.HalfSize), this.QuantizeWidth);
                this.Values[entityInQueryIndex] = entityInQueryIndex;
            }
        }```

```        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static int2 Quantized(float3 position, float step, int2 halfSize)
        {
            return new int2(math.floor((position.xz + halfSize) / step));
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static int Hash(int2 quantized, int width)
        {
            return quantized.x + (quantized.y * width);
        }```
#

that's the quantize job you can see in the above profile

#

the first bit determining their cells

#

the populate job just looks like this

        private struct PopulateSpatialHashMap : IJob
        {
            [ReadOnly]
            public NativeArray<int> Keys;

            [ReadOnly]
            public NativeArray<int> Values;

            public NativeParallelMultiHashMap<int, int> SpatialHashMap;

            public void Execute()
            {
                this.SpatialHashMap.ClearAndAddBatch(this.Keys, this.Values);
            }
        }```
#

just my batch add operation for a hashmap

timber ivy
#

bruh I didn't even know this was a thing

#

NativeParallelMultiHashMap

rotund token
#

o_O

timber ivy
#

I just started using dots like 3 days ago

rotund token
#

oh fair enough!

timber ivy
#

i've used a bit in the past

#

but not a whole lot

rotund token
#

yeah its /kind of/ a replacement for dictionary<T, List<TV>>

timber ivy
#

can you access its indexer?

rotund token
#

you can get an iterator from a key

timber ivy
#

oh cool

viral sonnet
#

guess most of the populate comes from the memcpy. maybe could be sped up with my ArrayHashMap πŸ™‚

timber ivy
#

How are you querying it?

rotund token
#

i think there was a reason i didn't do that though

#

but i can't recall

#

should probably investigate it

#

well whenever i get around to actually integrating this system in my game

#

i'll revisit that

timber ivy
#

is it possible to create a subscene programmatically?

rotund token
#

there's nothing special about a subscene

#

it's just a regular scene

#

and you can create a regular scene programmatically

#

just create regular scene and assign it to a gameobject with a subscene script

viral sonnet
#

like loading or really creating the GOs in there? because I'd say subscenes are not really designed for that or more to the point, the workflow isn't.

rotund token
#

got rid of the 2x array memcpy, the quantize job just direct write to the key/value buffers in the hashmap and then the populate job only does the bucket calculation

#

and it's slower?!

#
        private struct PopulateSpatialHashMap : IJob
        {
            public NativeParallelMultiHashMap<int, int> SpatialHashMap;

            public void Execute()
            {
                this.SpatialHashMap.RecalculateBuckets();
            }
        }```
#

consistent as well

#

takes nearly 30% longer

viral sonnet
#

is a resize triggered?

rotund token
#

there is no resize in here

#

stashed my changes just to be 100%

#

so confused

viral sonnet
#

just a recalc of the index can't take this long hm

rotund token
#

stash my changes

#

0.58 😬

#
            [NoAlias] this NativeParallelMultiHashMap<TKey, TValue> hashMap)
            where TKey : unmanaged, IEquatable<TKey>
            where TValue : unmanaged
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckWriteAndThrow(hashMap.m_Safety);
#endif
            var length = hashMap.m_MultiHashMapData.m_Buffer->allocatedIndexLength;

            var data = hashMap.GetUnsafeBucketData();
            var buckets = (int*)data.buckets;
            var nextPtrs = (int*)data.next;
            var keys = (TKey*)data.keys;

            for (var idx = 0; idx < length; idx++)
            {
                var bucket = keys[idx].GetHashCode() & data.bucketCapacityMask;
                nextPtrs[idx] = buckets[bucket];
                buckets[bucket] = idx;
            }
        }```
#

this is the after

#

this is the before```public static unsafe void ClearAndAddBatch<TKey, TValue>(
this NativeParallelMultiHashMap<TKey, TValue> hashMap,
NativeArray<TKey> keys,
NativeArray<TValue> values)
where TKey : unmanaged, IEquatable<TKey>
where TValue : unmanaged
{
CheckLengthsMatch(keys.Length, values.Length);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
AtomicSafetyHandle.CheckWriteAndThrow(hashMap.m_Safety);
#endif

        hashMap.Clear();

        if (hashMap.Capacity < keys.Length)
        {
            hashMap.Capacity = keys.Length;
        }

        var data = hashMap.GetUnsafeBucketData();
        UnsafeUtility.MemCpy(data.keys, keys.GetUnsafeReadOnlyPtr(), keys.Length * UnsafeUtility.SizeOf<TKey>());
        UnsafeUtility.MemCpy(data.values, values.GetUnsafeReadOnlyPtr(), values.Length * UnsafeUtility.SizeOf<TValue>());

        var buckets = (int*)data.buckets;
        var nextPtrs = (int*)data.next;

        for (var idx = 0; idx < keys.Length; idx++)
        {
            var bucket = keys[idx].GetHashCode() & data.bucketCapacityMask;
            nextPtrs[idx] = buckets[bucket];
            buckets[bucket] = idx;
        }

        hashMap.m_MultiHashMapData.m_Buffer->allocatedIndexLength = keys.Length;
    }```
#

literally removed the clear, capacity resize + 2x memcpy

#

and its twice as slow

#

popping changes let's try again

viral sonnet
#

i think the issue is that the bucket/next array isnt set to -1

rotund token
#

i was clearing it but

            if (hashMap.Capacity < entityCount)
            {
                hashMap.Capacity = entityCount;
            }
            hashMap.SetLength(entityCount);```
#

i was doing it before the length set

robust scaffold
rotund token
#

that is not true on hash maps at all

#
        {
            UnsafeUtility.MemSet(data->buckets, 0xff, (data->bucketCapacityMask + 1) * 4);
            UnsafeUtility.MemSet(data->next, 0xff, (data->keyCapacity) * 4);

            for (int tls = 0; tls < JobsUtility.MaxJobThreadCount; ++tls)
            {
                data->firstFreeTLS[tls * UnsafeParallelHashMapData.IntsPerCacheLine] = -1;
            }

            data->allocatedIndexLength = 0;
        }```
#

it memsets the bucket/next arrays to -1

robust scaffold
#

Ah, hrm. Guess it's not a list then.

viral sonnet
#

yep, i'm using next->Resize(length, NativeArrayOptions.UninitializedMemory); buckets->Resize(bucketLength, NativeArrayOptions.UninitializedMemory); UnsafeUtility.MemSet(next->Ptr, 0xFF, length * 4); // sets everything to max, Unity uses the same method in their NativeHashMap clear UnsafeUtility.MemSet(buckets->Ptr, 0xFF, bucketLength * 4); to clear to -1

rotund token
#

there we go

#

twice as fast

viral sonnet
#

noice πŸ‘Œ

minor sapphire
#

Sup in the dots land

#

Looks like hash maps in the dots land

robust scaffold
#

yes

timber ivy
#

Is there like a way you can do this in unity ecs?

var w = new  World();
w.Systems.Add(new SomeSystem()):

w.Systems.Update();
robust scaffold
#

Yes, but it's pretty painful.

timber ivy
#

really lame

#

how do you control execution order?

#

I saw attributes

#

but

#

that looks painful as well.

robust scaffold
#

That works. But doesnt sort.

robust scaffold
timber ivy
#

Yes that looks painful xd

minor sapphire
#

Create groups.
Use [UpdateInGroup] in systems.
Use [UpdateBefore] and [UpdateAfter] on groups, and systems within groups

timber ivy
#

Thats really the only way?

minor sapphire
#

no

timber ivy
#

whats the other way?

minor sapphire
#

If you really really want, you tick your own groups and systems

timber ivy
#

any docs on this?

minor sapphire
#

lemme check

timber ivy
minor sapphire
timber ivy
#

Yeah I can't find it anywhere either

#

Thank you though!

minor sapphire
#

it comes down to calling 'update' on a system, although I can't remember how you disable auto updating

minor sapphire
#

you can [DisableAutoCreation] but I'm not sure if that's really what you want

timber ivy
#

I mean that will work tbh

#

then can I just new System(); and system.OnUpdate wherever I want?

robust scaffold
timber ivy
#

awesome thanks

viral sonnet
#

groups and before/after cover pretty much the most use cases for ordering. does that not work for you?

robust scaffold
#

I can see cases where manual update would be nice. Like update once for monobehavior events if singletons are not possible.

viral sonnet
#

kind of hacky, requirecomponentforupdate but not have that comp around

robust scaffold
#

I need someone to verify this logic. I cant think it through:

#

Idx is originally 1, 2, 3... At the end, I want the value at Idx to match the resulting location of where the corresponding AABB and cents end up.

viral sonnet
#

does the tuple not require a temp variable?

robust scaffold
viral sonnet
#

huh pretty handy

timber ivy
rotund token
#

Just settings

worldly isle
#

Is there a good example somewhere of using the DOTs physics for colision detection?

#

I have been trying to find this all over and all I can find is raycasting stuff

#

oh and upto date

#

cause all the stuff I find is out of date

robust scaffold
#

That or suit up and dive into the source code.

worldly isle
#

wait so we just call hey has this thing collided all the time? that seems inefficient...

robust scaffold
#

Due to being stateless, what you have is "has it collided this frame". Nothing about last frame or any histories.

worldly isle
#

oh so we are not running a new calculation we are just checking the current state?

robust scaffold
#

Yep.

worldly isle
#

I feel like I am missing something here I don't see where this code belongs it just says to make a method public unsafe Entity SphereCast(float3 RayFrom, float3 RayTo, float radius) but not what class that is in or what system it needs to extend or how it gets called or anything

robust scaffold
#

It's probably buried somewhere in there. I'm not familiar with actually using the physics package personally.

worldly isle
#

cool beans

#

I am trying to learn it enough to make a youtube tutorial about it

viral sonnet
#

seems unrealistic. 1.7ms job for 250k entities

#

this on the other hand. pretty much nothing

drowsy pagoda
#

What does it take to move an entity from one scene to another during runtime?

robust scaffold
#

Yea, those percentages are clearly wrong.

robust scaffold
drowsy pagoda
robust scaffold
#

Otherwise, not during runtime. I asked the DOTS folks about that on the forums and they said Soon^tm.

drowsy pagoda
#

Ooof, there's that word again..."Soon"

rotund token
#

and can be closed together

#

you can add entities into this group by simply giving them the same component

#

however it's not persistent, once you 'close' the subscene during runtime the entity will just be destroyed

#

reopening the subscene will not recreate this entity

#

(and when i say open/close i mean during runtime via code, not via hierarchy)

drowsy pagoda
#

I think I'm gonna try that, I don't need them to persist between play modes.

rotund token
#

but it can be useful for tying effects and other things to these entities that will cleanup at same time

rotund token
#

if you close the subscene

drowsy pagoda
#

Oh!

rotund token
#

it just does destroy(allfromscene) including things you've added to it

drowsy pagoda
#

I think that's okay too in my situation. But thanks for the fine print.

robust scaffold
#

Huh, that is a neat trick.

rotund token
#

but it will just read back off disk when loading

drowsy pagoda
#

Thanks man

viral sonnet
robust scaffold
rotund token
#

these components

rotund token
drowsy pagoda
#

Yeah I was just about to ask

#

do I just need to mess with SceneSection or both?

rotund token
#

cant remember

#

if you have something in the subscene referencing a prefab

#

that prefab will also automatically be added to subscene and instantiating off it will be into the subscene at runtime

drowsy pagoda
#

nice

solemn hollow
#

thats the layout

#

this is essentially how it didnt work:

var tilesKeyArray = slotTilesHashMap.GetKeyArray(Allocator.Temp);
                    
                    var kernelSlotTiles = new UnsafeList<Entity>(100,Allocator.Temp);
                    intersectedCollapseKernel.kernelSlots.Add(new KernelSlot
                    {
                        tiles = kernelSlotTiles
                    });
                    
                    kernelSlotTiles.Add(tilesKeyArray[0]);
                    Debug.Log(intersectedCollapseKernel.kernelSlots[0].tiles.Length);```
#

that debug would always print 0

#

now my easy fix was to first fill the kernelSlotTiles and then add that to the kernelSlots afterwards. but i sure like to learn how id make that work. how would i access with -> ? never used it to access before.

robust scaffold
rotund token
#

hehehe down to 0.28mt + 0.28st for 200k

#

feel like unity's would be faster than that?

rustic rain
#

Why map population is single core?

robust scaffold
rustic rain
#

I mean tertles too

robust scaffold
rustic rain
#

Unity physics cause sync point as far as I remember

#

So maybe you should use this

#

Somehow

robust scaffold
#

How would sync points help?

rustic rain
#

You can calculate map capacity beforehand

robust scaffold
#

Hrm, assuming the parallelism is linear, division by 10 threads probably means 0.5ms for 10k. Which is pretty awful.

rustic rain
#

Increase it and then fill it threaded

rotund token
rustic rain
#

Huh

#

Is that a thing for native hash map?

rotund token
#

i have a lot of extensions for native hashmap to do batch operations

rustic rain
#

So I better always use single thread for it?

#

Hmm

#

Can you show batched add range?

#

I could use this one

robust scaffold
rustic rain
#

Huh

#

Maybe I can speed up target finding by a margin with that

#

But I assume

#

I should always use single thread for filling map, right?

robust scaffold
#

it's just a simple method change so just profile it.

rustic rain
#

It's not

robust scaffold
#

Or do both and profile the changes

rustic rain
#

Makes me refactor method

#

Which is a bit more complex than simply changing schedule method

rotund token
#

if you want to see difference from when i made it parallel to single thread batch operation

#

(and today i double the speed of the single thread operation)

rustic rain
#

Really interesting

#

Batching is a goal I guess

rotund token
#

the gotcha is this is only safe on a hashmap if it's empty

#

and if you're using non-multi version it won't check for duplicates

rustic rain
#

There are no duplicates in my case

rotund token
#

(it doesn't check for duplicates in multi either but the container allows it)

rustic rain
#

Oh wait

#

My map is multi

#

I forgot to mention

rotund token
#

yeah that's fine that's the one i linked

rustic rain
#

Ah

rotund token
#

you can add duplicates to that

#

normally

rustic rain
#

I simply need to fill entities based on sharecomp separation

#

Where they all share same id

#

So that should be easy to batch

rustic rain
#

Hmm

#

is there a way to have singleton blob?

#

I assume I could use World extension for that...

#

but would love some less managed option

rotund token
#

apart from being immutable, what advantages do you have using a singleton blob over a singleton entity?

rustic rain
#

blob for value

#

entity for tag whether it's active or not

#

I use blob because having I need a way to access data from anywhere

#

and since it's never removed

#

or moved

#

I can use singleton approach

#

it's kind of a variable like Time

timber ivy
#

im having a hard time finding an up to date solution for this

#

how do you add a component to an entity in a job you run with entities.foreach().scheduleparallel

rotund token
#

commandbuffer

timber ivy
#

does this.Dependency.Complete(); have to be called

#

or can i just comment that out and it would still work?

rustic rain
#

it's an example how it works

#

all you need to do is create ECB

#

and then addjob handler to producer

#

in ECB system

#

a bit below an actual example

#

of how it should look like

timber ivy
#

So you have to write your own ecb system?

rustic rain
#

no

#

there are default ones

timber ivy
#

ok cool thank you

#

Can you create the command buffer in system init and use it later or does it have to be recreated each frame?

rotund token
#

every frame

timber ivy
#

ecb has no get component is that just safe to use then?

rustic rain
#

GetComponent is codegen in foreach loop

#

it implements ComponentDataFromEntity for you

timber ivy
#

Is there no way to run this as a job?

        EntityCommandBufferSystem sys =
                World.GetExistingSystem<BeginSimulationEntityCommandBufferSystem>();

        // Create a command buffer that will be played back
        // and disposed by MyECBSystem.
        EntityCommandBuffer ecb = sys.CreateCommandBuffer();
        var pos = new float2(cam.position.x, cam.position.z);
        var sceneSystem = World.GetOrCreateSystem<SceneSystem>();
        Entities.WithAll<WorldChunkComponent>().ForEach((Entity e, ref WorldChunkComponent chunk) =>
        {
            if (math.distance(pos, chunk.position) <= 400)
            {
                sceneSystem.LoadSceneAsync(chunk.hash);
                ecb.AddComponent<RelevantComponent>(e);
            }
            else
            {
                if(HasComponent<RelevantComponent>(e) == true)
                {
                    sceneSystem.UnloadScene(chunk.hash);
                    ecb.RemoveComponent<RelevantComponent>(e);
                }
            }
        }).ScheduleParallel();

Passing sceneSystem is causing an exception since im passing a non value type

rustic rain
#

well, there is

#

but I have a feeling

#

that this job is run on simple entity

#

or not?

#

oh wait, is that dynamic culling system?

#

anyways

#

you can load scenes

#

by creating entities

timber ivy
timber ivy
rustic rain
#

take a look at what LoadSceneAsync does

#

pretty sure it creates scene entity

#
        void LoadEntitySceneAsync(Entity sceneEntity, LoadParameters parameters)
        {
            var requestSceneLoaded = CreateRequestSceneLoaded(parameters);

            EntityManager.AddComponentData(sceneEntity, requestSceneLoaded);

            if (parameters.AutoLoad && EntityManager.HasComponent<ResolvedSectionEntity>(sceneEntity))
            {
                foreach (var s in EntityManager.GetBuffer<ResolvedSectionEntity>(sceneEntity))
                    EntityManager.AddComponentData(s.SectionEntity, requestSceneLoaded);
            }
        }
timber ivy
#

yep

#

its nested in there pretty deep

#

but its in there

#

I wont be able to do that in a job anywyas will I?

rustic rain
#
        Entity CreateSceneEntity(Hash128 sceneGUID, LoadParameters parameters = default)
        {
            var requestSceneLoaded = CreateRequestSceneLoaded(parameters);
            var sceneEntity = EntityManager.CreateEntity();
            EntityManager.AddComponentData(sceneEntity, new SceneReference {SceneGUID = sceneGUID});
            EntityManager.AddComponentData(sceneEntity, requestSceneLoaded);
            return sceneEntity;
        }
rustic rain
#

that triggers SceneSystem update

#

which will load it

#

this is creating scene entity from scratch

#

but you should instead first check whether scene entity is created already

#

basically

#

you can resolve it all during your world chunk creation

timber ivy
#

That is done in the editor

rustic rain
#

so you can simply pass an entity to one of it's fields

#

and then use it

#

to load/unload subscene

#

btw, subscenes can also divide into sections

timber ivy
#

Wym?

#

Like they can be parented and stuff?

rustic rain
#

SubScenes support sections

#

that's why they have 2 shared components

#

not

#

1

#

you can load them independently

#

I haven't really touched any of that