#archived-dots

1 messages ยท Page 17 of 1

misty wedge
#

that's why all future comments should be in emojis only, it's a more powerful form of communication

rotund token
#

I think it's worded badly

#

If you say go to the back of the queue irl you would be the last to leave

robust scaffold
#

Think "end" in the comment as the earliest added in the queue

viral sonnet
#

i'll test this. can't imagine this really being FILO

robust scaffold
#

Values are being added at index [0] and the end is being pushed back.

#

So taking from the end returns the first in.

misty wedge
robust scaffold
#

What it should say is "front" of the queue.

misty wedge
#

Similarly "start of the queue" could be interpreted to mean either the part of the queue containing the people that started the queue (front) or the part of the queue where new entrants must join to start queueing (back).

robust scaffold
#

English. Yes. Everything needs to be emojis.

#

(says man who has never used a single emoji in text before).

misty wedge
viral sonnet
#

yep, NativeQueue is FIFO. just a reaaaally bad comment. should plainly say, returns the earliest element that was enqueued or make a FIFO reference.

rotund token
#

Well unless it was using parallel writer then it's really just a random element

robust scaffold
#

I think native queue is just a bunch of circular buffers.... i think

#

You can make a queue using an array and 2 ints but resizing it, no clue.

#

Everyone likes stacks. Far superior. Requires one less int.

misty wedge
#

But is there a good emoji for a stack? didn't think so

viral sonnet
#
        {
            NativeQueue<Entity> queue = new NativeQueue<Entity>(Allocator.Persistent);

            var queueEntity = EntityManager.CreateEntity(typeof(MonsterLineQueue));

            EntityManager.AddComponentData(queueEntity, new MonsterLineQueue()
            {               
                queuePtr = UnsafeUtility.AddressOf(ref queue)
            });
        }``` any idea why this is not working? I should be able to store the nativeQueue ptr like that and restore it with UnsafeUtility.AsRef
#

does addressOf only work for unmanaged memory?

rotund token
#

And it reads back per block

#

So 1 thread, then the next, etc will read back

#

Interlocks for grabbing a new block if it fills up

viral sonnet
#

yeah, that's what happens. anyway, not interested in parallel writing to queues. (i think that's a total fail) guess my method is not working. have to save the pointers or make an unsafe wrapper

robust scaffold
viral sonnet
#

yes ๐Ÿ™‚

#

the queue is created once, dequeued in a ST job and always filled up to a certain amount. i had a list before but the list has the problem that i can't just insert an element to the front without a memmove

#

well, actually the first element in the list was last. filling it up was the problem where i changed to the queue

robust scaffold
#

Unless you're doing this in parallel then yea, a queue will be better

viral sonnet
#

i'll keep this in mind. the list can have several thousand elements but i can keep it to 1 memmove. no parallel job involved

misty wedge
#

Does unity have any plans to incorporate C# hot reloading in the future?

misty wedge
#

Can you read an entity's component data using only a ComponentType? It doesn't seem possible from what I can see besides using reflection to dynamically create a GetComponent<T> with the T being the componenttype...

rustic rain
#

it'll be pointer to memory

#

so you simply read required amount of bytes

#

if type is unknown

misty wedge
#

What if I don't know how many bytes to read? My use case is I'd like to just get all components with all fields from an entity

rustic rain
#

pretty sure ComponentType can give it to you

misty wedge
#

I think I'll just stick with reflection, it doesn't really need to be performant

fierce shuttle
#

Hey, are there any scientific sources / papers on Unity DOTS or the Burst compiler? I've done some search already but been struggling to find any.

balmy thistle
#

What in particular would you find helpful

fierce shuttle
#

In general things I can cite on the topic. My big problem currently is that much of the information on DOTS and Burst is from Unity's website / docs which I am not really allowed to cite in my thesis.

balmy thistle
#

Ah, gotcha. Well, what's your thesis? It would make it easier to identify relevant sources

fierce shuttle
#

I'm working on a performance comparison for crowd simulation between OOP (traditional Unity component system) and DOD (Unity DOTS)

fierce shuttle
balmy thistle
#

Hopefully the bibliography can be mined for more references

devout prairie
#

Something annoying me at the moment, although i think i've noticed this before:

#

I have a system with lets say two ForEach jobs..

#

The first one writes to a particular buffer, the second one reads from that same buffer

#

However, the read job occurs a frame after the write job

#

But because both jobs are part of the same dependency chain, it throws the error ( must call Complete() on job 1 to read from that buffer in job 2 )

#

So I know that there is no problem as the second job always follows a frame after the first ( due to the presence of an entity created in the first job which the second job looks for )

#

So that problem can be avoided by simply splitting the system into two systems

#

It does exactly the same work in exactly the same way, but it doesn't throw this dependency problem

rotund token
#

automatic dependency only exists between systems

#

within a system you are entirely responsible for manually handling dependencies

devout prairie
#

well as i say, it's throwing the error, when both jobs exist within the system

#

even when job 1 only runs on frame 1, and job 2 only runs on frame 2 ( ie there is no conflict in read/write )

rotund token
#

even if the job doesn't run, it still means you're accessing something from the first job in the system after you schedule it

devout prairie
#

right yeah that's kindof what i suspected

rotund token
#

wouldn't this just easily be solved by scheduling the read job first within the system?

devout prairie
#

so internally, the system is cueing up that data for a write and a read, as it is part of that dependency chain, even if only the write job runs or only the read job runs

rotund token
#

i think it also has the benefit of kind of implying the read job is reading the previous frames work

#

without having to look at the actual job code

#

useful in 2 years time when you come back to it and forgot what's happening

devout prairie
#

i'm glad you got what i was saying, i was worried 'nobody's going to get this' haha

#

yep that's true also

#

i sometimes wonder, what's better - split a system up into multiple systems, or just have a bunch of jobs within a system

#

is there any significant overhead or detriment to splitting them up

#

i guess one potential advantage is you can have RequiresForUpdate and be more granular about which jobs/systems actually run at all

rotund token
#

SystemBase has quite a bit of overhead

#

much better with ISystem

#

especially if you're using the same query or component handles

#

it adds up over 500 systems

devout prairie
#

right yeah

#

i don't have 500, tbf, i'm guessing it's negligible, but worth noting

errant hawk
#

any news about DOTS lately?

karmic basin
#

Seen the video where the CEO talks a little bit about dots ?

pliant pike
#

I'm confused how you are running the jobs @devout prairie

#

I have several jobs in a single system like a chain all time and it seems to work fine

devout prairie
#

So because the first job writes to those buffers, the second job can't reliably read from them

pliant pike
#

oh yes I see, one of my sequences involves a buffer but that buffer is written to a nativearray and then that nativearray is passed to the second job

#

I think buffers are generally finicky like that

misty wedge
#

Nvm, I thought you meant BufferFromEntity, not GetBufferFromEntity...

pliant pike
#

I think I remember tertle saying something about you can't be sure about what's accessing a buffer sometimes so they have to have more protections

misty wedge
#

I'm guessing it's because he is getting the buffer before scheduling the job. I'm actually amazed unity lets you do this (pass a DynamicBuffer to a job), since that doesn't seem correct. I might be mistaken though

#

Ah, I missed the part about them not running in the same frame

#

Disregard everything I said ๐Ÿ™ƒ

pliant pike
#

it shouldn't make any difference even if they are in the same frame

misty wedge
#

If you schedule them as dependencies it should work fine

pliant pike
#

yeah, to be honest I thought systems had auto dependencies

misty wedge
#

Do you mean inside the system or between systems?

pliant pike
#

inside the system

misty wedge
#

They kind of do, one overload of Schedule (the one that doesn't get a JobHandle) automatically adds the dependencies for that scheduled job to SystemBase.Dependency

#

Meaning the dependency chain is equal to the order you call Schedule

pliant pike
#

oh ok

misty wedge
pliant pike
#

cool, thanks

pulsar jay
#

Anybody else her got this VlidTRS error?
This happens to me sporadically:

Assertion failed on expression: 'ValidTRS()'
UnityEngine.Matrix4x4:get_rotation ()
Unity.Entities.CompanionGameObjectUpdateTransformSystem/CopyTransformJob:Execute (int,UnityEngine.Jobs.TransformAccess) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Transforms.Hybrid/CompanionGameObjectUpdateTransformSystem.cs:96)
UnityEngine.Jobs.IJobParallelForTransformExtensions/TransformParallelForLoopStruct`1<Unity.Entities.CompanionGameObjectUpdateTransformSystem/CopyTransformJob>:Execute (Unity.Entities.CompanionGameObjectUpdateTransformSystem/CopyTransformJob&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

Seems to be an internal problem with the Unity Companion Transform updates

rustic rain
pulsar jay
#

Well how do you know ๐Ÿค”

rustic rain
#

are you using default(float4x4) anywhere in your code?

#

or default(float4) for rotation?

pulsar jay
devout prairie
#

Or debug step

coarse turtle
#

it's been a while since I had touched the conversion system & prefabs, but I'm having some difficulty linking a prefab entity to another authored entity

class DeclarePrefabSystem : GameObjectConversionSystem {
  public override void OnUpdate() {
    Entities.ForEach((SomeAuthoringComponent foo) => {
      this.DeclareReferencedPrefab(foo.Prefab);
    }
  }
}

class SomeAuthoringComponent : IConvertGameObjectToEntity {
  
  public GameObject Prefab;

  public void Convert(...) {
    var prefabEntity = conversionSystem.GetPrimaryEntity(Prefab);
    dstManager.AddComponentData(entity, new PrefabComp { Value = prefabEntity });
  }
}

It's in a similar vein to the code snippet, but I think I'm getting a different entity via GetPrimaryEntity (e.g in a subscene I'm getting index 8, but on runtime index 8 is a completely different entity)

pulsar jay
devout prairie
coarse turtle
#

Ah so the DeclarePrefabSystem runs in GameObjectDeclareReferencedObjectsGroup since I had recently ditched IDeclareReferencedPrefabs

#

since I still had the same issue ๐Ÿค”

devout prairie
#

This is the barebones of a typical mono i use for declaring prefabs, it doesn't use subscenes though:

[DisallowMultipleComponent]
public class SelectionSystemAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
{
    public GameObject circlePrefab;

    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var selectionSystem = dstManager.World.GetExistingSystem<SelectionSystem>();
        selectionSystem.placerRing = dstManager.Instantiate(conversionSystem.GetPrimaryEntity(circlePrefab));
    }
    public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
    {
        GeneratedAuthoringComponentImplementation.AddReferencedPrefab(referencedPrefabs, circlePrefab);
    }
}
#

I tend to chuck these together pretty quickly just to get something that 'works' so i'm sure there's a better approach, i'm not even sure if using mono's like this will be supported for long.

#

The whole conversion thing is a bit of a mess tbh, quite the headache

#

Fwiw i don't normally instantiate the prefab inside the conversion like that, but just to demonstrate that it does actually work and deliver the correct primary entity

robust scaffold
devout prairie
#

instead of what they have now which is basically a minefield of different approaches without any clear guidance on what exactly is what

#

aint nobody got time for that

viral sonnet
#

not much changing compared to IConvertGameObjectToEntity tbh

viral sonnet
#

at least not for the common use case of just binding data and add some IComps

robust scaffold
viral sonnet
#

yeah true, don't get me wrong it reads a lot better but it's all details and i don't care too much about that

#

dstManager.AddComp or AddComp ... meh

robust scaffold
#

It looks like a GOCS except without the Entities.ForEach() and the primary entity implicit inside the EM actions.

robust scaffold
devout prairie
#

do you think they'll switch to subscene only approach for conversion

#

i'll guessing not

#

ie probably support both

rotund token
#

Disappointingly no

robust scaffold
viral sonnet
#

when the ConvertToEntity is gone. How would you convert without a subscene?

rotund token
#

They posted recently, on netcode I think, that runtime conversion still a thing in their latest master

#

I feel like if they aren't removing it in 1.0 will never be removed

devout prairie
#

one of the things i've always struggled with, that there doesn't seem to be clear guidance on ( and so you have to find out through a lot of trial and error ) is for example when systems are created, vs when mono's are instantiated, vs when mono conversion code runs, vs when subscene content is streamed in and available, etc etc

#

to me that whole thing is really messy and difficult

#

whereas ECS itself - no problem, pretty straightforward

rotund token
#

At the moment are speaking, ConvertToClientServerEntity it is still present in 1.0. A final decision is still in progress for what I know.
I will check fore more up-to-date status, but it is safe to assume it will be still there.

Jul 25, 2022

devout prairie
robust scaffold
#

For now, performance doesnt seem to be that bad just going through mono for UI. That's what unity is doing for the inspectors.

devout prairie
#

Yeahh plus i think either way, they're gunning for a hybrid approach so i think it would make sense to clear some of these things up

#

I don't really feel that just dumping a complete example project on github is the best way to do that either

#

Primarily the docs should be clear on these things

#

just my 2c tbh

safe lintel
#

any examples of the aspect workflow in that repo?

#

or what hybrid workflows look like?

robust scaffold
viral sonnet
#

TransformAspect.EntityLookup seems built in

robust scaffold
viral sonnet
#

in the fetcherMovementSystem. Transform seems to be a builtin aspect

robust scaffold
#

Oh yea, the default 3D transform components are grouped together into a default TransformAspect

viral sonnet
#

which is nice because the roundabout way with the ITransform job was not that great

robust scaffold
viral sonnet
#

hm, is CDFE<Transform> a thing? Never tried it

robust scaffold
#

The GO transform?

viral sonnet
#

yeah

#

because that's what TransformAspect.EntityLookup does now

#

and I don't think that worked previously

robust scaffold
#

GO Transform is a Component class. Not IComponentData. So it wont work.

devout prairie
#

have they started adding Transform to entities then? as a reference to the GO?

robust scaffold
#

TransformAspect is just a grouping of L2W, Translation, and Rotation. The ICDs havent gone anywhere.

devout prairie
#

i never really used companions so i guess they could have

#

in which case i think it would be CFE<Transform>

viral sonnet
#

oh really? then it's a REALLY dumb name.

viral sonnet
#

Transform should stay exclusive to GO and MBs

#

everything else is confusing

robust scaffold
#

TransformAspect is just this except with RefRW<Translation> Position, RefRW<Rotation> Rotation, etc.

viral sonnet
#

lol, disappointing. i thought that was one new feature that helps with hyrbid

robust scaffold
#

And from what I see from these training samples, there's no integration of aspects with the IJobEntityBatch interface. So we still need to do GCDH<> for job scheduling

#

Aspects are an entirely codegen feature. Nothing that we, largely, can use.

#

I imagine if we want to be able to use aspects, we'll need to use the Entities.ForEach lambdas.

viral sonnet
#

yikes!

open shore
#

Are there any good DOTS equivalents of the old CharacterComponent?

rotund token
robust scaffold
#

You might be able to recreate it using a capsule body and then go from there.

open shore
rotund token
#

the physics samples has a full character controller

open shore
#

I want to avoid using a PhysicsBody because it's much heavier than what I want

#

And another question - does anyone know a good way to implement a movement state machine in DOTS? It's usually very object-oriented so it's hard to come up with a solution that fits a data-oriented structure.
From what I've seen so far, there are two obvious solutions:

  • Component + System per State
  • One component + system for everything and differentiate between states using enums.

Neither really seem like good solutions imo.
The first one is organized, but it means that there'll be a lot of systems running in the background and also means that I'll have to switch components often, which will reset the related cache. The second one is gonna be ugly. If I'm going to have ~15 states, the code will be unreadable. It's also not going to take much advantage of the instruction cache's efficiency boost, so it beats the point of using DOTS in the first place.

rotund token
#

first question

#

what purpose is the state machine serving for the problem you're trying to solve?

open shore
#

a 3d platformer character movement. I'd also like to use a state machine structure for every other living entity in the scene

rotund token
#
  1. even though less efficient will be much faster btw
open shore
#

which solution?

rotund token
#

1 system

open shore
#

I

#

oops

rotund token
#

you say this

It's also not going to take much advantage of the instruction cache's efficiency boost, so it beats the point of using DOTS in the first place.

#

but i'm pointing out it'll be much faster than your other solution

open shore
#

I'd end up with 10 systems that always run in the background even though most of the times nothing uses them

viral sonnet
open shore
rotund token
#

you're reading what i said completely backwards

#

i'm saying

  • One component + system for everything and differentiate between states using enums.
#

is faster

open shore
#

I was looking at Rival earlier and I was thinking about getting it to read how they implemented some things, but I'm not sure if it's using a PhysicsBody or not

rotund token
#

no component changes

#

only 1 system

open shore
# rotund token only 1 system

This beats the purpose of DOTS imo. I'm pretty sure most of DOTS performance boost comes from "abusing" the machine's instruction cache by bulk-running similar tasks instead of scattering them around the game tick. If I have a system with a complex task per entity, I might as well run it scattered anyways because the instruction cache won't be able to work with it.

rotund token
#

i think you've over simplifying the purpose of dots

#

what you're getting here is much better thread utilization

#

and significantly less main thread overhead

#

your data is packed even tighter together instead of being split over 15 chunks

open shore
#

I'd always want all of my movements to run on a single thread.
The place where DOTS really shines is the way they group tasks to run together. It sounds simple but it can bring a serious performance boost: https://youtu.be/CBP5bpwkO54

This Unreal Fest Europe presentation by Rare's Senior Software Engineer Jon Holmes covers the techniques employed to efficiently manage the scale of Ticking Components and Actors within Sea of Thieves while also diving into a few real-world examples of how the team optimised these systems and detailing how it all plugs in neatly inside Unreal En...

โ–ถ Play video
pliant pike
#

I did pretty much a state machine with a bunch of enums in one system it was pretty fast from what I can remember

viral sonnet
#

i'm not sure what's your problem with a physics body though. set to kinematic it doesn't do anything

open shore
rotund token
#

I've posted this before but if you want numbers from an actual production environment

#

original implementation, lots of little systems - 6ms
merging to single system, lots of little jobs - 2.5ms
1 single system, merging into 1 large job (reusing Gets) - 0.75ms
1 single system, 1 large job, burst compiling Gets - 0.35ms

#

lots of systems is by far the worst thing you can do for performance in entities atm

#

if you're targeting anything except high end desktop market

pliant pike
#

I think it takes advantage of dots fine

viral sonnet
#

pretty explicit ๐Ÿ˜„ ERROR: kinematic character objects cannot have a PhysicsBodyAuthoring component. The correct physics components will be setup automatically during conversion. Conversion will be aborted

viral sonnet
open shore
rotund token
#

If you need a lot of systems, use ISystem

#

it's the only solution to the problem

#

If you can use ISystem you can get away with a lot more of them

open shore
#

Another solution that was brought up was to not use a StateMachine at all, but it's pretty hard to come up with something new

rotund token
#

well that's pretty much why I was asking what state machine provides you

open shore
viral sonnet
#

i think FSMs are an OOP concept. not that great in DOD

open shore
#

yeah exactly

#

so any ideas for data-oriented alternatives?

pliant pike
#

yeah I'm curious what the alternatives are like is it possible to make something where you don't know and don't hardcode the exact number of states

viral sonnet
#

seperate jobs and queries for mechanics. it doesn't look too different, but it differs from having a huge switch case and calling a method. it's really about preventing polymorphic data

open shore
rotund token
#

I wasn't saying you shouldn't have multiple systems

#

I was simply pointing out from your original statement that it's faster to have a single system (most of the time)

pliant pike
#

its like it depends how fast you want things as well

rotund token
#

If you need a lot of systems, try and use ISystem

#

It gets rid of a lot of the overhead

viral sonnet
pliant pike
#

I'm sure if you used multiples systems it would at its base be faster than using monobehaviours

open shore
pliant pike
#

yeah but there has to be limits, just for gameplay's sake you can't just have millions of entities, I don't though it depends on exactly what you are trying to do

open shore
viral sonnet
#

no it's not for the reasons tertle pointed out multiple times

open shore
open shore
rotund token
#

for the record you can have unknown number of switch statements / states in a job

#

if you are happy to get low and dirty

#

my AI system logic/states is built entirely from UI no code gen

#

you can hook up any number of state combinations

#

basically just builds a graph

pliant pike
#

sounds interesting but I don't like to get low and dirty leahSAD

open shore
rotund token
#

who cares

#

it runs 20x faster than the instruction cache optimized system i have at work

open shore
#

I, the creators of Sea of Thieves, and many other studios who used that technique to save their game's performance

rotund token
#

all that matters is the final performance numbers

#

i can feed through over 100k entities/frame

#

into my utility AI system in 2ms

viral sonnet
#

there is really no way you run into instruction cache issues in todays hardware. the bottleneck is always data read/write and random memory access

#

and if you do, you are at point with absolutely perfect memory layout and code

open shore
viral sonnet
#

optimizing in the nanosecond range has no practical purpose if it isn't your dedicated job

pliant pike
#

yeah are you trying to make a game or a super AI

rotund token
#

sorry i lied 200k entities in 1.2ms

viral sonnet
#

what unity has done here, and changed, has nothing to do with instruction cache issues. it's about the data

#

calling single Update on monobehaviours was a problem because the data is all over the place

open shore
viral sonnet
#

that's okay, we all do. but start somewhere. code, profile, rinse and repeat.

#

(i was/am optimising for several months now ๐Ÿ™‚ )

open shore
#

Not really sure what you mean by that. The next step of my project is figuring this part out.

viral sonnet
#

i mean, the first step is to make it work, then find the flaws.

open shore
#

mark it as done, I already implemented a state machine that works flawlessly. Now to optimize it I need to come up with a completely different structure that works with dots.

viral sonnet
#

you implemented an OOP FSM with classes and managed memory, compiled in mono/il2cpp?

rotund token
#

the question I have is, what type of entity count are you looking at?

open shore
#

Yes, both in Unity and Unreal. I thought the next interesting step would be to get something similar to work in DOTS

viral sonnet
#

great starting point when you can compare

open shore
rotund token
#

oh

#

ah that's nothing

viral sonnet
#

haha yeah ๐Ÿ˜„

rotund token
#

run it in a single thread from a single chunk (from a single system)

#

you aren't really going to notice most of the improvements until you hit 1k+ entities

open shore
#

since I'm making it with DOTS, I wanna come up with something that handles more than that. (again - I want performance that I don't really need)

rotund token
#

with that entity count all you really care about is removing main thread overhead

#

your job threads are going to be so empty

open shore
open shore
#

by everything I mean everything that has a collider and moves. I'm gonna use separate entities that smoothly follow their physical entity. These entities can run asynchronously

rotund token
#

there's nothing really stopping you doing this with threads

#

most of entities / jobs are very deterministic as is

#

you just need to avoid parallel hashmaps really

#

and any usage of threadindex

open shore
rotund token
#

it'd be calculated the same way every time

#

entities is quite setup to be deterministic

#

there's only a few things you need to consider (and obviously the floating point issue)

#

and it's very easy to have deterministic threaded code with it

#

but yeah if you don't care about crazy threaded scaling and you're doing everything on main thread

open shore
# rotund token it'd be calculated the same way every time

think about these situations:

  • the platform moves away and then the character jumps to the edge of it
  • the character moves to the edge of a platform and then the platform moves away
    One will result in the player falling while the other will result in the player standing on the edge. This is just one example
rotund token
#

if you want performance use ISystem without jobs

rotund token
#

each playthrough (if you used a fixed update)

open shore
#

yes, and if they all run on the same thread

rotund token
#

no

#

even if your jobs run in parallel

open shore
#

that's gonna be bad. I need to wait for one collider to finish to be able to accurately update the rest

rotund token
#

the safety system ensures you can't fuck this up

#

the jobs will be scheduled after each other

open shore
#

then there's no point in running them asynchronously - they're all blocking each other anyways

rotund token
#

no?

open shore
rotund token
#

but the job itself can be parallel

#

and jobs that dont have dependencies on each other can run in parallel

open shore
#

they all depend on the current position of every capsule in the scene - they're gonna be blocked 100% of the time

#

collider*

rotund token
#

yeah but what about the job that has some creature eating a berry

#

3 screens away

#

you talk about the point of dots being instruction layout etc

#

but imo the point of dots is easy, safe, mulithtreading

#

and to me there's no point in using entities if this isn't your goal

open shore
#

I'm only talking about the movement system, I plan to use separate threads for the rest.

rotund token
#

sure

open shore
#

dots has a lot of good tools for multithreading, I'll definitely utilize it for other parts of the game, but if I want to run something in a sequence, multithreading isn't really a good solution regardless of how good the framework is

rotund token
#

you could just you know, double buffer it (if you were willing to use physics it'd be done for you)

#

i think conveyer belt games are a very simple example of this

#

they need to not collide but they can't scaling without threading

open shore
#

I can't use physics, realistic physics simulations never give me the result I want.

rotund token
#

i'm not saying you need to simulate physics - we actually only use physics for spatial queries at work

open shore
#

I usually code my own simple unrealistic physics - that's why I was using a CharacterComponent instead of a Rigidbody in my gameobjects project

rotund token
#

if you don't give anything a physics velocity it basically just becomes a very useful spatial map

open shore
rotund token
#

what calculations?

#

if you aren't simulating it's not calculating anything

open shore
#

you're recommending a PhysicsBody right?

rotund token
#

all it does is build a very efficient BVH

open shore
#

Every frame it handles collision, physics materials, and (relatively simple) physics simulations. I only need the collisions.

rotund token
#

handles collision, physics materials, and (relatively simple) physics simulations.
are you ignoring me

open shore
#

I think I'm missing the point lol

rotund token
#

if dont have physics velocity it doesn't simulate anything

#

in fact feel free to turn off the simulation system it won't be used

robust scaffold
rotund token
#

GetExistingSystem<StepPhysicsWorld>().Enable = false

open shore
open shore
robust scaffold
rotund token
#

purely for spatial lookups

#

so you can do Raycasts, SphereOverlaps

#

etc

open shore
#

I still don't see how it's gonna be threadsafe, run in parallel, and give me exactly the same result every single time

robust scaffold
#

Uhhh, physics integration and manifold resolution is inherently threadsafe.

#

Spatial partitioning can also be multithreaded. Raycasting is a read only operation so it's also threadsafe.

open shore
#

yeah it's threadsafe, but it's not gonna run everything in the same order every single time, one thread might always get ahead of the other, and in that case, nothing will break, but the execution order will be different

#

in 99.999% of the cases that's acceptable, but in my case I'd like to avoid that

robust scaffold
#

??? What? I think we have a critical communication disconnect on the fundamentals of computational physics simulation.

#

Why would execution order matter for physics?

rotund token
#

if you update the platform or characters position it doesn't matter because the physics position won't update till next tick

open shore
#

in one case the edge is still there when the character gets to it - so a coliision occurs,
in the other case the edge already moved - so the character just fell next to it

rotund token
#

doesn't matter what order you do

#

it's effectively double buffered

robust scaffold
#

All collisions are detected initially before any movement occurs.

rotund token
#

or that ^

robust scaffold
#

In that example scenario, the point in which the player collider checks if it will land on the platform is independent of order of detection.

#

Either it is already intersecting at that physics frame, or it's not.

#

Now the order will matter in continuous collision detection but those are dependent on the previous frame's position. In which case, you may have a "ghost" collision for that time step.

#

Dynamic-dynamic continuous collision is possibly the most complex aspect of a physics engine and it is a very very very deep rabbit hole on how accurate you want to have with those types of collisions.

open shore
#

that depends on how the physics are implemented. Let's say I'm using Unity's old CharacterComponent and I have two gameObjects that call the Move function. They both collide with a wall because of that movement. What will be the order of execution:

  • first object moves -> collision event called -> second object moves -> collision event called
  • first object moves -> second object moves -> first event called -> second event called
#

If the second order is the correct one, then yeah, multithreading should be fine

robust scaffold
open shore
#

so when will the events get called, in the next tick, or in the same tick after the physics calculations?

robust scaffold
#

The actual order, for box2D at least, is Spatial partition -> Check for collisions -> Resolve collisions (move objects apart) -> Integrate forces into velocity and then onto the change in position.

robust scaffold
open shore
#

okay that's great news, I can use multithreading

#

but since I'm running my "physics" on a fixed interval, is there a way to make unity's physics run on the same interval as well?

#

From what I understand, the current temporary solution for a FixedUpdate in dots is to update the systems manually through gameobjects, can I do the same for Unity's physics systems?

robust scaffold
open shore
robust scaffold
robust scaffold
open shore
#

oh is that a simple solution? ok I guess I'll be able to figure it out then

robust scaffold
#

I dont know what you want. It seems like you're trying to think of DOTS as it was object oriented / monobehaviors. But it's not.

open shore
# robust scaffold I dont know what you want. It seems like you're trying to think of DOTS as it wa...

not at all, I just watched this the other day but maybe it's an old video https://youtu.be/CA8GssG0HVQ

๐Ÿ“Œ Unity Sample Projects: https://tmg.dev/ECSSamples ๐Ÿ“Œ
๐Ÿ’ป My Game Development Setup: https://tmg.dev/GameDevRig ๐Ÿ’ป
๐Ÿ’ฌ Join the conversation with other ECS developers at https://tmg.dev/discord ๐Ÿ’ฌ

๐Ÿ‘‡ See below for time stamps ๐Ÿ‘‡

  • 0:00 - Introduction and Project Overview
  • 1:30 - Theory of Fixed TimeStep Workaround
  • 2:27 - Unity Project Setup
  • 2:55 ...
โ–ถ Play video
#

oh yeah... published on 2020...

robust scaffold
#

that was from 2 years ago, and I'm fairly certain FixedStepSimulationGroup was released before that

open shore
#

I guess I should stick to Unity's official docs for information

robust scaffold
#

Yes. I recommend that, the official samples, and reading the source.

open shore
#

Got it. now back to my original issue - finding an alternative to StateMachines in a data-oriented environment.

rotund token
#

Is an up to date tutorial

open shore
#

I'll read it, thanks!

robust scaffold
#

Tertle, dont you have a dots state ai?

#

or was that some other guy?

rotund token
#

My Ai is a graph based utility system

#

I only use state machines for game states (menu, game, options etc)

#

I do have an I guess automated component based state machine

#

basically turns a component with a bit field (of any size) and then automatically assigns components to each bit

#

that will add/remove as the bit field changes

open shore
#

I'm not sure if I'll decide to go with a state machine but I'd still love to read the code, is it opensource?

rotund token
#

there's 2 types

#

1 where you can only have 1 state active at a time

#

and another where you can have multiple states active at a time

#

basically it maps 1 bit to 1 system

#

i don't use this that much outside of game level states

open shore
#

yeah that's definitely going to help. ty!

rotund token
#

because component changes don't scale to the 6-7 digits of entities i benchmark with

#

but its very acceptable at 5 digits

#

(good chance it has a dependency on something else in my library so won't compile out of that bat)

open shore
#

I'm probably just going to read the source so it's ok. But @ me if you ever decide to properly publish it

rotund token
#

tldr:
implement 1x StateSystemBase or StateFlagInstanceSystemBase which controls the components
then implement N x StateInstanceSystemBase or StateFlagInstanceSystemBase which assigns a component to each bit and put your component login in that (technically you can just implement the interface if you'd prefer to set it up differently)
-edit- just realized my documentation on StateFlagSystemBase is a lie

pliant pike
#

I understood some of those words leahS

#

I really need to up my programming skills

rotund token
#

it's some interesting code

misty wedge
#

Why does DynamicBuffer implement IEnumerable if it's not implemented?

#

Is it because of the implementation for NativeArray.Enumerator?

tropic venture
#

Regarding "Performance by default" why not automatically make everything entities by default? At least on new projects, and/or at least as an option enabled by - drumroll - default, which can be opted-out from if desired

#

Is the ultimate goal of dots/ECS to replace the object oriented system? Will it eventually fully work with scene editor etc.?

#

I'm just a bit bothered by all the steps & scripts & "red tape" needed to go through in order to make use of the world of ECS, and hoping/wishing it would be "first class citizen" in Unity, working the ECS way by default with ease, just as the object oriented system works now

misty wedge
tropic venture
#

sad...

misty wedge
tropic venture
#

Will it be reconsidered once ECS is well established?

misty wedge
#

I don't think so. Not everyone wants to use an ECS to write game code

tropic venture
#

Aw man...

misty wedge
#

Why is that an issue for you?

#

You can use ECS if you want to, nothing is stopping you

tropic venture
#

They should make an alternate scene editor view maybe, for those who want first-class ECS Unity

misty wedge
#

I mean that part will eventually come, I didn't say they won't make it a first class experience, just that it won't replace the MonoBehavior workflow

#

There were plans to make a DOTS-only version of the editor which tied into project tiny, but nobody is quite sure what the progress is on that one afaik

tropic venture
#

so sad how a great technology has to be held back because of nostalgic userbase... Yes an alternate editor version for dots would be ideal

misty wedge
#

I mean it's not just nostalgia. Some people just want to write OOP code

tropic venture
#

so make them 2nd class ๐Ÿ˜† they should be the ones needing to write converters & authoring components etc

misty wedge
#

And alienate their entire userbase, sounds like a good plan thonk

tropic venture
#

so don't make dots 1st class? Also a sad bad idea

misty wedge
#

You can make both 1st class...

tropic venture
#

Obviously both should be 1st class

#

Right

misty wedge
#

But I'm not super up to date on that, others here can probably comment further

tropic venture
#

that's the part I'm miffed about... def looking forward to dots being 1st class not conversion & all that

misty wedge
#

Like I mentioned, I'm not sure if that's ever going away

#

I recall reading something about that being the intended workflow, but I don't remember where

tropic venture
#

Sure they can keep the conversion workflow for those still coming around. But there should also be a ECS-by-default editor

#

it's ok to make dots/ecs 2nd class with conversion workflow etc. - but why also stifle those who wanna go full-on only ECS? Should have a 1st class editor for that too, doesn't need to mutually exclude each other

misty wedge
#

I think eventually it will be a thing, but no idea how far they will go with it. Project tiny was originally meant for games-in-ads as a use case, not for a AAA experience. But who knows what they have planned ๐Ÿคท

tropic venture
#

Every once in a while a technology gotta re-think "if we created Unity from scratch today, how would we do it much better?" And once every decade or 2 you gotta consider doing a significant rewrite... Otherwise the ecosystem gets kinda stuck/stifled/left behind in many regards

viral sonnet
#

the need for a dedicated editor has vanished with the authoring/subscene workflow

misty wedge
#

^

#

I think they will eventually revive tiny regardless, just for the use case, but it will probably be focused on small experiences (e.g. only 2D physics, etc)

tropic venture
#

But it needs a LOT of scripting red tape, no? If it was "1st class" it would be a lot more streamlined wouldn't it?

misty wedge
#

It's not a huge amount of boilerplate

#

You just define your data and how it is converted

#

There's lots of places in ECS that require more boilerplate atm imo

viral sonnet
#

wdym? if you are getting at the missing animation package or smth, okay. it will be released eventually. prioritizing entities at this point when it's not even at 1.0 makes little sense

tropic venture
robust scaffold
misty wedge
#

I haven't checked 2023.1A though, so that's good to hear

robust scaffold
robust scaffold
misty wedge
#

haha

viral sonnet
#

boilerplate is minimal. anything more specific? data has to be defined. systems have very little boilerplate, same goes for jobs.

robust scaffold
misty wedge
#

Yeah, my thoughts too

#

I hope they can improve that in some way

viral sonnet
#

and unity is lagging behind bringing core systems to dots. at some point the gap will be closed. then there will be more development again in tiny and the editor. although i think tiny will be deprecated on the way

robust scaffold
# misty wedge I hope they can improve that in some way

What they need to do is create a codegen version that passes in raw pointers and batch count. That's the bare minimum rather than the current handholding and unoptimized mess that is IJobEntityForEach or whatever it's called

tropic venture
robust scaffold
#

Well ya, it is script heavy. But ECS itself is not really a newbie friendly coding style.

tropic venture
#

That's what i mean that the need for a dedicated editor has not really vanished

#

Unity has awesome appeal to ppl wanting to try their hand at it, and dots/ecs has amazing promise for performance, but the ease of tools is missing for dots/ecs

misty wedge
#

I don't personally see the current way it works as an issue. The boilerplate required for conversion pales in comparison to classic authoring time editor tooling that large games require

robust scaffold
viral sonnet
#

maybe i just don't see what a dedicated editor can bring to the table. it won't help with coding.

misty wedge
#

That's also something I like, you can put as much authoring crap and functionality on your authoring gameobjects as you want, once the game is actually running and converted it's gone

tropic venture
#

Ye I'm not entirely sure about that myself... But was guessing/hoping there were indeed a bunch of steps/boilerplate which Unity can actually just do by itself automatically by defualt, or something... And only needs scripting intervention just for the specific aspect of how to cut up data & behavior systems

viral sonnet
#

that's where the IJobEntity, Entities.ForEach helps. with code generation

robust scaffold
#

How to format your data and system structure is completely up to you. Unity isnt there to code your game for you.

misty wedge
#

A lot of people aren't happy with all the black magic unity already does for you, and actually want less

robust scaffold
misty wedge
#

Yeah, I'd agree too

tropic venture
misty wedge
#

Eventually you need to work with raw memory anyways

tropic venture
misty wedge
#

Those kind of people flock to monobehavior first, since you can build 99.9% of indie projects with it i'd argue

tropic venture
#

except - why would you? If it were possible to build the same game with same/similar editor, but in dots/ecs

misty wedge
#

Because people like writing OOP code

tropic venture
#

convert all monobehavior Update() methods to systems

misty wedge
#

It's a very different convention

#

That's not how that works ๐Ÿ˜…

viral sonnet
#

oh boy ... that discussion

misty wedge
#

Yep

#

Like that one guy on the forums

#

I forgot his name

viral sonnet
#

i think it was AcidArrow ๐Ÿ˜„

#

it's impossible to do that.

misty wedge
viral sonnet
#

unless we have AI that can program itself

tropic venture
#

Think different

#

๐Ÿ˜†

misty wedge
#

This is from the docs

viral sonnet
#

the last stage to singularity ๐Ÿ˜„

robust scaffold
#

I'm currently stuck on conversion myself TBF. DOTS is suppose to be an entity driven system but using the built in 2d physics, that means it's a GO driven architecture and conversion really isnt intended for that.

tropic venture
#

How would they have implemented dots/ecs if the community didn't push them back into the conversion workflow, and why can't we still have that as an alternate option of building with dots/ecs

misty wedge
#

I mean we can't know, maybe they would have gone with this approach anyways. No point in theorizing about what could have been

misty wedge
robust scaffold
#

So I need to conduct movement actions on GOs and then pull that data to the TRS components on entities.

misty wedge
#

I'd argue that's an issue separate from the conversion workflow, more like an issue with hybrid DOTS atm

robust scaffold
#

Yea. And Unity made the companion link component type internal to Entities for some fucking reason.

misty wedge
#

I have a similar gripe at the moment. I'm working on some simple runtime inspection of entities, and there is no GetComponent that takes a ComponentType because Unity doesn't want people to "accidentally" use the slow version, so they just don't put it in at all and force me to use reflection...

robust scaffold
#

yeaaaa, pain

misty wedge
#

Like, if that's the issue, hide it in some weird static utility class or something...

viral sonnet
#

i've written some scripts to handle hybrid. i don't like having to do that myself. some streamlined version from unity would be great instead of everyone rolling their own. and yeah, going from MB to entities is weird. especially when there are some edge cases where it goes from MB->entities->MB. this really sucks

misty wedge
#

I think that's mainly stemming from the fact that it just isn't finished. I hope they have all of this sorted out with 1.0

#

(although I doubt it)

robust scaffold
misty wedge
#

I rarely check development updates, that's what I assumed

robust scaffold
#

There are 0 examples of any hybrid interactions in the training github. If they're not training people on how to use hybrid dots, that means they're not ready to indicate that hybrid is production ready

misty wedge
#

I meant more along the lines of, make it less mandatory to go the hybrid route if you want stuff like sprites, 2D physics, etc

viral sonnet
#

hybrid was on their roadmap for 1.0

robust scaffold
#

Sorta? Kinda? Extremely vague on how they're gonna do it.

misty wedge
#

"It just works."

robust scaffold
#

Todd? Is that you? 15x the detail?

misty wedge
#

Yes, and there will be a new editor tab that will just be an instance of skyrim, integrated into the engine.

robust scaffold
#

Basically just a GO with a wrapper entity at this point

safe lintel
#

i think its better to just manage the companion stuff manually unless those gameobjects will never be destroyed/instantiated

#

(and I never use 2d so not sure how tilemaps are used)

robust scaffold
#

I got my own GO -> Entity sync. Otherwise these are all just references to the components.

#

References to skip using .GetComponent<>() on the CompanionLink GO which is a reflection find.

safe lintel
#

i mean if it has a companionlink on it, it is still governed by the builtin companion update systems isnt it?

misty wedge
robust scaffold
robust scaffold
robust scaffold
#

It's annoying that I cant get rid of them but they're just tags so they dont take up chunk space.

safe lintel
#

I skip touching companion anything for my entites that rely on gameobjects. gameobject is a prefab that gets instantiated and then pooled so I can create/destroy entities and reduce gc to a bare minimum of one class component(and then just access attached gameobject components from that one icd). could probably do something to manage them without even adding a class component reference but currently it is acceptable for my use

robust scaffold
devout prairie
#

Hey folks i was wondering if someone could help - how do interpret this in particular the Semaphor.WaitForSignal - what is that and i'm guessing it's not great that it's taking up so much time in this stress test..

robust scaffold
devout prairie
#

a lot of physics steps

rustic rain
robust scaffold
devout prairie
#

bit more zoomed in and showing jobs

robust scaffold
#

Well, there's ya issue. Blockman targeting system is quite expensive

#

and not well optimized.

devout prairie
#

okay yeah i was wondering about that

robust scaffold
#

For one, it's a lambda job. Which means if you want to start optimizing, break out the copy paste and refactor it into a IJobEntityBatch.

devout prairie
#

when i look in hierarchy for that system it's not showing up as taking a lot of time:

#

but i don't think this reflects the jobs themselves right

robust scaffold
#

The timeline is always correct. Hierarchy is ehhh

rustic rain
#

why even look at hierarchy with threaded code

safe lintel
#

the system doesnt take much time to schedule the job but the job itself takes time

devout prairie
#

right yeah

devout prairie
#

finally

#

at long last

safe lintel
#

do you need to run it inside the fixedstep group?

misty wedge
rustic rain
#

unless you use chunk specific optimizations

robust scaffold
misty wedge
devout prairie
rustic rain
misty wedge
#

Are there any DOTS specific optimization guides? I don't think I've ever seen any

rustic rain
#

probably burst related ones

#

like ensuring vectorization

quiet magnet
#

im not unity pro, so why am i getting this

#

A Hybrid Renderer V2 batch is using the shader "Universal Render Pipeline/Lit", but the shader is either not compatible with Hybrid Renderer V2, is missing the DOTS_INSTANCING_ON variant, or there is a problem with the DOTS_INSTANCING_ON variant.

#

also getting this issue, not sure where the fix lies

vital sandal
#

nm... was my mistake. * totally works... lol

quiet magnet
#

Note: Shader Graphs and shaders that Unity provides in URP and HDRP support DOTS Instancing

#

so what am i missing, latest URP installed

#

ah wait there i thought 0.51 is compatible with 2021.3 LTS. I guess not hehe

quiet magnet
#

oh right, so why these errors

rotund token
quiet magnet
#

every time after the havok subscription warning

rotund token
#

If you only see this once rarely it happens because the variant hasn't compiled yet

#

It should be fixed in 1.0

#

As long as you can see stuff of screen there's no issue

quiet magnet
#

ok well im trying to open it as a new project. initially i was adding it to a project, but must have a wrong version somewhere

#

right so, semi working

#

it seems the shader works in editor, until i press play, then get the pink shader of error

devout prairie
#

Just started getting this randomly on my random array of length=workers

#

after moving the system from fixed step to the simulation group

pliant pike
#

perhaps an order issue, i usually interpret that as the array has no values assigned

rotund token
#

wish they'd just debug.logerror

#

instead of throw exception -_-

balmy thistle
#

Why

rotund token
#

If they log the error first you can see it from burst

#

Instead of just getting an exception with the format string and no data

balmy thistle
#

Ah, gotcha

robust scaffold
#

Alright, found a use for the runtime conversion pathway: Hybrid DOTS.

#

Baked conversion makes GOs that are not added to the global update sequence. For example, setting a velocity on a rigidbody GO component of a hybrid entity will not move the object

#

However, using the runtime conversion (not the subscenes), the clone GO will work

robust scaffold
#

Looking at this for my GOs

#

And this for my entities. Everything seems to work pretty well for a hybrid format

stiff mesa
#

Hey everyone (especially tertle)! I'm using your event system for dots and I wanted to ask: does ConsumeEventSystemBase actually consume the event (as in destroys it and not let it through)? What I mean: if I have three systems that consume the same event, System1, System2 and System3, will Systems 2 and 3 receive the event or will it stop at System1?

rotund token
#

no

#

all systems will receive the event

#

i guess poor naming but i just like the name of produce/consume ^_^'

stiff mesa
#

Thanks!

viral sonnet
#

huh, I thought I'd be crafty and use a class IComp for a singleton and now GetSingleton only supports structs

rotund token
#

@viral sonnet there totally is extensions for this built into entities

#
    public static unsafe class ComponentSystemBaseManagedComponentExtensions
    {
        /// <summary>
        /// Gets the value of a singleton component.
        /// </summary>
        /// <typeparam name="T">The <see cref="IComponentData"/> subtype of the singleton component.</typeparam>
        /// <returns>The component.</returns>
        /// <seealso cref="EntityQuery.GetSingleton{T}"/>
        public static T GetSingleton<T>(this ComponentSystemBase sys) where T : class, IComponentData
        {
            var type = ComponentType.ReadOnly<T>();
            var query = sys.GetSingletonEntityQueryInternal(type);
            return query.GetSingleton<T>();
        }

        /// <summary>
        /// Sets the value of a singleton component.
        /// </summary>
        /// <param name="value">A component containing the value to assign to the singleton.</param>
        /// <typeparam name="T">The <see cref="IComponentData"/> subtype of the singleton component.</typeparam>
        /// <seealso cref="EntityQuery.SetSingleton{T}"/>
        public static void SetSingleton<T>(this ComponentSystemBase sys, T value) where T : class, IComponentData
        {
            var type = ComponentType.ReadWrite<T>();
            var query = sys.GetSingletonEntityQueryInternal(type);
            query.SetSingleton(value);
        }
    }
#endif```
#

In ComponentSystemBase.cs line 658+

elfin spire
#

does any of you run on the apple silicon? burst 1.7.2 seems broken on this version of the editor and was wondering if you knew one that's not

viral sonnet
#

ok got it, i need to use this.GetSingleton

#

no idea why it needs this in front.

rotund token
#

because it's an extension method

#

(i forget that was required because I use this as standard ^_^')

viral sonnet
#

oh ... right. of course. i'm getting sleepy ๐Ÿ˜„

dull scroll
#

Hello,
I tried to update Angry Bots to 2021.3.8f and Dots 0.51 version. Here is the repo: https://github.com/kharalos/AngryBots_ECS_2021.3

I managed to convert the code and use URP and the scene works but the player creates a clone of itself in the hierarchy and makes the controls junky. If I disable the clone after the scene plays then everything works fine. I tried to understand why it happens but failed. Can anyone help me?

rotund token
#

that is a very old project to be updating!

dull scroll
#

that is correct ๐Ÿ˜„

#

I did it to learn

rotund token
#

is your problem you don't know why it's making a clone?

dull scroll
#

yes

rustic rain
dull scroll
#

should I just not use it on the player?

rustic rain
# dull scroll

convert and inject creates clone of original game object

#

while creating entity

dull scroll
#

so at the end you have 1 original game object 1 clone game object and 1 entity?

errant hawk
#

is there a math function I can use to determine the angle (or radians) difference between two quaternions?

rustic rain
dull scroll
#

I see

karmic basin
# misty wedge Are there any DOTS specific optimization guides? I don't think I've ever seen an...

There's the best practices course, if you haven't already seen it https://learn.unity.com/course/dots-best-practices

Unity Learn

If youโ€™re working on a game (or other real-time simulation) that requires the most efficient CPU usage possible, then Unityโ€™s Data Oriented Technology Stack (DOTS) is a great way to get the performance you need. However, to use DOTS successfully, you canโ€™t simply grab the API documentation and dive straight in. Before you begin creating a projec...

karmic basin
errant hawk
karmic basin
#

you could reimplement your own dots version based on the source

        // Returns the angle in degrees between two rotations /a/ and /b/.
        [MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
        public static float Angle(Quaternion a, Quaternion b)
        {
            float dot = Mathf.Min(Mathf.Abs(Dot(a, b)), 1.0F);
            return IsEqualUsingDot(dot) ? 0.0f : Mathf.Acos(dot) * 2.0F * Mathf.Rad2Deg;
        }

        // Is the dot product of two quaternions within tolerance for them to be considered equal?
        [MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
        private static bool IsEqualUsingDot(float dot)
        {
            // Returns false in the presence of NaN values.
            return dot > 1.0f - kEpsilon;
        }

https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Math/Quaternion.cs#L169

rustic rain
#

dot product*

fluid compass
hot basin
#

wow... was Rival bought out by UT?

robust scaffold
#

Huh.

#

Seems pretty robust but it's 3D. Shame.

rotund token
#

Interesting. Wonder if he was hired by unity but I see no evidence of that yet

karmic basin
#

Damn I paid for that asset xD

rustic rain
#

Is that asset source free?

robust scaffold
quiet magnet
#

Can burst/entities build to mono?

#

IL2CPP never compiles for me these days

balmy thistle
#

Yes, but what's your il2cpp problem

quiet magnet
#

maybe next time. i tried some of the ecs samples

#

tbh think i might be running out of memory on build, although i have 32gb

#

i found the boids example interesting, was wondering what its like on build. il2cpp multiple issues, mono build no entities show

#

ill try one more build, but its not going to build im sure!

#

subscene concept is interesting, assume i need to include in build

#

warnings on mono build and no show on entities (or subscenes)

#

ok il2cpp actually built that time, for once

#

but crash on load

#

well i had hope lol

robust scaffold
#

IL2CPP must have the build for reduced file size to function

quiet magnet
#

rather than faster runtime?

robust scaffold
#

I dont remember the setting but yea. You have to toggle it on

quiet magnet
#

ok just trying that

#

nope

#

oh well

robust scaffold
#

No clue then

stone osprey
#

Passing stuff from the outside into a Entities.ForEach... does this allocate memory since its a closure ?

quiet magnet
#

@robust scaffold where do i get the error log on load?

robust scaffold
#

Development build?

quiet magnet
#

oh do you have to have it in dev mode

#

it comes up with the unity crash window briefly

#

Could not open file F:/Programming/Unity/Downloads/ECSSamples/Build/Boids CPP2/Jobs_Data/StreamingAssets/EntityScenes/e1e53224c62f2477ea66ccbee8043957.entityheader for read
Could not open file F:/Programming/Unity/Downloads/ECSSamples/Build/Boids CPP2/Jobs_Data/StreamingAssets/EntityScenes/9c5ff16a37c4a4220a0e7795b6c38c6d.entityheader for read
Loading Entity Scene failed because the entity header file couldn't be resolved: guid=e1e53224c62f2477ea66ccbee8043957

#

seems the problem is here

#

hmm there is no streamingassets folder?

robust scaffold
#

You must use the build pipeline, not the normal build

quiet magnet
#

so entity projects must use the platforms package to build always?

robust scaffold
#

Yes, for now. 1.0 DOTS will not need it

quiet magnet
#

@robust scaffold doesnt ask where i want it built to?

#

lets see what happens, but no idea where its building to

#

ok, Builds folder

#

and it crashes, oh well

#

maybe ill try again tomorrow ๐Ÿ™‚

#

Mon 2x builds, but not il2cpp (crash on load)

#

mono

#

interesting

#

normal IL2CPP that built, works, if i copy the streaming assets over

#

but yes pretty impressed with 25 mil verts, 4k at 60fps

#

on a gtx 970

#

cpu is also quite old but still powerful, 3930k 6core

#

at least i learn to use the build pipeline, just to get the streaming assets folder

robust scaffold
#

Huh, recent 2023.1A update has pushed documentation on IJPFT. Possibly the best documented IJPF variant now. And I was there when Unity threatened to remove it back in the day. Now it seems like it's a permanent addition, if they documented it and provided a code sample.

rotund token
#

well they're embracing hybrid so they kind of need this

robust scaffold
#

Still seems pretty clunky TBF. Would be nice if they added another API layer on top of TAA so I dont need to manually juggle and pool GO.Ts

safe lintel
#

huh good for phil to make something that unity decided to purchase. wonder what this means for the long term of the dots charactercontroller now

robust scaffold
#

hot compiling and reloading compute shaders is iffy

viral sonnet
#

oh, have to scroll up. nvm

#

huh, damn. paid for it. never used it. lol

#

great stuff though!

robust scaffold
#

Ya know, I wonder if a valid anti-cheat would simply have the entirety of the game logic and data located on the GPU. I'm pretty sure the majority, if not all, memory skimmers and cheat engines read from CPU memory. Assuming deterministic lockstep simulation using fixed point integer mathematics, current cheat engines would need to pull gpu memory and then parse the data in order to obtain hidden info. And that is pretty expensive. Anti-cheat through lagging the computer to the point where the game is unplayable.

#

You'll need to completely rewrite a gpu driven physics engine though. Practically write a gpu game engine at that point.

viral sonnet
#

hm, you don't have to go that far. what if you just store crucial values on the gpu and pull them for the cpu to read?

robust scaffold
#

Just something I thought up on the fly as I slowly grind my way through setting up rendering hooks.

viral sonnet
#

what do i use to run managed main thread jobs? i can't find it and i remember it's possible

#

i'd write normal main thread code but i don't want to use .Complete in the system

viral sonnet
#

job struct doesn't work with managed classes, right?

robust scaffold
#

It does, if you turn off burst.

#

The second you remove the [BurstCompile], you can do anything

#

Including using classes cross main-job boundaries and so on.

viral sonnet
#

huh, no idea where i got the error then. been a few days ๐Ÿ™‚ i'll try thanks

#

InvalidOperationException: RewardPlayerJob.inv is not a value type. Job structs may not contain any reference types. ๐Ÿ˜ฆ

robust scaffold
#

How did I manage to set shared component data inside a job then? hrm. Let me try

viral sonnet
#
        {
            public NativeList<MonsterDrop> monsterDrops;
            public Inventory inv;``` simple class here
robust scaffold
#

Hrm, I think I manually allocated the class using c#'s GCHandle, which is a struct, then converted it back to the class inside a job

#
GCHandle handle2 = (GCHandle) parameter;
List<string> list2 = (handle2.Target as List<string>);
``` Largely what I did to pass in classes. Burst compile must be off in order to use the class as well inside the job.
viral sonnet
#

how does Entities.ForEach do it?

#

like ```Entities
.WithoutBurst()
.ForEach((

            Entity entity,
            Animator animator,
            in Rotation rotation,
            in Velocity velocity
            ) =>
        {```
robust scaffold
#

True, how does the codegen look like?

viral sonnet
#

uses public Unity.Entities.ComponentTypeHandle<UnityEngine.Animator> __animatorTypeHandle;

robust scaffold
#

That can be used in a scheduled job?

#

not bursted of course

#

How do they get the actual class data?

viral sonnet
#

that i need to find out. tha compiled job uses .Run

#

var animatorAccessor = chunk.GetManagedComponentAccessor(__animatorTypeHandle, __this.EntityManager);

robust scaffold
#

huuuuuh. Interesting

viral sonnet
#

then just animatorAccessor[entityIndex]

#

where the index goes from 0 to the chunkCount

#

well, i already have the inventory i want to access on a singleton entity ๐Ÿ˜„

rotund token
rotund token
#

if you're writing IJob without burst and using Run

#

why write it as an IJob

viral sonnet
#

what's the alternative? i think i have been there. my previous solution was to run it in another system group

robust scaffold
#

So we dont need to go through GetEntityArray

rotund token
#

just create a method in your system it's the same thing

viral sonnet
#

well, i need to schedule as i have a dependency

rotund token
#

Dependency.Complete()
MyMethod();

robust scaffold
viral sonnet
#

hm, what's the reason i can't schedule a job with managed objects?

rotund token
#

fundamental restriction of the job system

#

it won't pin the managed objects

#

but holds the job as a pointer

viral sonnet
rotund token
#

if you want to pass managed objects in, pin them and pass in a pointer to them

robust scaffold
#

This works, somehow.

rotund token
#

it's literally just calling the execute method on the main thread

robust scaffold
#

But it does work, somehow.

rotund token
#

yeah i have a wrapper for that

#

you know you can do that in a thread?

robust scaffold
#

It defies all logic I know about job thread boundaries.

#
new DisposeJob
{
    FluidData     = state.EntityManager.GetComponentTypeHandle<FluidData>(false),
    EntityManager = state.EntityManager
}.Schedule(_fluid).Complete();
``` Yea, it works.
rotund token
#

i mean without even completing it

robust scaffold
#

I still need to complete since Im doing a structural change right after

rotund token
#

but yeah

#

for your case

robust scaffold
#

Absolutely magical. I have no clue what black magic unity did on the back to make it possible.

rotund token
#
    public unsafe struct SharedComponentDataFromIndex<T>
        where T : struct, ISharedComponentData
    {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
        private readonly AtomicSafetyHandle m_Safety;
#endif
        [NativeDisableUnsafePtrRestriction]
        private readonly EntityDataAccess* m_Access;


#if ENABLE_UNITY_COLLECTIONS_CHECKS
        internal SharedComponentDataFromIndex(EntityDataAccess* access, AtomicSafetyHandle safety)
        {
            m_Safety = safety;
            m_Access = access;
        }

#else
        internal SharedComponentDataFromIndex(EntityDataAccess* access)
        {
            m_Access = access;
        }
#endif

        public T this[int index]
        {
            get
            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                AtomicSafetyHandle.CheckReadAndThrow(m_Safety);
#endif
                return m_Access->GetSharedComponentData<T>(index);
            }
        }
    }```
#

i have this, you could totally write one for managed components as well

#

you can't use entity manager if you don't complete though

rotund token
#

because it breaks as soon as next system tries to use it

rotund token
#

but yeah if you use EntityDataAccess* instead of EntityManager it works fine to schedule it across systems

robust scaffold
#

Readonly, yea. Makes sense. How is this created?

rotund token
#
        public static unsafe SharedComponentDataFromEntity<T> GetSharedComponentDataFromEntity<T>(this EntityManager entityManager, bool isReadOnly = true)
            where T : struct, ISharedComponentData
        {
            var access = entityManager.GetCheckedEntityDataAccess();
            var typeIndex = TypeManager.GetTypeIndex<T>();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            var safetyHandles = &access->DependencyManager->Safety;
#endif

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            return new SharedComponentDataFromEntity<T>(access, safetyHandles->GetSafetyHandleForComponentDataFromEntity(typeIndex, isReadOnly));
#else
            return new SharedComponentDataFromEntity<T>(access);
#endif
        }```
#

extension method

#

it's actually writable if you want

#

good for writing data to RenderMesh

#

without a sync point

robust scaffold
#

Oh, the entity manager just is used to pull entityManager.GetCheckedEntityDataAccess(); Thats basically what unity is doing.

rotund token
#

well ok not a good example

#

that requires unityengine which requires main thread

robust scaffold
rotund token
#

i'm not doing a set component

#

but if the shared componetn has a managed object

#

and i change a value

#

there is no structural change

#

but the write handle makes sure this is safe

#

(within entities)

robust scaffold
#

Shared components rely on IComparable to ensure no collisions. I guess if you modify something outside the comparison, that wont be a structural change.

rotund token
#

well yeah but your IComparable usually would depend on the reference equality

#

not the actual data within it

robust scaffold
#

true, huh. Interesting

#

This seems really easy to extend into unmanaged shared components. At least a readonly functionality while still able to modify NativeArrays and other reference types. Why hasn't unity done this yet?

rotund token
#

i'm sure you could do some dumb things

robust scaffold
#

I can already do a lot of dumb things with the pointers available.

#

Jesus christ unity. Class name already breaks the max character limit.

#

I wonder, why use DynamicComponent when I can just use a generic job?

#

Damn, I thought I was onto something

rotund token
#

if you know your type you should be able to use a generic job fine

robust scaffold
#

Nah, it doesn't like creating a component type handle with generic component type.

rotund token
#

i do this

#

why not?

#

what is idx

#

oh you're doing it through entitymanager instead of system

robust scaffold
#

yea

#

System doesnt allow for managed component types... well in this case it shouldnt matter

rotund token
#

works fine

robust scaffold
#

It has to be part of a job schedule assignment

rotund token
#

yeah your idx

#

what is it

#

your AddTransforms generic doesn't seem to match

#

unmanaged

#

not struct

#

you are passing a struct generic

#

which might not be unmanaged

robust scaffold
#

Just changed that

#

Both are unmanaged to get the most narrow equality

#

Error's unchanged

rotund token
#

you're missing your generic on your job

#

AddTransform<T>

robust scaffold
#

Ah ha

#

I thought it could be implicit

#

but that fixes it, thanks

rotund token
#

(btw burst is going to complain about this)

#

(unless you cleverly create it)

robust scaffold
#

It uses managed components. It's not bursted

#

It's pulling the companion link game object's transform and adding it to the transform access array

rotund token
robust scaffold
#

Just wild.

#

Looks like this doesnt work sadly

#

It compiles sure but the reflection throws error

#

Actually thats not the issue. hrm

rotund token
#

oh hmm yeah i think the same generics rules apply even if you're not using burst these days >_>

robust scaffold
earnest spear
#

hi

#

im new here

robust scaffold
#

Well fuck, guess this wont work anyways since a private field of transform access array is not prefixed with NDUPR

earnest spear
#

i'd like to mod 3d model games like stumble guys

#

i search everything in youtube but i never found 1 that works

robust scaffold
earnest spear
#

where to do that actually?

#

ah ic thanks for your help ๐Ÿ˜„

rotund token
robust scaffold
rotund token
#

oh wait you can't even do that

#

without burst

#

haha

robust scaffold
#

yea. there's the toggle within burst.

rotund token
#

time to reinterpret and make your own copy with attributes

robust scaffold
#

pain

#

I think I'm just gonna stick with the slow non-job'ed version. The second I need to make my own wrapper copy is a bit too far.

rustic rain
#

It's not scheduled anyway

#

I think...

#

So you can probably get away with generic chunks iterator

devout prairie
#

alright help me out here, what am i missing..

#

when the simplest thing suddenly causes problems moment,

#

i moved this system into fixed step to diagnose raycasts not detecting hits

rotund token
#

Not really sure what you're showing us

#

Things missing if usually causes by bad layers

#

Either your belongs to or collides with

devout prairie
rotund token
#

Oh whoops didn't see that on my phone

#

If there no second exception?

#

This usually happens from another exception and the system exiting early

devout prairie
#

no

#

it's kindof weird tbh

#

restarting the editor, was just having some lunch

#

yeah still doing it

#

i figured i was just missing something obvious

rustic rain
#

hmm

#

is it possible to create your own Job interface extension?

viral sonnet
#

yeah, tertle wrote some ๐Ÿ™‚

rotund token
rustic rain
#

any example to share?

rustic rain
#

interesting

#

this is pretty cool actually, cause that means you can use Job system for custom ECS

devout prairie
#

The problem is both systems are RegisterPhysicsRuntimeSystemReadOnly() and i'm not writing to the world.Bodies array

#

i am reading the Bodies though

rotund token
#

If you're updating inside fixed update you still basically have to order your systems properly

#

Physics is a big reason why I'm strongly against coupled systems

#

It's so painful to use

devout prairie
#

yeah i get that, i can't see any issues with the ordering, or why it's complaining that i'm writing to bodies

rotund token
#

What are your orders

#

Update after build / step?

devout prairie
rotund token
#

I think project needs to update before export

#

Err

#

Before end frame

devout prairie
#

hmm i'm pretty sure i've copied the ordering in the collision system from the samples, it's basically just a bastardization of their stateful collision event setup

#

but again, i'm not writing to the bodies at all

#

the collision system works fine etc

#

issue is it thinks i'm writing to the bodies in that system

rotund token
#

It doesn't know you're not writing

#

It's accessing on main thread

rotund token
devout prairie
#

well i've just arbitrarily set projectile system to run after the collision system

#

hmm physics samples actually orders their stateful job like this:

rotund token
#

But you say both are reading

#

But you've ordered them differently

devout prairie
rotund token
#

Projectile can satisfy updating after blockman while also updating after end frame

#

While blockman must update before end frame

#

So either you're saying blockman doesn't need update before or you should add an update before to projectile

#

I'm not certain this will fix your issue, I'm just pointing out an inconsistency with your ordering

devout prairie
#

hmm i'm not sure that matters at all

#

i get what you're saying, the first job is set to run before end frame, whilst this isn't specified in the second job.. but it doesn't matter, they still order as expected:

#

so i guess i need to figure out why it thinks i'm writing to bodies, when i'm not

rotund token
#

Show scheduling code for blockman

devout prairie
#

1 sec, trying what you suggested in any case ๐Ÿ˜›

#

same, so basically this:

#

i guess it could be that Job, but again, it's only reading from not writing to bodies

rotund token
#

You're ignoring the part where it doesn't know that

#

The read only tag is used by burst

devout prairie
#

well that's what this if for right:

rotund token
#

That's the interesting thing here I'm thinking about

#

If they're both read only

#

They can both execute at same time

#

But it shouldn't matter because as you say, no writing

devout prairie
#

when i add a dependency to that Job above, to ensure it 100% is linked up in the dependency chain with the CollectCollisionEvents job, it makes no difference as expected

rotund token
#

Convert collision etc etc could you should the schedule part

devout prairie
#

so obviously it thinks i'm writing to bodies in this collision system, and i need to figure out why and how to tell it i'm not

rotund token
#

Are you not missing withreadyonly(bodies)

devout prairie
#

hmmmmmmmmmmm

#

maybe

#

damnit i think you're right

#

YEP

#

holy damn

#

it never occurred to me for whatever reason, that i'd need to specify that, or i've simply just overlooked doing it

#

as it was set to RegisterPhysicsRuntimeSystemReadOnly

#

thanks @rotund token ๐Ÿ™‚

rotund token
#

Ok good because it's way past bedtime and I'm sick and need to sleep

#

Have a good day

devout prairie
#

Cheers, hope you're feeling better tomorrow.

stone osprey
#

When i pass something into a Entities.ForEach from the outside... does this allocs memory since its actually a lambda ?

devout prairie
stone osprey
#

Oh shoot, thats why system generates like 1.5mb per call

#

Damn and how the heck can i pass stuff into it without generating tons of garbage ?

devout prairie
#

what is it exactly you're doing?

rustic rain
#

well, depends actually on what you're passing

#

cause native array is passed by value, but it's not literal value of all elements, but just pointer

stone osprey
#
            // Initialize and spawn a prefab/gameobject with network transform and rotation
            Entities.ForEach((Entity entity, ref Mesh mesh, ref NetworkTransform networkTransform, ref NetworkRotation rotation) => {

                if (!mesh.instantiate) return;
                
                var contentStorage = Database.GetContentStorage(mesh.id);
                var goContent = contentStorage.Get<GameObjectContent>();
                var prefab = goContent.Representation;

                // Spawns gameobject asset and assigns it to the component
                var pos = networkTransform.pos.AsUnityPosition(mercator, Map.WorldRelativeScale);
                var handle = prefab.InstantiateAsync(pos, rotation.value);     
                
            }).WithAll<MeshAdded>().WithoutBurst().WithStructuralChanges().Run();

Little example of my method, running on the main thread and its use is to spawn in gameobjects for me.
Database is actually existing outside of the loop... mercator too...

rustic rain
#

and what is Database?

#

struct? class?

stone osprey
#

A class, sorry forgot to mention... mercator is a struct however

rustic rain
#

class is passed by reference

#

struct is copied by value

stone osprey
#

But in case of a closure/lambda both should be copied right ? Atleast i know that closures and putting stuff into closures is pretty bad for gc

rustic rain
#

lamba is fake

#

in reality it's codegened into direct method

devout prairie
#

it maybe be the Instantiate that's generating garbage

rustic rain
#

and all locals that you use in lambda

#

become fields in job struct

devout prairie
#

you tried running without just that last line ( var handle = ) to see if it avoids the garbage

stone osprey
#

Hmm thats actually great i think... and yes the instantiate creates garbage, theres no way around it. But my profiler tells me :

#

Damn i dont have the profile anymore... atleast it told me that there happens many many Gc.Allocs inside there for some reason. The instantiate calls however were listed seperatly

devout prairie
#

it's kinda hard to guess what you're getting back from any of these lines tbh:

var contentStorage = Database.GetContentStorage(mesh.id);
var goContent = contentStorage.Get<GameObjectContent>();```
#

not familiar with those

stone osprey
#

Did a deep profile looks like i was wrong

#

Looks like ALL the allocs are really happening from the adressables stuff

#

Kinda sucks, thought the adressables speed up things

rustic rain
#

they do?