#archived-dots

1 messages · Page 189 of 1

pulsar jay
#

especially if the attacks in this example require different data. e.g. the rangedAttack has a projectile and the melee does not need one

amber flicker
#

one option is to not make them exclusive

#

if the rest of your systems behave as expected, it shouldn't happen right? Relying on exclusivity to sort out the issue comes with its own problems.

pulsar jay
#

yeah guess you are right

#

I think its more of a design thing

#

so I would like to prevent the game designer from adding multiple attacks

amber flicker
#

I'm an "anti state machine" person and I recognise I don't have much company 😅 - I find them useful conceptually and almost always problematic in practice.
I think it's reasonable to prevent a designer from adding multiple - but I'd say you can easily do that through editor tooling. A dropdown for example.

pulsar jay
amber flicker
#

it's easy to e.g. have all your authoring components extend from a class that checks the gameobject only has one of them in OnValidate... not sure I'd pick that particular approach but that's how easy it could be.

pulsar jay
#

I have a hard time not thinking in states. I mean even scenes or menus are "states"

pulsar jay
amber flicker
#

That works too. I have never ever seen (or written) a state machine in the wild that didn't end up having a mixed state or hidden state of some sort. Even menus in any more complicated than a game-jam sense. Anyway.. don't want to start a tab v spaces thing here 😬

pulsar jay
#

I have definitely have an opinion on tabs v spaces 😉 On state machines, not so much. I rather use them because I dont know of any better solutions for some cases. Would be eager to learn how to handle it differently though but I dont want to steal more of your time 😄

#

Thx for your help again

amber flicker
#

My approach is 1) simplify -> iterate -> simplify - do you really need different data? 2) Make a matrix of exclusive & mutual states - try to turn this into a hierarchy and choose the best method for that data - e.g. usually Tag, bool or enum.
When you start it's easy to go straight to Melee Attack, Ranged Attack & Magic Attack but after iteration I it might look a little more like a single ICD with e.g. float attackRange;, Entity effectPrefab; int AnimationIndex;

pulsar jay
#

Iteration is actually a pretty good point. I guess I tend to overthink the architecture and plan ahead quite a lot. Now that I started to actually implement some stuff there is a lot of "bad" ecs code which is not extensible but on the other hand it is pretty quick to refactor it.

amber flicker
#

Yea with practice I think I'm getting a little better but I think it's really hard to get it right first time (or second or third for that matter).

#

would be curious what other regulars like Sark & Psuong think of all this though - always good to get other perspectives for balance.

fathom trout
#

in an IJobChunk is there a method to get the Entity struct that an IComponentData is associated with? Or would it be a better idea to just have an Entity field within the IComponentData that has it set (when the Entity is created and data assigned)

coarse turtle
#
var entities = chunk.GetNativeArray(your_entity_type_handle);

for (int i = 0; i < chunk.Count; i++) {
  var yourEntity = entities[i]
}
#

that's the idea behind getting an entity that's associated with an IComponentData in IJobChunk

fathom trout
#

ah thanks! yea I saw the GetNativeArray and was starting to try it, but what if I needed the actual Entity struct with index and version in it? (or does that suggest maybe I shouldn't be depending on the actual Entity struct)

#

I was using it as sort of an identifier (though I know the index changes potentially if entities are removed)

zenith wyvern
#

You pass EntityTypeHandle, same way you do with ComponentTypeHandle

coarse turtle
#

hmm well if you access yourEntity you can access yourEntity.Index and yourEntity.Version also 🤔

zenith wyvern
#

Then access it like psuong's example. That is the entity associated with the component.

coarse turtle
# amber flicker would be curious what other regulars like Sark & Psuong think of all this though...

To your point, yeah I'd say that's pretty spot on. Write an implementation, ask myself does it fit my needs for my work - yeah? Move on. Revisit if the needs change later down the pipeline based on player feedback etc. I don't really think about the "future proofing entirely" aspect - since I think that depends, you can work towards a goal and go down a path, but needs and goals change over time

zenith wyvern
#

Psh, not me. I write everything perfect the first time. /sarcasm

karmic basin
#

😛

zenith wyvern
#

And regarding the state machine stuff, the idea behind the state machine is to associate a bunch of data and behaviour with a state, right?

#

Isn't that what ECS already does with components and systems

#

I wouldn't try to go against that unless I ran into performance issues

karmic basin
#

In short, SystemGroups as states ?

#

With a RequireSingletonForUpdate(chosenStateComponent) component to enable/disable system groups ? and you swith the chosen state at runtime ?

#

switch*

#

swap*

fathom trout
#

one more Q 😄 so with ComponentDataFromEntity<AINode> in an IJobChunk you use Entity to index into it, is there any way to iterate over all of them, or am I better off first copying to a temp NativeArray with ToComponentDataArrayAsync<AINode> and then writing the changes back in a second job?

coarse turtle
#

iterate over all of the ComponentDataFromEntity? @fathom trout

zenith wyvern
#

Using ComponentDataFromEntity is pretty slow if you're doing it a lot. Better to use an acceleration structure if you can

hollow sorrel
#

@fathom trout is there a particular reason you're not using Entities.ForEach over IJobChunk? sounds like that'd be the easier version of what you're trying to do

karmic basin
fathom trout
#

I see, yea in an IJobChunk for updating AI I was planning to loop the valid AI Nodes and then assign a node to the AI.
I am currently using Entities.ForEach but need to modify the Node also (when the AI selects it) and wasn't sure if the way I was doing it is correct, so started investigating IJobChunk

coarse turtle
#

Is the AINode on the Entity?

fathom trout
#

basically with the Entities.Foreach afterward I was doing this... Entities.ForEach((Entity e, int entityInQueryIndex, ref AINodeUser nodeUser) => { //since we modified the user in the prior job using temp array //we need to set it here.. hopefully the index is correct! nodeUser.User = nodeUsers[entityInQueryIndex].User;

#

but no idea if that index will always be correct

coarse turtle
#

yea I guess if you had a structural change before this job finished - the entityInQueryIndex might change

hollow sorrel
#

generally you wouldn't need temp arrays or buffers, you can just modify the component directly
dunno if you're doing something fancy to populate nodeUsers

zenith wyvern
#

A structural change would force any running jobs to complete immediately before it happens though

coarse turtle
#

ah true

fathom trout
#

hmm it's because I do Entities.ForEach Brain but since the AINodes are not on Brains (they are separate entites) I thought I had to use ToComponentDataArrayAsync<AINode> prior to the ForEach to get the AINode data

#

but then if I want to modify the data in that array, its not going to be on the original Entity

#

& about the structural change, is that why I'd want to use an Entity CommandBuffer ? To defer any change until it is finished re-assigning any of the modified data?

hollow sorrel
#

sorry still not sure what kinda logic you have set up

#

so you populate a new list of nodeUsers which are new structs, not living on any entity at that moment?

#

and then sync that up with the entity versions of those with the nodeUser.User = part?

#

also yeah you'd want entity commandbuffers (ECB) to defer structural changes, but structural changes only means adding/removing components/entities, if you're only changing component values that doesn't count so wouldn't be necessary

fathom trout
#
var validNodes _nodeQuery.ToComponentDataArrayAsync<AIValidNode>
Entities.ForEach Entity e, ref Brain brain
    //code for considering which valid node to pick
    
    for( i to validNodes.Length )
        //if picking a node
        validNodes[i].User = e; //set entity as user of node```
#

something kind of like that, so I'm only setting the user value

zenith wyvern
#

The array and your foreach are guaranteed to match up only if they have identical queries

#

AFAIK

fathom trout
#

ahh, that might be what I hit, I started getting index out of range errors when it got a bit more complex

#

(thus I started investigating IJobChunk) 😄

zenith wyvern
#

I think what you want would be to do _nodeQuery.ToEntityArray AND _nodeQuery.ToComponentDataArray. Pass both into the job.

#

Then you can match the entity to the component without using CDFE

hollow sorrel
#

wouldn't CDFE be better here

zenith wyvern
#

If I'm understand it right

#

CDFE is really really slow if you do it a lot

hollow sorrel
#

ah

zenith wyvern
#

If you are very concerned with speed it's better to do acceleration structures

hollow sorrel
#

is doing 2 .ToArray on queries better than one CDFE tho

#

seems like that'd be twice the work

#

but could be wrong

zenith wyvern
#

I think copying two arrays once is better than doing one CDFE for every single entity in the query, I think

fathom trout
#

thanks for all the clarification, giving it a try now, acceleration structures, is that similar to how the boids example is setup with the cells etc

#

basically minimizing how much you iterate over

zenith wyvern
#

Of course you should profile to make sure, but that is my gut feeling

hollow sorrel
#

do those .ToArrays let you write data as well?

#

or just read

zenith wyvern
#

They're copies. So you can write to them, if you want to write back to the original components you have to use _query.CopyFromComponentDataArray

hollow sorrel
#

cuz if not i'm just imagining something like

var nodeType = GetComponentTypeHandle<AIValidNode>();
Entities.ForEach((Entity e, ref Brain brain) =>
{
    //code for considering which valid node to pick

    for (i to nodeType.Length )
        //if picking a node
        nodeType[i].User = e; //set entity as user of node
}).Schedule();
#

and then you'd be setting it right away

#

no need for temp arrays

zenith wyvern
#

Oh I goofed and thought he was writing to the entities in the foreach

#

That seems way better

#

Also didn't realize you could use ComponentTypeHandles like that in a Foreach. I guess that makes sense though

hollow sorrel
#

or maybe reverse it, loop over AIValidNodes and check Brains instead

#

i think i'm missing something cuz i don't think you can do nodeType.Length but yea

zenith wyvern
#

You could get the length from the query

#

Hmm, but can you get the type handle from the query?

hollow sorrel
#

tru

#

you don't need to get it from the query

zenith wyvern
#

I think if you're targeting a specific archetype you would have to do it my way. If you only care about that one type

#

Your way is better

hollow sorrel
#

yea it depends on how you're picking nodes inside the Entities.ForEach

#

CDFE is basically a lookup table into that component type

#

so it's not just specific entities, it's all entities (if they exist)

#

same usage as a dictionary basically i think

#

i'm a bit rusty with ECS now so prob not giving the best advice

#

nice to see more ppl are picking ecs up now tho

spark glade
#
  at Facebook.Unity.MethodCall`1[T].set_Parameters (Facebook.Unity.MethodArguments value) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.MultiList.CalcExpandCapacity (System.Int32 current, System.Int32& needed) [0x00000] in <00000000000000000000000000000000>:0 
  at Game.Systems.Conversion.PrefabRegistryEntryAuthoring.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.Convert (UnityEngine.Transform transform, System.Collections.Generic.List`1[T] convertibles) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entit<…>```
#

What the actual fuck is Facebook doing in my stacktrace... 😱

#

Anybody seen something like this before?

karmic basin
#

You're doing a mobile game ?

#

With third-party authentication ?

spark glade
#

yeah

karmic basin
#

login system ?

#

yeah probs from that then

spark glade
#

this is in the middle of my game

#

not doing anything login related

#

Game.Systems.Conversion.PrefabRegistryEntryAuthoring.Convert is this code:

#
        public void Convert(Entity entity, EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) {
            if (TryGetComponent<TrailRenderer>(out var trailRenderer)) {
                gameObjectConversionSystem.AddHybridComponent(trailRenderer);
            }
            if (TryGetComponent<ParticleSystem>(out var particleSystem)) {
                gameObjectConversionSystem.AddHybridComponent(particleSystem);
                if (TryGetComponent<ParticleSystemRenderer>(out var particleSystemRenderer)) {
                    gameObjectConversionSystem.AddHybridComponent(particleSystemRenderer);
                }
            }
        }
#

AddHybridComponent appears to use a MultiList internally

zenith wyvern
#

If I remember right AddHybridComponent only works on gameobjects. Could be wrong about that

#

There's not much documentation on it

spark glade
#

It works fine on Android for some reason....

#

And it works fine the first time This conversion system is run

#

I kill the app and open it again and then it will blow up with this error

#

so weird

#

almost as if something gets corrupted

zenith wyvern
#

I only tried to use it once and I remember it just not working at all on components but working fine on a gameobject, maybe I was just confused

#

Is there something AddHybrid does that doesn't work with AddComponentObject instead?

safe lintel
#

is it possible if you manually destroyed the gameobject before destroing the entity its attached to through the companion system?

spark glade
#

not really 🤔

#

Also wouldn't explain why it works once and not a second time

safe lintel
#

i think addhybrid just links the lifetime of the gameobject to that of the entity(and vice versa) @zenith wyvern if you did addcomponentobject it doesnt track what gets destroyed at all

#

i dont use it though, dont trust it since the samples still say its super experimental(though they say that about animation too :D)

zenith wyvern
#

Really? Meaning if you destroy an entity it will leave the hidden components added with AddComponentObject behind?

#

From the documentation when you use AddHybrid you are meant to just ignore the existence of the gameobject altogether

safe lintel
#

well lets say you AddComponentObject(transform) to an entity, if you destroy the entity the gameobject that transform is attached to still lives on, and vice versa

spark glade
#
ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
  at System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Array.Resize[T] (T[]& array, System.Int32 newSize) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.MultiList.CalcExpandCapac<…>
#

For some reason it's resizing and then realizing, oh no, there's different kinds of elements in the array?

zenith wyvern
#

I just tested it, it seems like any objects added via AddComponentObject are destroyed with the entity

spark glade
#

Oh I think the Facebook.Unity.MethodCall`1[T].set_Parameters (Facebook.Unity.MethodArguments v might just be the uncaughtexceptionhandler looking hella weird at the top of the trace...

safe lintel
#

@zenith wyvern i would assume an otherwise unattached object but not necessarily a gameobject

zenith wyvern
#

I guess the results depend on if you're using "convertandinject". If you destroy the original gameobject after doing AddComponentObject, the entity still has the component on it (meaning your systems can still access the component)

#

But if you use "ConvertAndInject" it still syncs up the component to the original object

#

And if you THEN destroy the original gameobject, your entity still has the component.

#

So it seems it's still hiding a gameobejct in the background somewhere, just one that you're not meant to see or mess with

#

AFAIK HybridComponent does the same thing except it syncs up transforms automatically

visual juniper
#

dots netcode question : any bandwith experts out there that know when to use a ghostfield instead of rpcs to sync values ? example : a unit can have 3 items (byte itemSlot01 ,02,03). Items change only rarely (maybe once per minute on one unit, when user is dragging it onto the unit). Would an rpc whenever a user assigns an item beat the itemslots being ghostfields ? Or are ghostfields optimized that they don't even generate traffic as long as values don't change (i guess that's the real question) ?
(Imagine a game with 10 players, each having 10 units)

visual juniper
pulsar jay
#

Does anybody know how to convert referenced GameObjects to entities in GameObjectConversionSystems?

visual juniper
#

conversionSystem.GetPrimaryEntity you mean maybe ? or maybe you're looking for IDeclareReferencedPrefabs

pulsar jay
#

yeah but IDeclareReferencedPrefabs only works with IConvertGameObjectToEntity I think?

#

I am using GameObjectConversionSystem as this seems to be the preferred way as every unity conversion is using it

visual juniper
#

usefull helper functions they wrote

pulsar jay
#

Just found that GameObjectConversionSystem also has a DeclareReferencedPrefab method. Now I just need to figure out how/where to use it

odd cipher
#

How would you go about having multiple random values? I've done this before but it doesn't allow for more than 1 random value per ForEach

Random random = new Random((uint)UnityEngine.Random.Range(int.MinValue, int.MaxValue));

Entities.ForEach((Entity entity, int entityInQueryIndex) => {
    random.InitState((uint)(random.state + entityInQueryIndex));
#

as using the same Random variable multiple times just gives you the same number.

karmic basin
#

you can change the seed provided to Random

#

for example feeding it with Time.deltaTime

#

and new mathematics package has its random, I dont use the UnityEngine one anymore

#

Wait do you mean you want an array of randoms ? Or maybe use your already available entityInQueryIndex to retrieve next on random

odd cipher
#

What I want is 3 different random ints

karmic basin
#

3 for each entity, right ?

odd cipher
#

Pretty much

karmic basin
#

call nextInt() 3 times ?

odd cipher
#

I would but that would give the same number.

karmic basin
#
var deltaTime = Time.deltaTime;
Entities.ForEach((Entity entity, int entityInQueryIndex) => {
    var random = new math.Random((uint)deltaTime);
    Debug.log("Random: " + random.NextInt(yourMaxValue)));
}).Run();

Try something like that ? Not tested, I dont guarantee syntax or result :p

#

I would even try to init the seed only in onCreate, should still give different results

#

calling .NextInt() 3 times

odd cipher
#

Gives an error saying "seed must be non-zero"

zenith wyvern
#

dt is generally going to be less than 1, so that will always be zero. Try dt * 1000.

karmic basin
#

😛

zenith wyvern
#

But with random you're usually meant to pass in the seed once and re-use random from then on. Continually reseeding gives a pretty high chance you're going to repeat values early and often. Unfortunately using the same random over and over between jobs is not standardized and very annoying.

#

There are some solutions on the forums

odd cipher
#

Yeah with this I always get 0 from NextInt

zenith wyvern
#
var elapsed = Time.ElapsedTime;
uint seed = (uint)(elapsed * 1000);
#

Try that

#

Still not the right way to use it but it should give slightly better results

odd cipher
#

It does give better results but still the same number for both my NextInt calls.

zenith wyvern
#

You're seeding random before you pass it into the job right?

#

If you're seeding it in the foreach then yeah you're going to get identical results since it will just reseed it on every invocation

odd cipher
#

So I should do Random random = new Random((uint)Time.ElapsedTime * 1000); before the ForEach? Tried that but gives the "seed must be non-zero" error

zenith wyvern
#

Come on man. What do you think "elapsedtime" is on the first frame?

odd cipher
#

oh god-

zenith wyvern
#

Just add 1

odd cipher
#

it somewhat works but every entity has the same seed which is not something I want.

zenith wyvern
#

What do you mean every entity has the same seed? If you're calling "NextInt" once for each entity then they will all get a different value

pulsar jay
#

you could use the entityInQueryIndex to generate a seed per entity

odd cipher
#

Since the seed is made outside of the ForEach every entity has the same seed.

pulsar jay
odd cipher
#

That seems to work better

pulsar jay
#

Does anybody use GameObjectConversionSystems or is anyone just using IConvertGameObjectToEntity? I am having a hard time figuring out how to resolve referenced prefabs 😬

zenith wyvern
#

Does it not work if you just call DelcareReferencedPrefabs(go); var prefab = GetPrimaryEntity(go);?

#

I've only used IConvertGameObject but that is how I imagine it working

pulsar jay
#

DelcareReferencedPrefabs can only be called from the GameObjectDeclareReferencedObjectsGroup

#

which is why I added another system in that group calling DelcareReferencedPrefabs

#

but the resulting object which is instantiated later on is just an empty entity 😕

#

This is what it looks like atm:

class WeaponReferenceConversionSystem : GameObjectConversionSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((WeaponAuthoring weapon) =>
        {
            DeclareReferencedPrefab(weapon.Projectile);
        });
    }
}

class WeaponConversionSystem : GameObjectConversionSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((WeaponAuthoring weapon) =>
        {
            var entity = GetPrimaryEntity(weapon);
            ...
            DstEntityManager.AddComponentData(entity, new ProjectileAttack()
            {
                Projectile = weapon.Projectile?CreateAdditionalEntity(weapon.Projectile):Entity.Null,
            });
zenith wyvern
#

Yeah given what you just said that's what I figured it would have to look like. I was looking for an example in the packages, no luck. Did you verify that your prefab gets converted properly the usual way using either IConvertGameObject or GameObjectConversionUtility? Maybe it is working but there's some problem with your prefab

pulsar jay
#

I did not use either of those but was reliing on GenerateAuthoringComponent before which worked. Not sure if there is sth special about that though

zenith wyvern
#

Actually looking at that code you declare the Projectile as the prefab then get the primary entity as the base weapon, is that right?

pulsar jay
#

The projectile only has default components. The lower part is for converting the weapon which references the projectile prefab

#

I thought I would have to add all references per weapon with DeclareReferencedPrefab

#

but maybe CreateAdditionalEntity is the wrong way to access it later on 🤔

zenith wyvern
#

Having a hard time parsing what you're expecting from that code. When I have a referenced prefab I add the prefab gameobject via IDeclareReferencedPrefabs then during conversion to get the "Prefab Entity" i call GetPrimaryEntity on the same prefab gameobject. Then I can attach that prefab entity to my converting entity as needed

#

Not sure what the createadditionalentity bit is about up there

pulsar jay
#

ah I think I see the problem

#

I thought of GetPrimaryEntity only for getting the entity which is currently being converted

#

using that instead of CreateAdditionalEntity should solve the problem I hope

zenith wyvern
#

Yeah that sounds right to me based on what I see from that code

pulsar jay
#

great that works 👍

#

now I am just wondering if GameObjectConversionSystem or IConvertGameObjectToEntity is the recommended worflow

#

Unity seems to use the first one for all its own components. The latter one seems to be better documented though

zenith wyvern
#

I think a conversionsystem makes sense for when you're actually converting an existing non-entity-related normal ass unity component to entities. It saves you from having to mess around adding conversion scripts to stuff, you can just convert your existing gameobject into an entity and it "just works". IConvertGameObject makes more sense to me if you're just making an authoring script for something that is only going to be in the entity world

#

That's what it seems like to me anyways

odd cipher
#

@karmic basin I realized with the Reinterpret you suggested to use doesn't seem to work with FixedLists within my Neuron struct. Everything else in my struct works except those.

karmic basin
#

try to access it directly by index then ?

pulsar jay
odd cipher
#

Yeah but that requires me to also update the Buffer with my new Neuron struct

#

and that does not work in parallel

#

As we went through some days ago

odd cipher
#

I managed to get around this, It's not a problem anymore.

karmic basin
#

Great

cunning depot
#

omg... 1,5 years of DOTS development and now I find this Discord channel 😖

odd ridge
#

is there a way to enable/disable individual components?

#

I remember reading about it but I don't know if that was added yet or not

zenith wyvern
#

Not yet

gusty comet
#

btw hows unity dots doing

#

is anyone using it in production

#

or is it just like a feature that mayy (or not) be common and normalized in few long years from now

gusty comet
cunning depot
# gusty comet thats A LOT, wanna show results?

JUST READ THE INSTRUCTIONS is a surreal co-op first person shooter game where the only thing that matters is following the next set of instructions. Enemies will flood the scene, your weapons will break, more instructions will come, and then repeat.

Aspire to not die.

Steam page: https://store.steampowered.com/app/1461370/Just_Read_The_Instruc...

▶ Play video
gusty comet
#

thats cool af lol

#

maybe i should render stars using dots

#

since theres 3000 of them

cunning depot
gusty comet
#

haha stupid me

odd ridge
#

@cunning depot nice! how did you do the UI?

gusty comet
#

when do you recommend dots over normal gameobjects?

cunning depot
#

Uhm just normal old Unity UI. Thats the only thing that no DOTS at all.

gusty comet
#

like do you need a certain amount of objects for dots to be worth it or something (and how many)

#

yeah dots for ui makes no sense ha

cunning depot
#

Yeah... if you have a few years experience with Unity I recommend it.

gusty comet
#

no im still under first year

cunning depot
#

That's going to be an uphill battle... but you know, if you put your mind to it

odd ridge
#

@gusty comet imo, dots is worth it when using normal game objects would make people not want to buy your game because of performance. if rendering 3000 stars makes your game slow, dots will fix that.

undone delta
#

beginner DOTS progrtammer here. Im using the convert to entity feature on a simble cube. I have everything setupn and it works fine. Im trying to get the cube to rotate using a system:

using Unity.Entities;
using Unity.Transforms;

public class RotateSystem : ComponentSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((ref Rotation rotation) =>
        {
            rotation.Value.value.x += 0.1f;
        });
    }
}

Every frame my cube rotates, but also gets alot larger. Why?

#

sending gif of itm happening soon

zenith wyvern
#

Assuming that's the only code in your system I assume it's from trying to directly set a value on a quaternion. Also you shouldn't be using ComponentSystem anymore. You should model your code from/learn from the samples at https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/HelloCube

The very first sample shows how to do rotation

undone delta
#

why shouldnt I?

#

just curious

zenith wyvern
#

It doesn't use burst or jobs and it will be deprecated eventually

#

SystemBase is a superior replacement

undone delta
#

oh

#

what does in mean?

#

in RotationSpeed_ForEach rotationSpeed

undone delta
#

does systemBase use Burst automatically?

pulsar jay
undone delta
#

ok

#

time to see just how performant DOTS is

#

ok for what im currently testing dots is somehow slower than MonoBehaviours

#
using UnityEngine;
using UnityEngine.Serialization;

public class RotationScript : MonoBehaviour
{
    [FormerlySerializedAs("radsSpeed")] [SerializeField]
    private float rotationSpeed = 0;

    void Update()
    {
        transform.Rotate(0,this.rotationSpeed,0);
    }
}
#
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

public class RotateSystem : SystemBase
{
    protected override void OnUpdate()
    {
        var deltaTime = Time.DeltaTime;

        Entities.ForEach((ref Rotation rotation, in RotationSpeedData speed) =>
        {
            rotation.Value = math.mul(
                math.normalize(rotation.Value),
                quaternion.AxisAngle(math.up(), speed.RadsPerSec * deltaTime)
            );
        })
            .ScheduleParallel();
    }
}
#

this is a very basic example but i would thing that DOTS would outperform monoBehaviours

#

ok with a much bigger test DOTS outpeforms MonoBehaviours by far

amber flicker
#

Some potential factors 1) May not have burst enabled in jobs menu, 2) May have safety tests on (burst & jobs), even then you should test in a build, 3) method for measuring performance.

distant imp
#

Spawn 10 000 cubes, see which one perform better

deft stump
#

well for one, you're using schedParallel which adds some overhead because you need to startup a thread.
try using .Run() instead.

pulsar jay
#

Is my understanding correct that ConvertGameObjectHierarchy caches converted Prefabs so I wont need to cache the resulting entity myself and can just call it again when instantiating the same prefab multiple times?

#

Because currently I am doing this:

private Entity GetEntityPrefab(GameObject prefab)
{
    if (entityPrefabs.ContainsKey(prefab)) return entityPrefabs[prefab];

    GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);
    settings.ConversionFlags |= GameObjectConversionUtility.ConversionFlags.AssignName;
    var entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, settings);
    this.entityPrefabs.Add(prefab, entity);

    return entity;
}```
zenith wyvern
#

Looking at the code it looks like it doesn't do any caching at all. https://github.com/needle-mirror/com.unity.entities/blob/master/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs

I would only use it for unit testing personally. For actual editor tooling and such you're probably better off using subscenes

#

And you should never ever call that at runtime, to be clear

odd cipher
#

It still seems like the way I use Random isn't working correctly. Not sure how or why.

pulsar jay
amber flicker
#

If you can, wait until the dots team provides a solution - it's something they're working on.

zenith wyvern
#

Why would you need to convert at runtime? The idea behind conversion is to set it all up in the editor so at runtime you're only dealing with entity stuff. Right now that's a lot more annoying than it hopefully will be eventually but that's the idea. Just be careful about relying on it too much as it's probably going to break in the future

We still support more granular approaches like the ConvertToEntity MonoBehaviour and some function calls in GameObjectConversionUtility, but those should be avoided and are only kept around for dependencies we will remove in the near future. These approaches do not scale, are bound to be deprecated, and will not be addressed by this document.
pulsar jay
#

It would be great if we could convert prefabs at buildtime but I guess thats not possbile. So converting at runtime is the only way when trying to instantiate anything at runtime isnt it?

zenith wyvern
#

Using "DeclareReferencedPrefabs" is how you're meant to do it right now I think. If you need an entity version of a prefab at runtime, you create a second component that holds that prefab and add it to your prefab holder during conversion

#

That is how I've been doing it at least, it seems like what they intend based on samples

pulsar jay
#

I guess that would more ore less result in creating some kind of asset database subscene 😬

zenith wyvern
#

Making use of "GetSingleton" can make this a bit smoother since you can just group up a bunch of related prefabs on a single component and use GetSingleton<SomePrefabs>().MyBulletPrefab inside a system

pulsar jay
#

yeah I have also used that kind of code in the past. but it feels more like a hack or workaround tbh

#

the thing is that the whole scene conversion thing does not really work for all kind of projects

#

for example I am planning to have a map editor that works in the editor and at runtime which is why I am also using entities at edit time

#

otherwise I would have to write 2 completely different map editors. One for editing gameObjects (which also gets really slow for bigger maps) and one for runtime

#

and I cannot just store the runtime created map data in a subscene so I have to create the map from another data source

#

which means load and instantiate at runtime 🙄

zenith wyvern
#

Yeah that's a bit tricky. With the conversion system I guess Unity would in fact expect you to make two verison of the editor, which kind of sucks

coarse turtle
#

I had something similar, so I just wrote map editing information to a memory mapped file and loaded that on runtime

#

you can extend that and put in another step to create entities after loading in the memory mapped file

pulsar jay
coarse turtle
#

Kinda, - it's more information per entity since in my case all entities that would be generated had the same component types

pulsar jay
#

I thought about that too. But I am using tilemaps and they can pretty easily be stored as 2d arrays which makes it easy to replace tilesets etc afterwards. Storeing the whole map as entites would make it a lot mor static

pulsar jay
#

but if you only store some information per entity you have to instantiate the entities at runtime right? Or do you create them in code?

coarse turtle
#

i just instantiate them at runtime

amber flicker
#

better prefab & addressable workflow has been promised for quite a while now... doesn't help right now, just saying you might want to be careful how elaborate a solution you make if you can get away with waiting a bit

#

*of course a bit == DOTS soon(tm) == 😬

coarse turtle
#

Yea that too, I don't even know if tht solution I wrote is still being used ¯_(ツ)_/¯

amber flicker
#

american dates..for a minute I thought that was from back in January 🤣

pulsar jay
#

yeah thanks to reminding me of that discussion @amber flicker 😅

amber flicker
#

oops.. username blind apparently

pulsar jay
#

yeah I mean you are right that it fits the topic and that I partly already forgot about that

#

but the original question of the current discussion was: does ConvertGameObjectHierarchy cache objects if called mutliple times? It uses a blobAssetStore so I would think so. But I am unsure if it only caches some Assets like meshes or the whole prefab

coarse turtle
#

ah yeah, sorry I wouldn't know from the top of my head on what that does - I'd need to look into it when I have free time 🤔

amber flicker
#

I don't think it would cache it. At least I'm pretty sure it would do most of the work again - creating an entity and adding and setting components rather than instantiating from a setup entity.

pulsar jay
#

Well I guess I have to dive into it and find it out myself. Just thought anybody might have done that already

amber flicker
#

Like Sark mentioned - mostly seen as something to avoid. ~~Though it should be easy just to instantiate the entity when it's called again if you keep a local variable.~~Sorry just looked at your code and looks like that's what you're doing I think.

pulsar jay
#

yeah. it gets a little bit "trickier" with lists of stuff. I just wasnt sure if I was building a cache on top of a cache

eager jungle
#

Hey guys. What would be the cdfe equivalent for shared components ?

zenith wyvern
#

You can't use shared components in jobs so I don't think there is one. Since shared components have to be used on the main thread you would just use EntityManager

fathom trout
#

with entity command buffers, is there anyway to Instantiate a hybrid style entity prefab, or is it not possible by that point because of it being in ECB?
Would my best bet be reading back some entity component data and doing my GameObject.Instantiate there (with convert and inject) ?
Basically have a spawner and trigger system via ECS, but realized animation w/ mecanim will not work so I need to have it spawn characters but keep them "hybrid"

cunning depot
#

Declaring enums as byte, does that do any difference? I Have a lot of enums that will never be over 256 values. Some of them are also keys in NativeHashMaps (the HashMap declared as <byte, data>). Will it do any difference?

gusty comet
#

Has anyone been able to set up dots unit testing?

#

I tried setting this up months ago and I'm still having issues with it. My Game namespace is never recognized by vscode and now Unity Editor does this thing where if I try to double-click a file to open it in VSCode it just crashes. I get a dialog saying 'OnGui.MouseDown' that never goes away until I task kill

gusty comet
#

It compiles and runs despite the fact that VScode doesn't know the reference

#

Vscode seems the 'game' reference, it has the game reference code in the same solution explorer, so I have no idea how this is happening

#

sorry if this shouldn't be in dots btw but I don't have this issue with pre-2020 versions not using dots

#

I just changed the editor and now it works, so whatever I guess.

pliant pike
#

If I'm creating a flow field as just straight entities, do you guys think using an enum would be a good way to denote multiple flowfields?

karmic basin
#

Multiple something calls for a Collection in my mind. Enum probably okay for finite size.
But I dont get what your use case is.

pliant pike
#

yeah I just want to limit the number of fields

#

I figure just using straight entities, for the flowfield data seems more straightforward, instead of putting them in buffers or whatever

odd cipher
#

All of them seem to use the same Random variable but they arent using the same one in the code. It must be something wrong with the seed no?

#

This is how my code looks ```csharp
double elapsedTime = Time.ElapsedTime;

Entities.ForEach((Entity entity, int entityInQueryIndex) => {
Random random = new Random((uint)(elapsedTime * 1000 + 1 + entityInQueryIndex));

pliant pike
#

I dont know if your doing it but if your using the burst safe random then you have set the random value back into it

odd cipher
#

Not sure what you mean by "setting the random value back into it"?

#

And yes, I am using Unity.Mathematics Random.

pliant pike
odd cipher
#

I tried using the exact code from that website but it never worked.

pliant pike
#

it worked for me 😕

odd cipher
#

I might have to try that again then.. I'm not sure..

amber flicker
#

I'm just going to go ahead and guess you're using scheduleparallel and each thread is starting with the same random seed.

odd cipher
#

That ForEach is in parallel yes.

#

Unsure about the rest though.

north bay
odd cipher
#

"ISystemBase interface for making struct based systems that allow Burst compiling main thread update"

#

I

#

That is interesting

#

I wonder what a use case for it would be

coarse turtle
#
  • New scheduling API for IJobEntityBatch which limits the resulting batches to an input NativeArray<Entity>

This change is pretty neat, great for post filtering entities

north bay
#

"## [0.17.0] - 2020-11-13" did they just not update the date or are they really holding the releases back for that long?

coarse turtle
#

Oh wow I didn't notice the date 🤔

safe lintel
#

to follow that up, its the SkinMatrix buffer on the entity with a rendermesh that is under the root rigged entity. whats confusing is that that a skinnedmeshrenderer gameobject gets split into two entities(one parented under the root joint entity, other under the root rig entity) and also theres buffers everywhere. so many buffers, so little documentation!

#

now if only i understood why its a float3x4 instead of 4x4? 🤔 anyone with a better understanding of math got any guesses?

deft stump
#

still no enable/disable components

#

my disappoint my immeasurable

#

and my day is ruined

zinc plinth
#
* Deprecated `Frozen` component as it is no longer in use
``` then what the fuck are we supposed to use then --'
karmic basin
#

So an optimization trick

odd ridge
#

is there an example how to use the burst inspector? I can't find out how to see the assembly output for my own ecs code

visual juniper
#

out of curiousity, what would be a usecase for disabled components ?

rancid geode
#

It will remove the need to add/remove components for things like events and state machines (just examples, there are much more use cases that benefit from that)

#

Basically we will be able to avoid structural changes whenever we want to without losing functionality

#

Basically what we are able to do already with monobehaviours (5 years using Unity and I can count on my fingers how many times I needed to use Destroy com a Component instead of just disabling it temporarily)

cunning depot
# odd cipher I wonder what a use case for it would be

It's really a performance thing. I've got old colleagues who works in dots with a 25 pp team and about 10 programmers. They said that the scheduling of jobs account for more than 1ms, they have thousands of those. I know they already knew about this change and will be very pleased.

gusty comet
#

I need some help thinking in a DOTS way on this.

  1. I have a bunch of boxes stacked next to each other and on top of each other, think 3x3x9.
  2. Each box is an entity with a buffer representing contents.
  3. The contents have color data attached to them.
  4. The contents can change for a ton of reasons.
  5. The color of the box (RenderMesh) needs to be updated as they change.
#

Where does the logic for updating the color of the box go? Can it be threaded?

cunning depot
cunning depot
deft stump
#

I believe you can thread the change in color if you use URP or HDRP based material and have a component hook to one of it's colors

#

though I'm not sure anymore with this update

cunning depot
odd cipher
#

@cunning depot How exactly will it help with scheduling jobs?

cunning depot
odd cipher
#

I meant your ping. You pinged me an hour ago or so

cunning depot
#

Oh right, sorry. Confused... Well scheduling in bursted code will probably be a lot faster. I think that's about it.

#

I think Joacim Ante has mentioned that i few times in the forums

odd cipher
#

Hm interesting

cunning depot
#

I think GetSingleton in OnUpdate will be especially faster, since right now is basically a EntityQuery wrapped in help functions. It will still be a form of query, but queries are so fundamental to ECS and will probably be very optimized while bursted.

gusty comet
#

I need the colors to be dynamic

cunning depot
#

I think HDRPMaterialPropertyBaseColor is what your are looking for

odd cipher
#

@gusty comet All you need to do is have HDRP installed, add a "MaterialColor" component to your entity and create a HDRP shader for your entity with just one "Color" variable, has to be named color and connect that to "BaseColor". Then you can change that "MaterialColor" component whenever you want.

gusty comet
#

I've reached that point and am looking at scheduling the job now

odd cipher
#

Reference should be "_Color" I think.

#

Ah alright

gusty comet
#

I took a crack at this a few months ago but at that time unit testing did not work and my system is very unit test dependent, so I'm looking at it again and trying to pick up where I left off

cunning depot
odd cipher
#

Not sure

cunning depot
#

I have not tried that, but HDRPMaterialPropertyEmissiveColor seems to work that way

odd cipher
#

I don't know what that is either so.

gusty comet
#

Do I have to do anything but inherit SystemBase to have OnUpdate called?

cunning depot
#

Nope

gusty comet
#

after enabling HDRP the cubes don't show up at all, rip. Is there something special I need to do to the material? Only non-entity objects render in the test.

cunning depot
#

Well the shaders used in HDRP is completely different from old Standard rendering. Have you used the HDRP Upgrade wizard to upgrade all materials? Have you tried them straight up in the scene? Sorry to say, but there is quite a few things that can be wrong if you are using DOTS and just upgraded to HDRP...

gusty comet
#

It's a very basic project. There's one material.

#

I've changed it to HDRP/unlit. It's blue.

#

I ran the wizard

amber flicker
#

installed hybrid renderer v2 and added the define to your project settings?

gusty comet
#

I have High Definition RP 10.2.2 and Hybrid Renderer 0.10.0-preview

amber flicker
#

and you added the define as per the hybrid renderer docs?

cunning depot
gusty comet
#

worked

#

well it worked insofar as I now have boxes appearing

cunning depot
#

I'm just going to warn you. DOTS with HDRP is not a walk in the park... Read the documentation (and maybe even the source code) as much as possible . It's preview for a reason.

gusty comet
#

I'm still having fun at least

#

Missing how to make this reference the IComponentType MaterialColor.Value

#

I've never worked with shaders or any of this, I literally just wanted a colored box but that's complicated with DOTS apparently

#

well "complicated" i'm snapping things together like I'm playing with legos at the moment

#

Oh I see, it's all in the documentation.

cunning depot
#

I really thing your sould look into HDRPMaterialPropertyBaseColor first

gusty comet
#

behold its beauty.

glacial bolt
#

@cunning depot Don't post reaction gifs, please.

gusty comet
#

What's the component for material alpha?

#

I thought it was the MaterialColor W property

#

I guess I could just make my own

cunning depot
gusty comet
#

That was it, I discovered that I had to manually drag the shader back onto the material to get it to adopt new properties

safe lintel
#

@karmic basin thanks, nice find

gusty comet
#

Okay, here's a practical problem. In that above picture I'm filling up a space with cubes. I want any cube to be able to determine, easily, which cube is adjacent to it in all 6 directions. The cubes are generated on tiles which have x,z and then they are on their own x,y,z grid. The adjacency should work across tiles.

#

I can change any part of that still, but that's just how it is currently.

#

What would be the easiest, most efficient way for these cubes to find their neighbors

karmic basin
#

you can find an entity index position on a 3d grid from its vector position in the world

#

then you can -1 and/or +1 in each direction to find neighbors

#

you need to know gridcell size and divide it to the position to get index

gusty comet
#

Is this in the docu for location?

karmic basin
#

badly explained, tell me if you need a more specific one

#

nah but you can find plenty tuts on spatial partitionning

gusty comet
#

I'm actually thinking of just serializing this. If I know the grid is 256x256 and there are 3x3x9 cubes in tile, then I know there are 5,308,416 cubes in the entire game and I can serialize an a,b,x,y,z to an int between 0 and 5,308,415.

#

and just have one really, really big array that's created when the map is set up.

#

I don't know how stupid that'd be though.

#

I could even use pointers for this.

gleaming plank
#

Not unusual or uncommon. Plenty of octrees are serialized in Morton order.

safe lintel
pulsar jay
fathom trout
#

what does it mean when some of my entityManager.AddComponent / SetComponentData seems to "leak" across to other entities? (this is one I'm calling specifically from a MonoBehaviour in Update just for the player, while the majority of the others are not using monobehaviours)

#

is it the command buffer thing where a structural change occurs and thus the entity index / version my monobehaviour is referencing isn't correct for that frame ?

deft stump
fathom trout
#

makes sense, yea the player controller is all in mono unity, don't really want to port it (this is for 7day fps jam). I think I have a solution though, to keep the components in question all in ECS

safe lintel
#

ive not seen entity manager leaking, so kinda curious whats going on

fathom trout
#

I have a Fire component that is added to their weapon entity when they have a target aimed, then the weapon fires until a counter on Fire hits zero (Trigger pull time)
So for the player I'm doing entityManager.AddComponent<Fire>() but it occasionally causes the player's weapon to appear on one of the enemies feet and fire from there for 1 frame

safe lintel
#

cant say ive ever encountered that and Ive got quite a bit of mixed use cases with monobehaviours.

#

could be a bug though, if its small enough could just fire off a report

fathom trout
#

another Q, I'm noticing if I use dstManager.CreateEntity() within IConvertGameObjectToEntity.Convert(), it screws up the converted entity (things in wrong positions etc).
Would using GameObjectConversionSystem avoid that?
I was attempting to create separate PhysicsCollider entities and put them into a IBufferElementData during Convert()

#

actually maybe what i need is conversionSystem.CreateAdditionalEntity

#

...scratch that, seems to work fine after shifting the order of things around in Convert() turbotaThonk

vagrant lotus
#

Is it feasible to have dynamicbuffer which is a nativehashmap?

gusty comet
#

World.DefaultGameObjectInjectionWorld.EntityManager has no value during unit tests. How do I make an Entity Manager for testing?

karmic basin
#

Never tried but EntityManager purpose is to handle entities for the world, so I would begin by looking the source code of how the world gets it.

low tangle
#

you don't create the entity manager, you create a world

#

look into the unit tests within the Unity.Entities package, theres lots of examples

olive kite
#

is there a nativearrayutility-like class similar to the arrayUtility?

vagrant lotus
gusty comet
#

For whatever reason for years I've had issues trying to get Unity to correctly rebuild with new references

#

I'm trying to get Untiy.Entities.Tests in, and I just cannot get it to work

gusty comet
coarse turtle
gusty comet
#

the problem is now that .net doesn't recognize it

#

the code compiles and runs fine, but I get squiggles on everything

coarse turtle
#

Yea - I remember having that issue, so I just copied their TestFixture locally to my own testing dir

gusty comet
#

pfffffffffffff

#

this was an issue last time I tried working with ECS half a year ago

#

you'd think they'd have this sorted

#

I just want to do some very simple testing

mint iron
#

@vagrant lotus DynamicBuffer uses a pointer to the actual data in chunk or elsewhere on heap. its allowed to be passed around like that because structural changes will cause its internal validity checks to fail and it will not let you use it anymore.

vagrant lotus
#

@mint iron thanks

stone osprey
#

quick question... how can i edit a entity during the play mode ? Just one little value ? ^^

#

The fields are greyed out and i cant insert new values in the "Entities" tab :/

#

Any ideas ?

coarse turtle
#

they're generally not editable, unless you use a subscene

stone osprey
#

Damn... would be great :/ its much work to adjust values in code each time to see the outcome

gusty comet
#

Question about design philosophy.

In OOP, I have a class called a Jar. It contains chemicals. So the Jar contains a liter of water at room temperature. I then call Jar.AddChemical(Water, Temp.Boiling) and it knows, because the existing contents and the new contents have different temperatures, that there's work to do.

In ECS, I have EntityManager.GetBuffer<ChemicalComp>(cube); and I am adding another struct to this buffer.

#

How do I standardize this so I can make sure events fire no matter how chemicals are getting added?

mint iron
#

not sure what you mean by events firing, but you'd have a system that either always looks at the data and figures out if it needs to do anything with it, or trigger execution by the presence of a component. For example, a foreach filtered to run on cubes with NeedsStuffDone component.

gusty comet
#

That's simply not possible. There will be tens of thousands of these. I can't scan them constantly.

#

I have, for instance, a Jar.HeatInhomogeneousTag that I can add as a component to handle the math.

#

But it'd be really nice to have a static method or something for dealing with this

#

Jar.StaticMethodForAddingChemicals(Entity, Chemical)

#

But that sounds OOPish and not what they'd want me to do

gleaming plank
#

Are all chemicals <substance, temperature> pairs?

stone osprey
#

Theres literally no "clean" way to do this inside an ecs... You should just mark the entity as "ChemicalAdded" and having a loop running over them "Entities.ForEach((ref ChemicalAdded ca, ...) => { // Process and remove ChemicalAdded after processing is done }"

gusty comet
#

@gleaming plank ChemicalComp struct is Chemical, Matter, Temp

stone osprey
#

Oh and if the performance matters... you can simply use command buffers and multithreading, should be fine aslong as you dont acess engine stuff

gusty comet
#

So yes it's an IComponent and can be parallel threaded

#

That's the point

#

But idk, I just feel like there should be a more precise way of doing this, where adding something fires an even that allows for some hooks

#

Can systems even fire events?

stone osprey
#

@gusty comet There is... its called "Reactive System"

#

But its not implemented in unity yet... so you need to simulate it by yourself... or code one by yourself

#

I literally had the same problem and coded my own system... but it does not work with buffers :/

gusty comet
#

hm, okay. I'll move forward with plain systems and pin a note about reactive systems.

#

If there's a performance issue I'll look back on it

gleaming plank
#

lol I feel like I missed a lot of exposition on whatever you're making. Could you clarify what thing was difficult for you to design the ECS way?

mint iron
#

i think its just hard to get your head around, it feels like working around the problem when it should be so much easier if you're used to oop. took me ages.

amber flicker
#

just going to mention that one thing that makes reacting to events somewhat ill suited conceptually is the scheduling & parallel nature of systems - you almost never want something to react immediately as that puts you straight back on the main thread and possibly a sync point. So you often end up with events either at start or end of frame and then you lose that immediacy/iteration/recursion that events lend themselves to. Then it tends to look like either a) an entity created per event, b) tags, c) icd's with a counter/bool etc d)native stream stuff like the often sited events package on the forums. If you design around the whole game infrastructure around the concept of events, you may be best sticking to just main core imo.

coarse turtle
#

hmm if anyone knows, which systems are responsible for bringing over the entities from a subscene into a world?

coarse turtle
#

actually figured it out, it was everything under the SceneSystemGroup 😅

hollow sorrel
#

ya basically everything in that but also

#

if you're starting with a world with no systems:

  • InitializationSystemGroup (the ones below update in this group)
  • ConvertToEntitySystem
  • EndInitializationEntityCommandBufferSystem

and your world needs to be set as DefaultGameObjectInjectionWorld as that's where the subscene gets loaded into when your regular unity scene gets loaded

zenith wyvern
#

How do I standardize this so I can make sure events fire no matter how chemicals are getting added?
@gusty comet

You can do WithChangedVersionFilter<ChemicalComp>() then your job will only run if there's a change to the chemical. You get a reactive system minus the structural changes

#

It gets tricky to prevent the job from running all the time though, you need to be very careful about read/write access

#

And you need to validate state since it runs on a whole chunk

olive kite
#

Does anyone know why I am getting a "IndexOutOfRangeException: Index 1 is out of restricted IJobParallelFor range [0...0] in ReadWriteBuffer.
ReadWriteBuffers are restricted to only read & write the element at the job index. " error on this:

#

it happens inside of the raycast it appears (just discovered) on :
Unity.Physics.Broadphase+BvhLeafProcessor.RayLeaf[T] (Unity.Physics.RaycastInput input, System.Int32 rigidBodyIndex, T& collector) (at Library/PackageCache/com.unity.physics@0.5.1-preview.2/Unity.Physics/Collision/World/Broadphase.cs:590)
which is: RigidBody body = m_Bodies[rigidBodyIndex];

#

is anyone using raycast calls in parallelfor jobs or systems?

gleaming plank
#

Can you show the rest of the job?

olive kite
#

that's it. there's more but even when i take out the rest it happens. I replaced the collisionWorld reference with a CollisionWorldRO reference and it works now, not sure why. The ecs physics samples uses collision world inside parallelFor and it works

#

ColisionWorldRO being read only version, i guess that makes sense though

deft stump
#

tried disabling burst?

#

run and see attempt the error?

gusty comet
#

@zenith wyvern I can't find anything with that name anywhere. Is there a docu for it? It's called WithChangeFilter<T>

gleaming plank
thorny halo
#

Hello, does anyone know how to optimize a 2D grid for random access while using the job system? I'm using a* pathfinding, which uses more and more random accesses the longer it searches. The grid for my purposes would be about 1000x1000 cells, each cell containing roughly 28 bytes. If the code is ever going to be cache friendly i obviously can't have data the size of ~27mb loaded every time i need to sample a grid cell. I'm thinking of chunking the grid into 16x16 cells and using Z-curve encoding for each chunk, however, i can't figure out how to create a NativeHashMap of NativeArrays, since array type data structures are banned to be inside one another in DOTS.

zenith wyvern
#

Like you said you can't have nested native containers, period. You can do nested arrays in blobs, or use NativeMultiHashMap or NativeStream

vagrant surge
#

@thorny halo first trick you have to try is to decrease the complexity of the grid

#

doing cells is a great idea, as that gives you a 2-level acceleration structure of sorts

#

but generally dont bother so much with the z curve encoding or similar if you are already doing cells

#

if it really is a problem, try to turn it into a navigation mesh. Convert it first into a grid, and then on each grid, try to "mesh" it into rectangles that cover multiple tiles

#

it doesnt matter if the meshing isnt so accurate as long as its somewhat reasonable

#

but a 1000x1000 grid isnt even that much to begin with. Pretty sure the old Dungeons and Dragons games like Baldurs gate did A* on that size of a grid with no effort back in the 90s

#

have you actually benched it to be an issue?

zenith wyvern
#

I have, and yeah astar gets very VERY slow for a grid that size

#

~20ms in my testing, bursted with safety checks off for a naive implementation of astar

vagrant surge
#

well fuck

zenith wyvern
#

For a worst case scenario with no walls pathing across the entire map

vagrant surge
#

but are you sure that the slow thing isnt the priority queue?

#

on all the A* impls ive done that was the big bottleneck

#

btw, you should be doing flood-fill

zenith wyvern
#

In my testing it was about half priority queue half the rest of the algorithm

vagrant surge
#

to give the separate zones an ID

#

that way you avoid the pathological case of "no path"

zenith wyvern
#

And I tested a lot of different queues

vagrant surge
#

in that case we start getting into the tryhard level

#

first thing to do is to optimize the amount of nodes for it to be down. A grid is a good first step

#

every 16x16 tiles or whatever you join them into a grid node. The node has connection points to the other nodes next to it

#

when doing the A*, you first do the path on the grid nodes, and then you do the "normal" A*-ing on the nodes themselves

#

multiple levels of grid might be a thing if your path space is absolutely huge

zenith wyvern
#

Yeah I figured the easiest way to optimize beyond trying to do some low level cpu magic is simple hierarchical changes to the map to reduce the number of nodes processed. I will say it was VERY fast on <300x300 maps. Way faster than an identical non-burst version

vagrant surge
#

converting the grid into a navmesh is also a popular thing

#

as it greatly reduces the number of nodes in the map

#

less nodes = faster everything

#

there is also another trick. Not using A*

#

jump-point-search

#

problem is that it requires the grid to be uniform-cost

zenith wyvern
#

In my case my game was constrained to a grid so astar was definitely my best option. But yeah if you're not actually making a grid based game then there are better alternatives

vagrant surge
#

you still want to convert it into a navmesh

#

even if its still constrained to a grid

#

you just merge groups of tiles togther to search better through them

zenith wyvern
#

That makes sense. Just another form of hierarchical changes to the map. I personally wanted to avoid that to keep things as simple as possible

vagrant surge
#

doing the 2-level grid is probably already more than good enough

#

meshing it is the next step after the 2-level grid

thorny halo
#

unfortunately for my use case, the grid will be baked at runtime quite frequently on a large scale so point search optimizations can't be implemented as it takes multiple seconds to finish. I've only kept to grids thus far to keep it simple, i might look into converting to navmeshes in the future tough. Here's an example to what magnitude I'll be dealing with terrain manipulation. https://www.youtube.com/watch?v=sH1b9wZ9xsk&ab_channel=Crysicle

GPU and CPU data state synchronized. SphereCasts/Raycasts can now interact with the heightmap.

Remaining to implement: reduction to the amount of tris/verts rendered. Most likely custom terrain LOD will be required. Unity's terrain methods are too slow.

▶ Play video
zenith wyvern
#

Watching that all I can hear in my head is "Escape from the City"

#

I don't know why

frigid onyx
#

I'm trying to use Unity.Physics' CastCollider method and I'm getting exceptions thrown.

This appears to be coming from Unity.Physics\Collision\Geometry\BoundingVolumeHeirarchy.cs

In the method

public unsafe BoundingVolumeHierarchy(NativeArray<Node> nodes, NativeArray<CollisionFilter> nodeFilters)

It's throwing an exception saying that GetUnsafeReadOnlyPtr isn't implemented for NativeArray 🤷🏻‍♂️

Has anyone else run into this?

#

I guess I'll have to cast a ray from the corners of my bounding box instead (assuming the CastRay function works)

hollow sorrel
#

@frigid onyx yea unfortunate that compound colliders aren't implemented, i could see why that would be useful
non-convex mesh and terrain casting isn't supported by physx either tho

frigid onyx
#

Terrain makes sense, because typically you'd cast something into a terrain.

I'll work around it, but it would be nice it if the documentation called this out rather than individual devs stumbling upon it at runtime. 🤷🏻‍♂️

hollow sorrel
#

ya i mean non-convex terrain

#

convex terrain and convex mesh should be supported

#

also i would think casting into a non-convex terrain/mesh should also work fine

#

seems that casting that as a shape into others is what's not supported

#

but if it isn't then yea that'd also suck

viral comet
#

When I look in the Entities source, there is documentation, but when I use a package there it is not.

#

How guys to make it visible?

spark glade
#

The feeling when you find your bug after 2 hours of "unexplainable" NaNs due to using normalize over normalizesafe 🤦‍♂️

agile dome
#

Sorry we don't do off topic embeds.

icy hinge
#

When switching from Hybrid Renderer V1 to V2 fog and shadows look different, how can I fix this?

#

I also get an index out of range error from a GetSharedComponent call in Hybrid Renderer V2, it seems it's trying to get a component from an entity that no longer exists

deft stump
#

so i'm trying to make a jobs based frustrum culling. been trying to get some samples so I can make my own implementation. but I can't wrap my head around it. because I'm limited with the job's system nativecontainers only accepting blittable types.

#

so what's a good approach to making this frustum culling a reality?

amber flicker
#

hmm what data do you have that's not blittable?

deft stump
#

I haven't started coding yet. Just getting a feel for it.
but I think only one? the Renderer component of the affected objects.

#

ah and also I think the camera. I have no idea how to calculate if a certain vertex is in view or not with jobs

north bay
#

I would just make a bounding box that contains the entire mesh. Then you can fetch the planes of your camera and test against those inside a job.

deft stump
#

oh you can get the planes?

#

huh

#

that makes it so much easier.

coarse turtle
#

Yeah you can use the planes of your view frustrum using the geometryutils class (it'll return to you an array but you can copy it to a nativearray or pin the array for a pointer to it)

deft stump
#

nice nice nice... crap i was thinking to manually calculate the planes given that I know the fov, pos, and rotation. saves me the trouble

#

😄

amber flicker
#
Joachim: Yes, got delayed a bit because we had several iterations of shipstoppers since we are now validating all dots packages together...``` - validating all dots packages together 😲 🥳
solar ridge
#

👀

deft stump
#

so 0.17 will have enable/disable components?

#

say yes

#

please say yes

amber flicker
#

haha no I don't think so

deft stump
#

haaaaaaa

amber flicker
#

could be wrong

deft stump
#

welp... I'm gonna cry in the corner for a bit

karmic basin
#

We need the skinnedMeshRenderer more :p

north bay
safe lintel
#

yeah enable disable doesnt appear to be in the patch notes

slim nebula
#

hello I'm back again. I'm trying to create a framework/feature for creating multiple instances of a subscene (rooms of a randomly generated maze of rooms).

  1. I've created a ClientServerBootstrap to make mulitple worlds.

  2. I've instatiated the subscene using LoadSceneAsync and I see the subscene in my secondary world as intended.

  3. I want to use MoveEntitiesFrom but there are other entities in the secondary world created by the subscene system. When I try to delete those, something else deletes the entities I want to keep. My guess is that it's looking at the BlobAssetOwner component, but it's internal so I'm not sure how to remove it to see if that's the issue. Has someone done like this before? Or does anyone have an idea on how I can proceed?

Is there a better way to make muliple instances of a subscene?

pliant pike
#
public class ObstacleAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{    
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
               dstManager.AddComponent(entity, typeof(ObstacleTag));
}```
#

I don't suppose anyone can tell me what I'm doing wrong with the above code

#

the object gets converted to an entity but it doesn't add the component at all I don't understand 😕

slim nebula
#

looks right to me. what makes you think it's not adding it?

#

@pliant pike

pliant pike
#

yeah I think it is working right I just can't find them in the editor

slim nebula
#

in the entity debugger? do you have the right world selected?

pliant pike
#

plus if they were converted and in the right scene they would show up in my visual debugging system

slim nebula
#

yup

#

are you saying the entity is not showing up at all?

amber flicker
#

yes be sure to check which world you're looking at - if you have the subscene open, they're in the subscene's world (and named). If closed I think they're in the default world (and unnamed).

pliant pike
#

I don't know it doesn't make any sense I can see the entities but they don't have the tags added to them

amber flicker
#

I think your code looks fine. Do you have a system that removes ObstacleTag?

slim nebula
#

dumb question but did you actually add said MonoBehaviour to your game object?

pliant pike
#

yep I think I've got some confusing with naming of things though

safe lintel
#

does it work if its new ObstacleTag() instead of typeof(ObstacleTag)?

pliant pike
#

you just get an error if you do that

amber flicker
#

^AddComponentData

slim nebula
#

i use this one myself. not sure if it matters: dstManager.AddComponent<RoomLibraryInitializationComponent>(entity);

amber flicker
#

all are valid and should work

slim nebula
#

ye

amber flicker
#

but yea, agree - prefer that over typeof()

slim nebula
#

timbloc do you know how to create multiple instances of a subscene?

pliant pike
#

yeah that's what I changed to @slim nebula

amber flicker
#

Not really - though Unity did release a generative dungeon example or something didn't they? Where every procedural tile was a subscene?

slim nebula
#

ooo any chance u could link me that?

#

has not come up in my searches

amber flicker
#

last time I tried to find it I failed but lemme try again

slim nebula
#

love

#

thanks

amber flicker
#

esp check out the known issues

safe lintel
#

does that sample work? thought it relied on unreleased parts but cant remember

slim nebula
#

says prefab instances

#

I'll still look tho thanks

safe lintel
#

also actually just tested using AddComponent(entity, typeof(mytag)) and it worked so not sure what was going on with your case calabi

pliant pike
#

I don't know its bemusing how I even come up with these errors 😕

slim nebula
#

yeah looks like that sample is using prefabs.... I guess I should just stick with that

#

aren't prefabs always loaded in memory tho?

#

can I create a bunch of subscenes each containing a single prefab?

amber flicker
#

fyi we're eagerly anticipating news on this front (prefabs/addressables/subscenes workflow improvements).. as-in, I believe a lot of the work is already done but not yet ready for release. Of course there are no timelines, just mentioning.

slim nebula
#

ok. that's good to know. then maybe I just do flat prefabs for now, and hopefully it's out by the time my shit is big enough to matter

amber flicker
#

I think subscene per prefab is.. fine? Though yea as I say, don't go and do a massive project based on that workflow as it's likely to change soon(tm).

slim nebula
#

yeah. I mean I'm just one dev. doubt I can make something big enough to be a problem in that time

#

thanks for the help timboc

pliant pike
#

I seem to have fixed the issue somehow by creating a new script and renaming things leahWTF

slim nebula
#

hah XD

#

i bet that just makes you happy and confident

pliant pike
#

nope just more confused 😕

karmic basin
gusty comet
#

how many components is too many

zenith wyvern
#

Whatever number makes it too hard for you to keep track of what you're doing

#

And I guess if you have enough components on an entity where it won't even fit inside a chunk...that's probably too many

tawdry tree
#

As Sark said:
-It's too many if you can't keep track of em
-It's too many if they can't fit in a chunk*
-Not "too many", but remove any unused components (used in no queries, as data, tags, or otherwise)
* TBH it's too many way before that; If you have entities with a lot of data, consider whether perhaps the entity should be split into multiple entities. If you have very few of the archetype (<10, typically 1), consider if this data benefits from being on an entity at all, or whether it could be elsewhere.

#

I'd said the first one is the most important, but the second would be a big red warning flag that you miiight be using the wrong tool for whatever job you're trying to do.

deft stump
#

okay. so does mathematics have an equivalent of TestPlanesAABB?

coarse turtle
#

there's an AABB struct

#

you can use

deft stump
#

isn't that part of the entities package?

coarse turtle
#

no should be the math extensions assembly

deft stump
#

strange

#

I can't see it in documentation

coarse turtle
#

not sure if its documented, but should be there since I used it

deft stump
#

uuuughhh... I thought my math was wrong

#

but I was just passing the wrong parameters

odd ridge
#

I have a couple thousand entities which ecs works well for

#

but now I need a way to detect collision between each of them

#

does it make sense to implement an octree in ecs? the only examples I found were using dots native arrays without any ecs

visual juniper
#

physics collisions ? In case yes : you could use ICollisionEventsJob which provides you entity pairs that are currently colliding

#

Since unities new physics system already handles world optimization i guess that's one of the best solutions currently

odd ridge
#

not for physics collisions but simple object overlapping detection. unity physics is too slow for my needs

#

I need the collision detection without the physics simulation

coarse turtle
#

like the physics elements are static?

#

im having a hard time imagining what you mean by "i need a collision detection without the physics simulation," since physics will usually simulate so you can detect collisions in the narrow phase of a physics engine

#

ah I reread what you wrote, @odd ridge if you only need to detect if objects are overlapping and I assume those elements are static, then yeah a spatial data structure is really all you need so you can reduce your search space.

odd ridge
#

I suppose unity physics doesn't expose that? I would have to write my own?

north bay
#

Unity physics does have a BoundingVolumeHierarchy that you can use. I'm not sure if it's public by default or if I have made it public myself

proper silo
#

Hello! Anyone know how to get the scale of an entity after it has been converted from a gameobject with the script "convert and destroy"? Rotation and Translation are working but, Scale isn't... (Tried NonUniform scale as well)

slim nebula
#

CompositeScale is what you're looking for I think

#

@proper silo

deft stump
#

So I've got a problem...
here's a snippet.

    public void ForceUpdateCulling()
    {
        FCJHandle.Complete();

        //Dipososing Other natives here ...
        //...
        //...

        if (NativeResults.IsCreated)
        {
            for (int i = 0; i < NativeResults.Count(); i++)
            {
                //there's over 100 renderers!
                Renderers[i].enabled = NativeResults[i];
            }

            NativeResults.Dispose();
        }
    }

now my problem is that copying back the result from the job to over 100 renderer.enabled is literally killing perf.
I'm wondering what's a good strat to solve this perf problem

proper silo
zenith wyvern
#

So I've got a problem...
here's a snippet.

    public void ForceUpdateCulling()
    {
        FCJHandle.Complete();

        //Dipososing Other natives here ...
        //...
        //...

        if (NativeResults.IsCreated)
        {
            for (int i = 0; i < NativeResults.Count(); i++)
            {
                //there's over 100 renderers!
                Renderers[i].enabled = NativeResults[i];
            }

            NativeResults.Dispose();
        }
    }

now my problem is that copying back the result from the job to over 100 renderer.enabled is literally killing perf.
I'm wondering what's a good strat to solve this perf problem
@deft stump

Are you running it inside burst? Also if you can reduce the things you're reading from/assigning to into a single value of the same type you can do a memcopy or memmove of the entire run of data at once.

deft stump
#

ForceUpdateCulling isn't runnign in burst

#

I'll try memcopy

zenith wyvern
#

Even if you just move the for loop into an ijob struct with the burst attribute and call it with .Run you would see a huge improvement. Assuming that is in fact your bottleneck

deft stump
#

Ah no. this isn't running in ecs. it's just a regular jobs.

zenith wyvern
#

An ijob struct has nothing to do with ecs

deft stump
#

But Renderer is managed type. isn't that not allowed in a job?

coarse turtle
#

hmm I had thought that unity by default does frustrum culling already with the renderer components, the draw calls change depending on how the frustrum is angled

zenith wyvern
#

Ahh, yeah if it's a managed type you can't use it in a job unless you pin it

coarse turtle
#

ik it's not done in Graphics.DrawMesh(...) APIs unless you use the newer Batching (forgot the exact API name) API or fill a buffer and cull it yourself

deft stump
#

I think I've bitten off more than I can chew

#

XD

coarse turtle
#

if you want to continue giving frustrum culling a try, you can try to fill an array with matrix4x4 from a job and pass that to Graphics.DrawMeshInstanced

#

or Graphics.DrawMeshInstancedIndirect

slim nebula
#

does UnityEngine.InputSystem work with dots/ecs?

#
            var horizontalMovement = inputMaster.Player.HorizontalMovement.ReadValue<Vector2>();
            input.RightLeft = horizontalMovement.x;
            input.FrontBack = horizontalMovement.y;

            input.UpDown = inputMaster.Player.VerticalMovement.ReadValue<float>();
            input.YawRightLeft = inputMaster.Player.Yaw.ReadValue<float>();
            input.PitchUpDown = inputMaster.Player.Pitch.ReadValue<float>();
            input.RollRightLeft = inputMaster.Player.Roll.ReadValue<float>();
#

seems to always just return 0. not sure what I'm doing wrong

#

(input is my component, inputMaster is the generated c# code by unity)

#

am I doin it wrong?

#

(or is there a better place to ask this)

#
            inputMaster.Player.HorizontalMovement.performed += ctx =>
            {
                Debug.LogError("horiz");
            };```this doesn't seem to work either. not sure what I"m doin wrong
#

I was missing inputMaster.Enable();

gleaming plank
# odd ridge I need the collision detection without the physics simulation

I'm not too versed in the UnityPhysics package, but an ICollisionEventsJob (or ITriggerEventsJob) is probably what you should use. It'll give you all pairs of colliding entities.

AFAIK the dynamic motion parts of the physics simulation only run on entities with the PhysicsVelocity component. If your entities only have the PhysicsCollider component, I think you're only paying for collision detection.

If you're searching for specific collisions, rather than an ICollisionEventsJob which iterates over all collisions, it might be more efficient to run queries on a CollisionWorld directly.

The API is pretty verbose, so I'd recommend going through the official samples.
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/UnityPhysicsSamples/Documentation/samples.md

Sample 2d2 implements an ICollisionEventsJob as part of the example.
Sample 3 is basically a walkthrough of every CollisionWorld query.

proper silo
#

Why is adding a Scale component in a Monobehavior Convert method not working while any other component is?

deft stump
#

I think making my own custom renderer is going to be faster in terms of perf than trying to make do with unity's renderer components

coarse turtle
#

I've done that and it works quite decently for DrawMeshInstancedIndirect

deft stump
#

Oh I was able to circumvent it by using Array.Copy to a managedArray.

#

then use Parallel.For

#

then rely on the Update method to update it for me.

#

uuugh it's not performant but at least I'm getting results

deft stump
#

okay so. Upon testing... it seems that my solution isn't anymore faster than rendering everything

gusty comet
#

how do i add a collider to my terrain in unity 2020 i am new to unity

slim nebula
#

click add component, and select one of the colliders

gusty comet
viscid echo
#

@gusty comet well your character must not have a collider. the unity terrain comes with a collider

maiden delta
#

how do i get data from entity in a monobehaviour? i need to change an object's mb's properties depending on entity's data

karmic basin
#

You can access the entities package from monobehaviours

#

this means you can retrieve your world's EntityManager, or do your query, whatever...

maiden delta
#

any way to get a linked entity from a go?

zenith wyvern
#

A query. Or pass it to the gameobject from inside a system

maiden delta
#

to be exact i need get an entity's PhysicsVelocity and use its data to show speed to a user using unity ui

maiden delta
zenith wyvern
#

The gameobject in this scenario would be the ui?

maiden delta
#

yep

zenith wyvern
#

When you're authoring your gameobject that's being tracked, you can add the ui as a reference in a managed component

#

And use a system to update the ui any time the physics velocity changes

maiden delta
#

how would i do that? i cant add gameobjects to components

zenith wyvern
#

You can. You can use a "Managed component", IE a component that is a class instead of a struct

#

Then it can hold managed data, and you have to use WithoutBurst and Run any time you access it

maiden delta
#

wait what?

zenith wyvern
#

In that example the "HealthUI" holds a reference to a text component

#

Not the least bit performant but good enough to bridge the gap until we have proper dots ui....if we ever do

maiden delta
#

well i also need it to control an fmod event soooo either way i have to use it lol

#

besides the main purpose of dots for me is physics raycast performance in dots unity/havok physics

vagrant lotus
#

imported hybridrenderer
restarted editor

#

checked using Unity.Rendering & Unity.Rendering.HybridV2

#

Visual Studio still does not recognize RenderMesh anywhere

#

How do I resolve this issue?

zenith wyvern
#

If you're using assemblies you need to make sure that's referencing the rendering assemblies. Otherwise try closing visual studio and deleting all the .vsproject files and the .vs folder in your project directory.

vagrant lotus
#

ok

#

will try deleting vsproject

#

thanks for quick respond😊

slim nebula
#

Does unity do entity conversion of the top level scene on compile? or in runtime? Are there future plans regarding this?

#

I guess I can just have a subscene as the only child of the root and put everything in it

deft stump
#

are native hashmaps resizeable?

zenith wyvern
#

Yeah. They resize automatically as you add stuff

#

Same as a list

deft stump
#

huh so what's the point of adding a capacity then?

zenith wyvern
#

Resizing isn't free. Just like non-native containers, you safe some CPU time by setting a sensible initial capacity

#

Also there's a limit to how much it can resize at once. Something to do with cache size

zenith wyvern
#

It won't let me use UpdateBefore/UpdateAfter on a custom ComponentSystemGroup, so how do I specify when my group gets placed relative to the default groups?

visual juniper
#

Has someone made any experience with SharedComponentData and IJobChunk ? I'm having 10 'battlefields' which each consist of 40 'fields' , i added each field a sharedComponent with battlefield index (int) to structure them into chunks, but I would need to compare some requests to that index to target the right battlefield (for movements for example). So i was wondering wether it's possible to (readonly) access shared component data for a chunk ?

mild ledge
#

Hey guys, real quick question. How can I easily do hybrid renderer for static objects and still have normal physics for them? Duplicate the object with just the colliders or what ?

thorny halo
#

Hello, I'm creating a Priority Queue data structure which I'll be using in a job later. Initially I thought I'd just need a hashmap and a heap, but now i realize that it's only enough for a single job thread as other threads would need their own priority queue. If i needed an x amount of threads to use a Priority Queue for each thread, is the only way to do that is to create a Priority Queue Array? Where the x heap arrays and x hashmaps would essentially be combined into a single heap array and a single hashmap?

E.G. Priority Queue [Heap][Hashmap] -> Priority Queue Array of size 4 [Heap0Heap1Heap2Heap3][Hashmap0Hashmap1Hashmap2Hashmap3].

deft stump
#

wait lol what. nativehashmap cannot support parallel writing?

#

uuuugh

deft stump
#

okay I'm getting confused how do I write to a nativehashmap?

#

here's the code

thorny halo
#

@deft stump When trying to save a value in a hashmap the key will be converted into an index of the hashmap array, if the index is already occupied, it will move to the next index until it finds an open index. Because of this, hashmaps always have race conditions when multithreading and writing to them. Writing to a hashmap can only be done in a single thread in order to avoid overwriting data from 2 or more different threads/

deft stump
#

then what's .ParallelWriter for?

thorny halo
#

@deft stump If I'm understanding correctly, on line 129 "NativeResultMap = ParallelNativeResultMap;" is not a data copy, NativeHashmap is just a struct on c# with an index pointing to c++ data. So It's copying the index, not the array data. So when you're doing "ParallelNativeResultMap.Dispose();" on the next line, you're deleting the only data you have. Therefore, NativeResultMap, which is now pointing to the deallocated data, is causing exceptions when trying to access it.

#

To fix, probably just make ParallelNativeResultMap with Allocator.Persistent, dispose of NativeResultMap , then assign ParallelNativeResultMap to NativeResultMap .

deft stump
#

hrmmm

#

Okay since I can't do parallel writing. maybe I could shard it?

#

and then have x number of ijobs running

#

or maybe use NativeDisableContainerSafetyRestriction]?

coarse turtle
north bay
#

Still waiting for 0.17 😦

odd ridge
#

I jumped onto version 2020 because dots in 2019 is hardly usable imo but I'm definitely sticking to 2020 LTS this time. updating my project everytime unity releases a patch is such a pain

deft stump
#

so... HAHAAHAHAHAHAHA
scheduling the frustum calculation per object. instead of making a giant list and scheduling it once is no go.

#

for 1003 objects, i'm getting 60ms just from this one monobehaviour that's scheduling a job being called 1003 times.

zenith wyvern
#

Yes, scheduling 1000 jobs in a loop will work very badly

zenith wyvern
#

Here's an example of writing to a native hash map in parallel

        var nmh = new NativeHashMap<int, int>(32, Allocator.TempJob);
        var writer = nmh.AsParallelWriter();
        
        Entities.ForEach((int entityInQueryIndex, Entity e) =>
        {
            writer.TryAdd(entityInQueryIndex, entityInQueryIndex); 
        }).ScheduleParallel();

        Job.WithCode(() =>
        {
            var arr = nmh.GetKeyValueArrays(Allocator.Temp);
            for (int i = 0; i < arr.Length; ++i)
                Debug.Log($"{arr.Keys[i]} : {arr.Values[i]}");
        }).Schedule();

        nmh.Dispose(Dependency);
#

@deft stump

#

Don't try to dispose the parallel writer. It's just a wrapper around the original container

gusty comet
#

Is there an easy way to get the delta time since the job last ran?

deft stump
zenith wyvern
#

I have no idea what your use case is. If you need to run through every element you can just use foreach on the container, I only use the KeyValueArray because you can't do foreach inside a job

viral comet
#

Does anyone know if the ComponentSystem will be deprecated?

deft stump
#

yes, ComponentSystem is deprecated

#

use SystemBase

coarse turtle
#

It'll still be around for the GameObjectConversionSystems that are in place (but yes use SystemBase instead for your gameplay logic)

viral comet
#

I'm getting a dots-complaining error about my generic component

#

for the ComponentSystem there was an option to register them via assembly: attribute

#

[assembly: RegisterGenericComponentType(typeof(MyGeneric<ComponentName>))]

#

However it doesn't work here

coarse turtle
#

ah sorry, I don't know much about generic components usage in DOTS :/

viral comet
#

sounds like i'm going to recreate the whole game 😢

deft stump
# zenith wyvern I have no idea what your use case is. If you need to run through every element y...

well my idea is this.
there's 2 scripts, 1 is a Singleton (for the sake of arguement), and 1 is a regular old monobehaviour attached to X number of objects.

the idea is:
register each monobehaviour in the singleton hashmap with instanceID as it's key, the bool wether i want it to render or not as it's value.

setup and schedule the job inside the singleton update method.

then after the job is done each monobehaviour gets the result from singleton hashmap.

#

that was the idea.

zenith wyvern
#

Is there some reason you need extra culling beyond the built-in frustum culling?

#

If you need occlusion culling for gameobjects they already have a system for that

deft stump
#

just a side project and nothing really serious.
I just want to see it done and in the most performant way possible.

zenith wyvern
#

In most cases if you want the most performance you should be using ECS. Gameobjects are slow

#

And awkward to use with jobs in most cases

hollow sorrel
#

i thought your bottleneck was the renderer.enabled = true/false part

deft stump
#

that changed

hollow sorrel
#

ah

stone osprey
#

Back with some design questions for my little dots project... soooo i want to implement some sort of combat system 🙂 Each entity has some sort of health, which is no big deal because thats easy to realize ( Health{ health, maxHealth } )... furthermore there should be certain types of damage and resistence. For example magic damage, physical damage, true damage and other forms... and phsyical resistence, magic resistence and other forms. How would you realize the damage and resistence in components ? Each type one component ( PhysicalResistence{ strength... }? One component for damage and one for resistence with enums/strings as a generic variant ( Resistence{ type..., strength... } ? Or another variant ? ^^ Whats a common approach for this ?

#

Im still struggling with the data oriented mindset, so im glad for any help here ^^

zenith wyvern
#

I don't know if there's a "common" approach. You're describing a pretty complicated system with a lot of different components that need to talk to eachother

#

I was thinking about it for my roguelike. You could have combat represented as an entity with references to the attacker/attackees. You can have TurnBegin/TurnEnd systems, then other systems that operate between them that affect the combat entity in different ways before it reached the TurnEndSystem where the actual damage gets applied

#

That's a lot of boilerplate but I feel like it does a decent job of separating concerns

stone osprey
#

Thanks for the insight ^^ ! The main focus of my question lies on the different variants for representing dynamic content ( Resistence and Damage types in my case ) 🙂 Any ideas on those ?

hollow sorrel
#

i'd prob do the latter, Resistence with enum type

low tangle
#

bypass the indirection you have

zenith wyvern
#

But then you can't have multiple resistances

low tangle
#

give the native hash map to all of the monobeaviours, access though the singleton likely, stuff it into a field

#

have each access grab from it

#

don't copy memory before you need it

#

have the ability to fetch it

hollow sorrel
#

yea i suppose it would be a dynamicbuffer of resistances then
would normally keep things as simple as possible and do seperate component for each type, but then you'd prob end up with a lot of duplication since damage/resistance is usually applied the same way

zenith wyvern
#

Yeah I was just thinking that, like one component and system or at least job per type is a lot of typing

stone osprey
#

^ So its always some sort of trading with flexibility ?

zenith wyvern
#

You could use [Flags] on the enum and resolve it that way

#

Kind of awkward though

stone osprey
#

Like, the buffers are much more flexible in terms of "new" resistences e.g.

#

It also should be easy to add "new" types of resistences... so its probably better to keep the resistence flexible too

hollow sorrel
#

i think dynamicbuffer would still be pretty flexible
and if you have 4 (for example) different resistances in your game, you could specify your dynamicbuffer size as 4, and then specify an index in your enum per type so you can just do
buffer[DamageType.Physical] or whatever to get the one you want, so you don't have to do a bunch of searches

#

since i would assume the default value of a resistance would be 0, not null

#

so makes sense to preallocate that in the dynamicbuffer size i think

coarse turtle
#

if all the resistances use like the same struct but different values, you can stash all the values into an array and can fetch the value based on the flag value:

Resistance A: 1 << 0 would be accessed like so: log2(1 << 0) = 0, so you can access the 0th index of an array and fetch those values to apply)

zenith wyvern
#

Yes a buffer for the resistance type makes it more complicated than it needs to be I think

#

You can represent "DamageType" as a single enum. Reuse it for attack type and resistance. Then you can have a single system that checks for the resistance component and just checks if the resistance enum has the same type as your damage, and modifies damage accordingly

#

Kind of out of the scope of dots for sure beyond that

next latch
#

Anyone know of an up to date Dots tutorial? all seem to be from a year ago

zenith wyvern
blissful gorge
#

Have any of y'all had any problems with generic function pointers like FunctionPointer<Func<int, bool>> in bursted code? When I try it in burst-compiled code it works just fine, only running into errors with it in C# code.

gusty comet
#

A lot of the tutorials / sample content I'm looking at are outdated. Anyone got any recommendations for things to look at so I'm not exposed to depreciated ways of doing things?

coarse turtle
#

EntityComponentSystemSamples is your best bet

coarse turtle
gusty comet
#

Ah - yea I saw the pins but one of them pointed to the wiki which pointed to a few outdated tutorials

#

I'll check that one out tho

slim nebula
#

I'm completely lost been bashing my head at this for hours. I do this:

                        var sceneSystem = EntityManager.World.GetOrCreateSystem<SceneSystem>();
                        var subEntity = sceneSystem.LoadSceneAsync(scene.SceneGUID);
```then a few frames later sceneSystem.IsSceneLoaded begins returning true, but none of my subscene entities exist in the entity debugger. What am I missing?
#

what's the correct way to load a subscene? is this not it?

#

shouldn't this RequestSceneLoaded component be getting eaten by somthing in return for the scene actually loading?

#

i can't handle this I"m going nuts

#

is there source available for SceneSystem? I guess I have to look line by line and figure out how the serialization works?

#

Deprecated Deprecated ConvertToClientServerEntity, please use the sub-scene conversion workflow instead.

#

so if LoadSceneAsync is not the way to do this, what is?

#

I don't know how to load something only for client or only for server world if this is not it

#

is there some magic setting somewhere in options to enable subscene loading?

slim nebula
#

I'm trying to load a subscene with a single object with a single component. it just doesn't load. what am I missing?

#

I"ve looked at a million tutorials they all say the same thing. anyone?

#

has anyone here loaded a subscene before?

#

how dod you do it?

#

calling LoadSceneAsync 10,000 times per frame doesn't seem to help either

north bay
#

lol

#

LoadSceneAsync is the way to do it

slim nebula
#

😢

#

i dont... understand

north bay
#

So your object doesn't appear in the entity debugger after loading it on the server?

#

The scene seems to be loaded since it has the PrespawnInitialized flag in your screenshot

#

I'm sure there are other indicators for that but I'm not that deep into the sceneloading logic

slim nebula
#

so here's my subscene

#

it's in my main scene

#

I"ve confirmed the guid passed to loadsceneasync matches the .meta file of the scene

#

then I have my system

#
public class FUCKYOUSystyem : ComponentSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((Entity entity) =>
        {
        });

        bool working = false;

        Entities.ForEach((Entity entity, ref FUCKYOUComponent fuck) =>
        {
            Debug.LogError("WORKING WORKING WORKING WORKING WORKING WORKING WORKING");
            working = true;
        });

        if (!working)
        {
            Debug.LogError("FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL");
        }
    }
}```
#

my FUCKYOUComponent never shows up

#

no

#

I have to click reimport

#

is that all?!?!

#

/wrists

#

it might be working now.....

north bay
#

It should automatically reimport the scene if you do changes to it

#

But I do not really trust that to be honest

slim nebula
#

that's what I thought too... appears to be broken

north bay
#

Does it work now?

slim nebula
#

seems to be yes

north bay
#

yikes

slim nebula
#

I can delete the component and it breaks it and fixes it without having to click reimport now

#

so I guess it just got into some bad state?

#

thanks for helping

#

aaaaaand it's broken again. the fuck did I do

#

sigh

#

disregard

#

yes!!!!!!! it loads my stuff now

#

so happy

#

now to delete hours worth of debugging code and profanities haha

#

my favorite part of unity editor is the play button gamble. Click it and wait for 10 seconds to see if it did anything. It might work it might not. it might be playing and if u click it again it'll queue up a stop. great feature

stone osprey
#

Its me again... the discussion about stuff like damage and resistence brought me to new questions :c Lets say our mobs have weaknesses and strengths against either "weapon-types", "damage-types", certain "environments / locations" and other modifiers... how could we realize this in an extendable way ? Lets say we dont wanna use an enum or hardcode that many modifiers in our combat system... how would such a structure look like in component based design ? 😮

slim nebula
#

I think there's mane ways to skin this cat with ECS genar

#

your components could inheret some generic modifier interface

#

and be applied generically to hoever you plan to store the modified data

#

but that's just one option

#

I can think of a few

stone osprey
#

@slim nebula That sounds interessting... what do you mean with that ? ^^ generic modifier interface ?

slim nebula
#

like IComponentData

#

just add your own interface and use multiple inheritence

#

then you can cast ur different components to that interface and process it generically

stone osprey
#

Ah ok like "FireModifier : IModifier, IComponentData { ... }" ? ^^ But then we would need to iterate over each new modifier-type to calculate the damage result, right ? Which means tons of Entities.ForEach loops ^^

#

Or can we iterate over all "sub" types on an component ?

slim nebula
#

you could use an isharedcomponentdata to group things maybe to reduce to 1 query

stone osprey
#

Thanks, thats a good idea !

slim nebula
#

so I've got some game objects to organize hierarchy in the editor, but I don't need these as entities. Is there some component I can add on them to skip converting them?

#

or some other mechanism?

rancid shell
#

Is ECS pretty much the go-to architecture for Roguelikes?

vagrant lotus
#

IJobParrellelFor is only avaliable with .Schedule() or .Run()
is it not possible to have .ScheduleParrellel()?
(without using IJobChunk)

#

context of the logic
forloop (relatively small int)
forloop (relatively large int)

so it would not be optimal to to use
Entities.Foreach({
Job.Run()
}.ScheduleParrellel()

zenith wyvern
#

You can't schedule a job from inside a job

vagrant lotus
#

it should be Run(), sorry

#

just demonstrating the problems i faced

zenith wyvern
#

I'm confused by the question, IJobParallelFor is separate from ECS, it has no knowledge of chunks or anything

vagrant lotus
#

yes

#

it is a voxel terrain generation thing

#

it takes in data and output meshes

#

the number of entity to iterate over is low

#

but the number on executes in the generation is high

#

the IJobParrallelFor was from a non-ECS project before

#

i was experimenting with redoing the whole project in ECS

olive kite
#

Question regarding blobs: pre-ecs I would use scriptable objects instead of enums for a few reasons, but considering they are stored randomly in memory it would work against the concept of ecs. Blobs are immutable so it seems like they would be a good place to go in place of SOs, but they must be created each time, as they are stored in memory.. is that correct? and would the best workflow be to still store them as scriptable objects and then create blobs on startup?

deft stump
olive kite
#

ok cool. that seems like it would work just wanted to make sure there isn't any reason it would be bad to do

deft stump
#

since SO's, from my understanding, are also designed to be immutable as well. A block of data that you want to read from instead of writing to it.

olive kite
#

do you change any of your blobs runtime?

deft stump
#

nope

olive kite
#

for example, some of my scriptable objects i used as variables that could create separation between systems, like health

#

i'm assuming a new blob could be created and the old one disposed

#

but might not even need to do that with the change in architecture

deft stump
#

that's expensive to do, but yes, you can do that. dipose old and create new

olive kite
#

yeah that's what I thought, so will probably avoid.

#

thanks for the info! Do you load them like this?

deft stump
#

I'm not sure where to look

olive kite
#

sorry.. with the Addressable system?

deft stump
#

ah... no I haven't used addressables with ecs yet.

olive kite
#

you just create a normal blob and grab data through a mono maybe?

#

that would be an easy start

deft stump
#

from hearsay, I think there's going to an ecs addressables??? I'm not sure where I heard that.

deft stump
olive kite
#

cool.

#

thanks so much

vagrant lotus
#

my mistake

#

IJobParallelFor.Schedule() is the same as IJob.ScheduleParallel()

#

so there is no IJobParallelFor.ScheduleParallel()

#

and there is no need

#

@zenith wyvern thanks for help

tame sigil
#

@amber flicker isn't you who making a tween tool for DOTS ? can I have a status about it ? I'm interested 🙂

amber flicker
#

Thanks for remembering @tame sigil - still a month or two away from getting it to some beta testers but doing my best to get it to that stage asap 💪

tame sigil
#

nice 🙂 thanks for update

amber flicker
#

np - feel free to add me on twitter or dm me for my discord if you want to stay more up to date

distant imp
#

Nvm, I just needed to add it to package manifest dependencies 🤦‍♂️

safe lintel
#

theres a dots animation forum! 🥳

gusty comet
#

Are subscenes more efficient than the convert to entity script? Even if it's only one gameobject?

stone osprey
#

How did you realize damage in ecs ? Each of my entities owns a "Health" component... thought about a "Damage" component that stores incoming damage for the attacked entity, that would be easy extendable. We could have an shield system that iterates over the incoming damage to absorb it. The other way is having some sort of damage event which connects two entities, less flexible because our shield system couldnt iterate directly over the entities... instead it needs to iterate over damage events. What would you choose ?

zenith wyvern
#

I feel like the damage event (represented by it's own entity) makes it more flexible. By definition one thing damaging another involves exchanging data between two entities, so trying to force it all onto one of the two doesn't work.

#

If you later wanted to do something like give experience to the entity doing the damaging, then you need some way to refer to the damager anyways

stone osprey
#

@zenith wyvern Thanks ! Thats right ^^ Furthermore it decouples the logic a bit. So lets say we have an damage event and the hit entity has some sort of "ResistanceModifiers" that should reduce or maximize the incoming damage... so we would simply iterate over the damage event entity, check if the hit entity has this component to apply the modifiers ? What if the hit entity doesnt have such an component ? Thats the only part that feels strange, i hope you understand what im trying to describe. A natural ecs applys its logic to all entities containing some component... an event however, only connects two entities and therefore its a bit harder to implement logic to reduce/increase the damage... or am i missing something here ?

zenith wyvern
#

@stone osprey

CombatSystem => 
Generates "Combat" Entity. Combat Entity has data for damage and entity references to things involved in combat.
Also Generates "BeginCombat" *component* on attacking and defending entities. These gives the attacker/target a reference to the combat
so they can affect it before it gets resolved.

DamageBonusSystem => 
Entities
    .ForEach((Entity e,
    in DamageBonus bonus,
    in BeginCombat begin)=>
{
    var dmg = GetComponent<Damage>(begin.combatEntity);
    SetComponent<Damage>(begin.combatEntity, dmg.Value + bonus.Value);
}).Schedule();
// Remove "BeginCombat" component

ResolveCombatSystem =>
Entities
    .ForEach((Entity e,
    in Combat combat,
    in Damage damage) =>
{
    var targetHealth = GetComponent<Health>(combat.target);
    SetComponent<Health>(combat.target, health - damage);
}).Schedule();
// Destroy Combat Entity here

Rough draft of what I was thinking of

#

May or may not work

#

Just kind of the idea I had in my head

gusty comet
#

I have a blank HDRP project and I added the hybrid render. Immediately I get this weird semi-pixelated look everywhere that wasn't there before the hybrid render was in.

It may look slight in these pictures but when you're moving around the checkerboard noise effect is really noticeable (look at the edge of the light to see it best)

stone osprey
#

@zenith wyvern Thanks a lot for your time ! 🙂 That helped a lot ! ^^ So our combat system spawns in a combat event entity... then the damage bonus system comes in and increases its damage and the resolve system applys the damage to the target.

zenith wyvern
#

Exactly. It's a lot of indirection but that's what you have to deal with when you want entities to talk to eachother in complicated ways

#

And it seems like it should be pretty flexible

#

And the same principle for resistance. It queries for BeginCombat and Resistance and changes the combat damage based on the damage type as needed

#

I guess you might need BeginCombatAttacker and BeginCombatDefender actually

stone osprey
#

This is actually great, because in my previous draft i had something like "Damage{ amount }" on my target entity... this changed later to "Damage{ list<float> amount }" because one entity can receive damage from multiple other ones and then i changed it to "Damage{ list<damageDesc> damages}" because i also wanted to involve different damage types... but having an damage event that stores stuff like type makes it much more composition based. BUT the "Damage" component on the target entity stays as some sort of consumer right ? So the event only calculates the damage and passes it to the entity-damage component. And that component value gets applied to the health ?

#

ah nevermind... just saw in code that "Damage" is on the event and that the event system substracts it from the targets health ^^

zenith wyvern
#

The combat entity can just use a buffer of entities for targets rather than a single entity

#

Ah I guess that wouldn't work, you would need individual damage for each entity so they wouldn't affect the damage for unrelated targets

#

I guess for that system to work you would just need to generate one combat entity for every target, and just have the same attacker as the source in every case

gusty comet
#

Why generate an entity at all? Why not just run systems on the entities involved?

stone osprey
#

But thats totally fine ^^ its not like there thousand of entities attacking each other in my game

zenith wyvern
#

@gusty comet The entities need to be able to affect the data before it gets resolved, and the attacker and the defender want to affect the data in different ways. Having data that both entities are trying to affect live on either one of the entities sounds like a nightmare

#

Or maybe I'm just missing something there

gusty comet
#

I was just thinking if an entity has health then it is capable of being either an attacker or a defender so just code a system for checking if you're being damaged and a system for checking if you're damaging something

#

Also on my pixilated problem, this is now happening with blank HDRP no-dots projects even though I have an existing blank hdrp no-dots project where this is not a problem and they're on the same version....

agile dome
#

@gusty comet The discussion was around an extendable damage system. Dealing the damage itself doesn't really seem to be the problem.

gusty comet
#

Right but I don't see how this wouldn't be extendable.

zenith wyvern
#

Could you elaborate more? How would you handle the attacker having a damage bonus and the defender having damage resistance?

gusty comet
#

If characters can have resistances, just run the for each on all entities that have health and resistance and then lower the entity's health by the damage inflicted * resistance modifier. It would be complicated with more variables but I would imagine the damage entity you're using will also get rather complicated

#

I guess I'm making the assumption that attackers and defenders have the same attributes

neon shard
#

Hi, no idea if I've stumbled into the wrong house, but we're a bit stuck on an issue and have so far failed to find any info to help.
We have an existing app built in Cordova (I know) and are trying to implement some AR functionality. Eventually we have come to the point of trying to integrate a Unity instance into the code using a plugin.
We have successfully compile the Android version and have one error when compiling the iOS version which is apparently a missing library:
ld: library not found for -lUnityARKit
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not even the dev, just desperately trying to find some pointers 😬

neon shard
#

Thanks!

slim nebula
#

is there any way for me to change this from 4 to like... 30... just so it goes away while I'm working on other stuff?

deft stump
#

you can't change allocator life time.

#

either change it tor allocator.permanent or respect the allocator lifetime.

slim nebula
#

it's unity preview packages doin it. I havn't allocated anything myself

deft stump
#

oh

#

then....

#

idk

#

XD

slim nebula
#

XD

#

yeah I figured i'd probably have no solution

#

I'm just OCD and hate warnings