#archived-dots

1 messages · Page 226 of 1

stone osprey
#

Depends, it takes a few seconds till the player reaches the item in the most cases ^^

#

But i probably found some sort of solution...
Pickup{ entity item, int amount, abortConditions} and a system just checks if that player is still moving to that item or if he changed his move to location... if so it removes the component. I guess thats the simple way of doing this

pliant pike
#

why wouldn't you just not add it until the player has pressed the button

stone osprey
#

That was the plan... but what happens if the player double taps to cancel the pickup action ? Atleast that should be possible because he will start moving to that destination.

#

But a system checking that condition should solve this problem

pliant pike
#

what if you have more than one item close to the player

#

I don't know you shouldn't really need to cancel picking up an item I don't know of many games that do that

#

there's only Red Dead that I can think of that has really slow pickup animations that you might want to cancel but why would you want to copy that game's mechanics leahWTF

finite breach
#

Simple way would be to have a component Action { Entity e } on your player entity and put PickUp{ Entity itemOnGround } and a PickUpItemSystem{} on the action Entity. Then check your input for a double click and remove/destroy the action component on the player.

sour atlas
finite breach
#

If you use DrawMeshInstancedIndirect than yes

#

Any reason why you do not want to use Hybrid Renderer?

sour atlas
#

because i dont know what that entails

#

im just trying to render sprites on quads

#

so if theres a better way please do tell me how that works

finite breach
#

I dont know you level of Unity or coding but you can take a look here:

sour atlas
#

oh yeah the main problem with that is unless i misunderstood or missed a part is that i dont think i can manipulate the materials shader for each entity as they all share the same material ?

finite breach
#

Hybrid Renderer V2 allows material overrides for the shaders

sour atlas
#

ah thats great! gonna have to figure out how that works then :)

finite breach
#

It will save you a lot of work on the sorting and culling etc... if you use the hybrid renderer. Basically you attach a few predefined components to your entity and it get automatically rendered in game

sour atlas
#

ah thats great. i pretty much have a functional pipeline but the main issues with it are that everything thats fast cant be depth sorted in the same pipeline as the dynamic quads so if the hybrid v2 gets a fraction of that performance without that problem then im happy :)

finite breach
#

Did you use Bursted Jobs in your previous attempt?

sour atlas
#

yup

#

the idea was to have render batches based on layer and material, do spatial registries into pre defined chunks and then for every layer sort every entity with that material inside the chunks in parallel, merge all sorted chunks into one pipeline, render, repeat.

finite breach
#

Don't know specifically for this example if HRv2 is going to be faster in this case. Testing will be the only option I guess 🙂

#

I am just working on something similar at the moment with the HRv2 but I havent finished it yet so I can really comment on the performance

sour atlas
#

its going to be more flexbible. i need flexibility AND performance not just performance haha

finite breach
#

That is usually the case 😆

sour atlas
#

cant expect the environment artists to create a render pass order for every single layer lol

finite breach
#

Is it 2D or 3D you are doing?

sour atlas
#

2D but with a Z-Axis

finite breach
#

So a simple sort on the z-axis per material is not possible?

sour atlas
#

well it is but then i lose the performance of using large batches

#

e.g if its ordered like
mat A
mat A
mat A
mat B
mat A

(silly example but it scales)
drawing matA all at once is going to be much more efficient than drawing matA 3 times, then matB and then matA

#

right now its doing the former

finite breach
#

Is it a lot of static meshes or quite dynamic?

sour atlas
#

well the bulk is probably going to be environment related

#

so static for the most part.

#

i think.

finite breach
#

Well as long as the materials use the same shader, HRv2 can use the SRP batcher to batch all materials with the same shader and can also keep data on the VRAM. So no loading form DRAM to VRAM.

#

In my case (I am working 2D tile map) I do all my sort through z-index and I can do 50k quads under 0,75ms (altough most is static)

timber ginkgo
#

I have a situation where I want to have a dynamically updated native hashmap or array of some kind, but I'm not sure if I should use some large-limit-sized persistent array, or allocate a new one every tick (I will need to populate the new list from the old one)

#

it's a fixed update tick-to-tick sort of function...

#

any advice or thoughts?

#

size could be anywhere from 1 or 2 to 100 or 200

hollow sorrel
#

@timber ginkgo if you're reallocating every frame and not using it from other threads, Allocator.Temp is basically free if you can get away using that
if it has to be persistent then yea alloocating one with large limit is prob better to avoid reallocating

timber ginkgo
#

i cant be sure whether or not there will be threading issues: I'm essentially remaking the OnCollision events system, and the dynamic list is a bunch of "collision pairs" that are needed for detecting the Enter,Stay, and Exit events.

#

I think I could probably use some sort of out parameter to make it thread safe (i.e: the events will fire on the next fixed update from the main thread using a list generated from the job)

hollow sorrel
#

yea in that case you prob don't want Allocator.Temp since it only lives for one frame (update frame, not fixedupdate frame) and can't be used from other threads

timber ginkgo
#

roger that.

sour atlas
#

instead i use a single material and add the texture in a shader

timber ginkgo
#

Got another interesting dots question:

I have a situation where I need to store various settings for every rigidbody in a scene (custom settings like material type or other references). I need to access them via ridigbody instanceID, so I was wondering if I should have a dictionary based hash map that uses instanceID as the key and a custom struct as the value (a struct containing the custom data), or if I should use a nativeHashMap for each individual custom parameter. I'm worried that having too many persistent hashmaps would create issues vs the benefits of a native hash lookup

#

perhaps i could encode parameters in the place values of an itneger

coarse turtle
timber ginkgo
#

just realized that using things like int4x4 as a value in hashmaps opens the door for a lot of potential (far better than a digit based encoding)

#

wrote this func to pick out individual digits of an int or float, but intuition tells me it's god awful

#
    {
        return math.floor(integer % math.pow(10, place +1) / math.pow(10, place));
    }```
timber ginkgo
#

additional question: is there a way to quickly set every value in a hash map without affecting the keys?

karmic basin
#

Add comments :p Other devs would expect use of 4x4 for matrices for example but for a custom data storage I wouldn't want to guess intended usage. A bitmask would be more expected I guess

timber ginkgo
#

it's kind of like a bitmask, but with each place value being a 0-9 integer for more dynamic encoding

#

that function is merely to grab the specific place value in a given int

#

(oh i think i see what you mean; and yes you're right)

#

was considering something with enums and properties (as a way to keep things legible)

karmic basin
#

You're exploring dots tech on its own or to apply it to your evolution sim ?

#

Oh just remembered you were also playing with physics and VR lately ^^

timber ginkgo
#

it's more or less related; I am using the new contact modification API and i need to make my own collision event stuff

#

since the callback is outside of the main thread (meaning i need native collections), and since i need to deal with a crap ton of rigidbodies (at least hundreds), jobs code is about the only way to keep it scalable

karmic basin
#

oh okay so Jobs and Collections

timber ginkgo
#

yep. the collision system is going to be the core of all the dynamic sound/vfx stuff in addition to doing physics work, so i'm putting in the effort to make it good

#

I have got it mostly worked out, just the specifics of native code are a bit new

karmic basin
#

Did it went scope creep ? 🙂

timber ginkgo
#

more like scope big bang

#

lol

karmic basin
#

🙂

timber ginkgo
#

some snake friction using the contact mod API

#

since everything keeps working, i gotta keep trying lol

#

locomotion using contact modification is also really swell

#

the "threaded" (non-main thread, but not jobified) code for doing this sort of thing is a bit of a nightmare, but it's informative

#

eg: for locomotion ``` private void ModifyGroundLocomotorPair(ModifiableContactPair pair, float3 worldLocomotionVector)
{

    for (int i = 0; i < 1; i++) // pair.contactCount; i++)
    {

        ContactModType colliderModType;
        modifiableColliders.TryGetValue(pair.colliderInstanceID, out colliderModType);
        if (colliderModType == ContactModType.Locomotor)
        {
            Vector3 wrldloco;// = worldLocomotionVector;
            //align with collision surface
            wrldloco = Quaternion.FromToRotation(currentUp, pair.GetNormal(i)) * worldLocomotionVector;
            pair.SetTargetVelocity(i, wrldloco);
        }
        else
        {
            Vector3 wrldloco;// = worldLocomotionVector;
            wrldloco = Quaternion.FromToRotation(currentUp, -pair.GetNormal(i)) * -worldLocomotionVector;
            pair.SetTargetVelocity(i, wrldloco);
        }
        if (pair.GetSeparation(0) > 0.01f)
        {
           feetTouch = false;     
        }
        else
        {
            feetTouch = true;
        }
    }
}```
karmic basin
#

I love everything you do 😛

sour atlas
#

NativeMultiHashMap returns a NativeMultiHashMap Iterator but i need the values as a NativeArray or NativeList, is there a way to convert that iterator without looping over the entire structure and copying each value ?

heady edge
#

Hello folks, quick question: when do systems in unity ecs update their queries? is it before update?
will it be safe to call a method of a system A from system B update, if said method does something with EntityManager and queries?

molten flame
heady edge
#

basically what I'm asking is can it be safe to do

public class SystemB : ComponentSystem
    {
        private EntityQuery query;
        protected override void OnCreate()
        {
            query = GetEntityQuery(ComponentType.ReadOnly<Damage>());
        }

        protected override void OnUpdate()
        {
            //do whatevern
        }

        public void OnSystemACall()
        {
            using var entities = query.ToEntityArray(Allocator.Temp);
        }
    }
    public class SystemA : ComponentSystem
    {
        private readonly SystemB _systemB;

        public SystemA(SystemB systemB)
        {
            _systemB = systemB;
        }
        
        protected override void OnUpdate()
        {
            _systemB.OnSystemACall();
        }
    }```
robust scaffold
#

I just wish unity would give us some update...

heady edge
#

Another thing, can code inside OnSystemACall() be burst compiled?

karmic basin
karmic basin
heady edge
#

I'm not concerned about ECS purity right now, just about the possibility of making such calls

#

discussion of why I want to do it and is it a good idea is another matter entirely
(also if I remember correctly boids demo had some system to system calls anyway)

karmic basin
#

Well then yeah of course like always you can fight against and break the pattern as far as you manage until it falls down below your feet

#

So do it and you'll see where you can push it

#

Depends how much free time you have available i guess

heady edge
#

don't be passive aggressive like that

karmic basin
#

Im not. Just saying yeah go ahead do it while it works

#

👍

sour atlas
#

yeah that seems to return all values

#

and to get all values for a specific key i need to use the enumerator. which implements a private native array.

sour atlas
#

i had the wrong file openend. thats why i thought it was using a native array

#

either way any other ideas ? i can still just copy each value individually but thatll slow everything down a bunch.

#

i think if i can get the count of values for each key i can copy from the array containing all values 🤔

karmic basin
#

You can access by key if you know it, no need to iterate over all values

sour atlas
sour atlas
#

thats for a NativeHashMap not a NativeMultiHashMap

karmic basin
#

Oh damn

#

I'm sorry I misread then

#

so you retrieve all values for one specific key. And you want to bypass the enumerator because you know you gonna use all of them ? I don't know if there's a way

#

I would just iterate and build the container myself, and focus on my next true problem

sour atlas
#

but building the container one value at a time is really really slow for large containers

coarse turtle
# karmic basin Just like an array, access by index

nativemultihashmap uses unsafehashmapbase internally. The iterator grabs a pointer and iterates through that. So if you really want to avoid the iterator, you'll need to make an extension function which just grabs the pointer and returns it as nativearray of sorts

#

ah whoops I replied to the wrong person @sour atlas ^

karmic basin
#

That's the kind of hassle i never go through but good to know 👍

sour atlas
#

yeah thats what i thought ill have to do. i cant edit the class itself though, can i extend classes like in e.g ruby ?

coarse turtle
sour atlas
#

👍 thanks

#

will get to that tomorrow

jaunty herald
karmic basin
#

Alright good to know too 👌. I'd still keep it for a few cases only, not build everything around it :)

jaunty herald
#

Yeah definitely try to avoid it where possible 👍

#

imo it's usually a tradeoff between performance and how close you want to stick to the ECS pattern (which usually results in more decoupled systems and cleaner code)

acoustic spire
#

Can ECS guarantee that if I create a set of entities in special order it will preserve this order? I won't remove it

#

By this I want to get rid of Index component and avoid using dynamic buffers

jaunty herald
#

I wouldn't depend on it

sour atlas
#

i dont think entity indices are even guaranteed to stay the same during run time

jaunty herald
#

Are you sure? If they didn't it would mean all references would need to be remapped

#

Not sure how that would work

acoustic spire
#

hmm, probably the entitites will be moved if I change archetype, right? (eg add a tag)

jaunty herald
#

They will be moved, but the entity id and index shouldn't change afaik

acoustic spire
#

yeah right

stone osprey
#

My ECB sets a component every frame to some entities for updating them...
At some point one of those entities gets deleted, however my ECB still sets the component for it which results in an error because that entity does not have that component anymore... well it was deleted.

Any idea how i could solve this issue ? Is there a "ecb.SetComponentWhenEntityIsStillExistant()" ?

#
                    var childEntity = parent.children[index];
                    if (HasComponent<Child>(childEntity)) ecb.SetComponent(childEntity, new Child{ parent = entity });
                    else ecb.AddComponent(childEntity, new Child {parent = entity});

This is basically my problem... as you can see im checking if that child has an component, set component using the ecb.
But at some point the child was removed and the ecb still tries to set that cmp

#

Any ideas ?

amber flicker
#

You have to make sure you either don’t destroy the entity, don’t destroy the entity until after the above system, run this system after the entity is destroyed or have an intermediate step where you tag/set bool or put the entity to delete in a container (that’s checked by this system). This is partly why I’ve never found ecb’s that useful myself. By the time you’ve guaranteed the order of things you often may as well use EntityManager.

stone osprey
timber ginkgo
#

is there a performant way to set all the values in a native collection (without affecting keys) without iterating through the whole thing?

timber ginkgo
#

also, is this sort of approach really the only way to iterate through a antive hashmap without a pre-existing key array?

#
private NativeHashMap<int2, bool> collidingRigidbodyPairs;
private void DetectCollisionExits()
    {
        NativeArray<int2> valueArray = collidingRigidbodyPairs.GetKeyArray(Allocator.Temp);
        for(int i = 0; i < collidingRigidbodyPairs.Count(); i++)
        {
            if (!collidingRigidbodyPairs[valueArray[i]])
            {
                // collision exit event here
            }
        }
    }```
sour atlas
sour atlas
timber ginkgo
#

i see

#

thanks for the info!

coarse turtle
#

don't think for each is supported in NativeHashMaps 🤔

jaunty herald
sour atlas
#

🤷‍♂️ maybe it was in the context of bad practice, i really don’t remember

jaunty herald
#

🤷

#

Unless you mean the "version" part of the entity, and not the "id" part.

Because the version changes all the time

amber flicker
#

deleted nonsensical reply

heady edge
#

what do you mean ids can change? Entity id remains the same (points to the same set of components) until the entity is deleted and once the same id gets used for another entity, version goes up.
There is no practical way to change Entity struct everywhere it is saved.

amber flicker
#

Sorry you’re right. I was thinking about ordering within chunks. Shouldn’t be replying when I should be sleeping 😴

sour atlas
jaunty herald
#

(if the IDs are reused)

#

Ah nvm, the entity version is only increased if the entity is destroyed, like you said

#

I was thinking of the chunk versions which increase every time a chunk is acquired with a writelock

heady edge
jaunty herald
#

How are they unsafe?

heady edge
#

in the sense I've described

#

you can theoretically end up with a reference to another entity

jaunty herald
#

I don't understand, how are you ever going to get an incorrect reference if the version increases each time (barring an overflow)

heady edge
#

overflow exactly

jaunty herald
#

Well yeah ok, but besides that they should be stable

heady edge
#

yeah

sour atlas
coarse turtle
#

look up extensions methods in c# and with my example my return type was void, if you need it to return something then you should make it return something

#

if you need other parameters also, then you'll need to include that also

sour atlas
#

ah alright, i think i got it 😄

sour atlas
#

nevermind, i cant seem to actually get the pointers i need to copy to a native array, if youre not busy can you help me out ? @coarse turtle

coarse turtle
#

I'd recommend looking through their source and just following along, you probably want to look at UnsafeHashMapBase's TryGetValue/TryGetNextValue and replicate that

#

You'll notice that that's where they get a pointer and you can potentially iterate

sour atlas
# coarse turtle I'd recommend looking through their source and just following along, you probabl...
public static unsafe void GetNativeArrayForKey<TKey, TValue>(this ref UnsafeMultiHashMap<TKey, TValue> self, TKey key)
        where TKey: struct, IEquatable<TKey> where TValue: struct
        {
            TValue item;
            NativeMultiHashMapIterator<TKey> iterator;
            self.TryGetFirstValue(key, out item, out iterator);
            TValue* ptr = &item;
        }

im feeling really silly now, as far as i understand what im trying to do this is how it should work but it just doesnt for probably obvious reasons :b

#
public bool TryGetValue(TKey key, out TValue item)
        {
            NativeMultiHashMapIterator<TKey> tempIt;
            return UnsafeHashMapBase<TKey, TValue>.TryGetFirstValueAtomic(m_Buffer, key, out item, out tempIt);
        }

doesnt help much either since UnsafehashMapBase is internal

coarse turtle
#

assembly defintiion references allows you to access internals since your script will be compiled 'into' Unity.Collections

remote crater
sour atlas
coarse turtle
#

You'll probably need to make sure .csproj files are generated for those packages too

sour atlas
#

👍 ill try that, thank you

#

In the Project window, locate the folder containing the scripts you want to include in the referenced assembly.
uh does that mean i should put it in the Extension folder or the unsafehashmap folder ?

coarse turtle
#

Just stick in your Assets/Scripts directory or whereever you want

#

you're going to reference the Unity.Collections assembly

sour atlas
#

ah right, that makes sense

#

still not able to get it to work

coarse turtle
#

That's not an assembly definition reference, that's just an assembly definition, they're 2 different things 🤔

sour atlas
#

oh fuck youre right

#

FINALLY got it working, thank you !

hybrid portal
#

Unity.Physics' package doc for ray casts in DOTS is outdated/inaccurate 🤦‍♂️ nothing in ECSSamples either, anyone know how to raycast with DOTS??

sour atlas
#
Entity Raycast(float3 from, float3 to)
    {
        BuildPhysicsWorld physicsWorld = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildPhysicsWorld>();
        CollisionWorld collisionWorld = physicsWorld.PhysicsWorld.CollisionWorld;
        RaycastInput input = new RaycastInput()
        {
            Start = from,
            End = to,
            Filter = new CollisionFilter()
            {
                BelongsTo = ~0u,
                CollidesWith = ~0u,
                GroupIndex = 0
            }
        };
        Unity.Physics.RaycastHit ray = new Unity.Physics.RaycastHit();
        if (collisionWorld.CastRay(input, out ray))
        {
            Entity e = physicsWorld.PhysicsWorld.Bodies[ray.RigidBodyIndex].Entity;
            return e;
        }
        else
        {
            return Entity.Null;
        }
    }

this is a very crude raycast method i wrote a while ago.

#

might still work

sour atlas
#

is there no way around being unable to schedule jobs from other jobs ?

remote crater
#

Is there a way to tell an entity's name from ECS/DOTS/ SystemBase ?

#

like after:

timber ginkgo
#

How should i arrange a way to nativeHasMap-lookup a struct(by a rigbody instanceID)? Should I have a native array of the structs-in-question, and a secondary <int,int> hashmap using instanceID's as the key, and the associated index value for the native array containing the structs?

#

im guessing there's a more direct way to do this

coarse turtle
timber ginkgo
#

what do you mean?

coarse turtle
#

NativeHashMap<int, YourStructType> map

timber ginkgo
#

I tried doing this but i ended up concluding it's not possible

#

perhaps i was using the wrong kind of struct 🤔

#

it said non-nullable (non-value types?) aren't permitted

coarse turtle
#

the struct has to be blittable, which is pretty much the only requirement

#

so class references aren't allowed

timber ginkgo
#

im assuming a Rigidbody component reference isn't blittable lol

coarse turtle
#

Yeah it's not

timber ginkgo
#

that's essentially one of the main points of the struct

#

i need to associate a bunch of extra parameters with rigidbodies

#

some of them dynamic

coarse turtle
#

Well even then you won't be able to include it in a NativeArray

#

since your structs have nullable fields and such

timber ginkgo
#

I was considering having my rigidbody list sit in an old fashined array

#

and put an index reference in the structs

coarse turtle
#

ah yea that's fine

timber ginkgo
#

right now im using a dictionary which i hate for some reason

coarse turtle
#

Yeah by then doing a NativeHashMap<int, int> to map to an index to a NativeArray is fine. Otherwise a different step would be to hash a rigidbody and get an index, which would be your key in a native array if you want to avoid the whole NativeHashMap

#

pretty much writing your own hash map

timber ginkgo
#

I didnt realize that a native array could use keys (figured it was just an ordered list)

coarse turtle
#

well no, its just a fixed sized list

#

but you can technically just get a hash from a rigidbody that maps it into an index, thus treating your NativeArray as a hash map

#

the former approach is just much simpler to do without having to write your own hash function and such

timber ginkgo
#

i see

#

now that i know how to use a hashmap with structs, it seems like the best bet

#

thanks very much for your insight and help!

coarse turtle
#

np

wintry ermine
#

ummmm

hard wagon
#

Wonder why my capsule player keeps disappearing when entering the runtime? I have rendering.hybrid enabled and pretty much all DOTS stuff (entities, mathematics, jobs, you name it). Where do I look after if gameobject keeps disappearing? I can see them in the DOTs profiler tho?

sturdy rune
#

It becomes an entity, no longer a game object @hard wagon

#

Look in the entity debugger in runtime, it should be there.

hard wagon
#

I don't mean that I can't see them in the hierarchy, I understand that, What I actually mean is that the entity itself, even with the rendering stuff, turns invisible when play in game.

#

I can see it in the scene at editor time, but when I enter the playmode, they disappear. This same thing happen to the other game object that doesn't have anything complex, but shapes. And they too disappear. I'd like to know where I need to look for, or understand why they're invisible when playing.

#

What rendering settings does DOTS currently support in 2020.3.11f1?

digital kestrel
#

no tuples in Native Containers?

karmic basin
vagrant lotus
#

where to get started on DSPgraph?

heady edge
#

does anybody know a way to quickly replace all components on entities with components from another entity?

#

without writing manual per component copy code and deleting all old components

slim nebula
heady edge
#

yeah the point was to make entity replacement hidden from all other entities

stiff skiff
#

Any news on the ECS lately?

pliant pike
#

we're still using it!!

hard wagon
#

Can someone help me understand what I did wrong? Anything I add to Convert To Entity, would rendered the object invisible. I've seen video showing that they should appear in the game once they added the component on game object. Wish I understand why unity is keep rendering them invisible! frustrated!

safe lintel
#

@hard wagon do you have the hybrid renderer package installed?

hard wagon
safe lintel
#

hybrid renderer also requires urp or hdrp

hard wagon
hard wagon
#

@safe lintel I am using HDRP settings, fresh out of Unity's 3D package. I've added other package as well, but don't think this directly impacts the rendering for using DOTS. This is what it looks like in scene. I've got a player model, and a plane/sprite as a reference. The player model got some componentdata attached, but the plane/sprite does not. Both of them turns invisible when played in unity. (I've intentionally left the other blocks alone to see if it was a unity kind of thing)

#

This pisses me off that I can't easily work using DOTS right out of the package, less alone trying to troubleshoot this nonesense just to make this functional and working 😦

sour atlas
#

im having the same issue right now.

pliant pike
#

Check there positions maybe, that they aren't flying of somewhere

hard wagon
#

They're not going anywhere afaik

#

They're "There", but invisible.

left oak
#

well, convert and destroy is not right, if you want to keep the gameobject around

#

which I thought you mentioned earlier

hard wagon
#

Then that wouldn't be a pure ECS?

left oak
#

definitively not

#

but weren't you talking about rigidbodies earlier?

#

that's not pure ecs either

hard wagon
#

Then how exactly can I apply ECS to Unity??? I'm now being resort back to use object oriented design instead of using the data oriented design

left oak
#

ecs is not feature complete

#

it is a preview package

#

it is on equivalent to classical unity

#

*not

coarse turtle
#

i dunno much about hybrid renderer, but does the HybridRendererV2 systems run? If it's not then that's probably the reason you're not seeing something 🤔

left oak
#

yeah i'd wonder about material instancing as well

hard wagon
#

I have enabled the system precompiler to use hybrid rendering v2. The fact that I cannot have the gameobject destroy kinda defeats the whole purposes of having a pure ECS...

#

but since that stops the gameobject from being invisible makes it somewhat a workaround for the time being.

left oak
#

you can totally render entities without gameobjects

#

but it's not ready to go straight out of the box

sour atlas
#

for me adding the URP asset to the graphics settings fixed the issue.

safe lintel
#

@hard wagon so what does the inspector & entity debugger show for the entity you want to render? like pics of it before conversion and after conversion

hard wagon
safe lintel
#

the samples repo is a good starting place to get familiar with the current concepts of dots

hard wagon
#

Where are those example repo? The one I downloaded from Unite Copenhagen doesn't work. All I get was just the main menu, and nothing else. It literally broke Unity. It only works when I created an output build. (But it's just the main menu...?)

safe lintel
#

bottom of the first post in the pinned messages here

hard wagon
#

Thanks! Pretty sure that's where I got the examples from, but will try again.

zenith wyvern
#

If you have everything set up correctly and it's still not working I found toggling the batching setting on the graphic settings asset (and possibly restarting afterwards) fixed it for me after all else failed

broken cradle
#

hey i would like to make a parralel for with dots, but on a 2 dimensionnal array, it seems like we can't do this however
NativeArray<NativeArray<float>> grid;
How can i figure this out ?

zenith wyvern
#

You can't nest native containers. If your arrays are a set size you should just use a flattened 2D array

#

If they're dynamic you need to get more creative, you can use UnsafeList<NativeList> or maybe NativeMultiHashMap

broken cradle
#

this is fixed size fortunately, i have to rewrite my whole code to use a flattened array and it's kinda huge 😢

zenith wyvern
#

Imo it's the best option. You can even run parallel jobs over the array assuming you're being sensible about not accessing the same indices

broken cradle
#

i think the parralel for will suffice, i need this to reach below 10ms, currently it takes 200ms to run, it's for a real time pathfinding

zenith wyvern
rugged grove
#

do I need to declare dynamic buffers as readonly?

zenith wyvern
#

In what context?

rugged grove
#

in ForEach job

zenith wyvern
#

If it's a parallel job yes. For single threaded jobs you can safely write to them in the ForEach

rugged grove
#

that's a bummer. I thought I had a neat system that would make my life way easier.

#

Basicaly I access a tile map a lot in a lot of places. So I hoped I can make a TileReader that I can declare in one simple line and use.

zenith wyvern
#

Not sure what you're trying to do there but it's not safe to let a reference to a dynamic buffer leave the scope it was created in

rugged grove
#

If there was a way to do EntityManager.GetReadOnlyBuffer() to declare it readonly that way...

zenith wyvern
#

They only make sense being accessed via the entity they reside on

rugged grove
#

I'll dispose, no problem

zenith wyvern
#

You shouldn't dispose them either. The whole point is the ECS manages them so you don't have to

broken cradle
#

thanks for the ressource it will help me

rugged grove
#

the use case:

rugged grove
zenith wyvern
#

Not dynamic buffers. They are created and disposed of by the ecs. Their existence is tied to the entity they are attached to.

#

If you want to "pass them around" you should be passing around the owning entity, and always access the buffer through that via a BufferFromEntity

rugged grove
#

wait.. what are you talking about

#

TileReader leaves the scope when Update method ends

#

leaves the scope means it ceases to exist

#

its a struct

zenith wyvern
#

Yeah I see from the code you posted it will only exist for that frame, so that should be fine. You should try to avoid retrieving dynamic buffers on the main thread if you can though, in my experience it can cause a lot of syncing issues. Better to just pass the owning entity into the job and get the buffer via a BufferFromEntity

#

I did something similar to what you're doing when I was working on my block game in dots, it was a real headache to manage the buffer dependencies

rugged grove
#

the lack of readonly declaration is my main concern there, there must be a way to make it work still without making it verbous

#

now a noob question. if I go WithReadOnly(tileReader.TileBuffer) will it work?

zenith wyvern
#

No. You're accessing the buffer as read/write when you use EntityManager.GetBuffer

rugged grove
#

oh..

zenith wyvern
#

That was my solution

#

With a lot of extension methods to access the relevant data from all the different buffers

rugged grove
#

this will work, thanks.

#

damn.. extension methods.... I couldn't figure out how to extend a struct without inheritance XD

#

this is ver very helpful

zenith wyvern
#

Actually looking at it I wasn't using extension methods, just lots of different structs for different kinds of access

#

In the end I couldn't figure out a nice way to make it all work together so I gave up. Good luck

rugged grove
#

thanks for the.. encouragement.. X)

rugged grove
#

generics could help with accessing different types of data and making different readers without copy-pasting code

#

@zenith wyvern

#

the api sucks a bit since it's not explicit, but it works..

zenith wyvern
#

That's a good idea, but my biggest issue by far was dealing with job dependency errors between the different jobs that were going to access my world data

#

What I came up with worked as a starting point because my block representation was super simple, the real issue was figuring out how to make it play well with parallel jobs combined with the user potentially being able to access/change it at any point

#

I imagine somone with more experience writing games that use multithreading would have a lot more luck. For me just trying to work that all out made my head hurt too much

rugged grove
#

I would imagine that in absolute majority of cases it is acceptable to wait for a sync point. so to totally avoid structural changes in the middle of the frame

#

just sync once. sounds easyX)

zenith wyvern
#

I suppose so. I could have had change deltas based on user inputs, changed the world on those in one job, then world gen next. I also ran into a huge headache trying to rely on change filters. It seems like a natural fit - only update a chunk after a job changes that chunk, but using change filters requires you to go through so much effort to avoid accidentally accessing your data as read-write, I have to imagine there was a better way

rugged grove
#

change filter use sounds like a good idea there. maybe I wouldn't worry too much about messing it up until I know that it hits the performance noticeably. my case is pretty easy. 2d tile map. tile = entity. feels nice so far 🙂

zenith wyvern
#

Should be fine for small maps. You might want to consider an alternative if your maps get very large, or you just end up with a ton of entities that are doing nothing but rendering a tile, which could be done much more efficiently by a combined mesh

rugged grove
#

oh I'm just using the Unity's Tilemap

#

presentation I don't care about that much. just want a fast simulation

#

this is kinda manageable..

zenith wyvern
#

Keep in mind using ComponentData/BufferFromEntity is pretty slow. It's your only option for random access of course but try to minimize it where you can

rugged grove
#

yes, sure. I benchmarked it at one point compared to normal arrays. it's still noticeably faster, I believe, to get componentsFromEntity[entityBuffer[index]] than to access int[index] array

#

taking threads into account or not I don't remember.. definitely is faster threaded

zenith wyvern
#

That doesn't really sound right, you're saying looping over a buffer of entities was faster than a plain array?

rugged grove
#

I think so 1000 or 10000 reads

#

sounds right to me. I might test it again

zenith wyvern
#

I guess I'd have to see the actual test but yeah, if everything else is equal nothing should be faster than a plain for loop over an array, especially in burst

rugged grove
#

the reads from the array probably were random as well

broken cradle
#

can anyone tell me what's wrong here ? I'm having a memory leak error

#

"A Native Collection has not been disposed, resulting in a memory leak."

zenith wyvern
#

If you enable full stack trace in the debugging options it should give you the exact line where the leak is allocated from

#

The only way I can see a leak from just the code you posted is if your job throws an exception

broken cradle
#

yeah it runned fine, then i added burst and it told me i had an error

coarse turtle
#

why do you need to reassign node array with grid? Are you double buffering?

broken cradle
#

no but i need to store the result of my job inside this class to be accessed later by other monobehaviour classes

coarse turtle
#

Well I'm not sure how often this runs, but why not just stick with a persistent native array and pass that one array into the job instead of reassigning the nativearray once the job is complete?

zenith wyvern
#

You would have to track the job handle and force complete it before you pass it in

broken cradle
#

what is though the job made a copy of the array and did not modify it directly, i am wrong ?

zenith wyvern
#

It doesn't make a copy, native containers are pointers

coarse turtle
#

So your struct copy still points to the same memory

broken cradle
#

oh ok nice

#

ok it was juste that i i to Dispose() when OnApplicationQuit happens

broken cradle
#

gained 40% optimization with burst, better but still a little disappointed for the effort required

#

also strange thing, burst seems to still work with vector2int, even tho i saw it worked only with specific types not including it in the documentation

zenith wyvern
#

Burst can (potentially) optimize better with the types from the new math library

#

Based on the code you posted it seems like you're introducing unnecessary bottlenecks. For example, you shouldn't be calling complete on a job immediately after you schedule it, you're just blocking the main thread that way.

broken cradle
#

indeed however this is a pathfinding algorithm for a rts, i can't wait for things to happen it has to respond instantly to the player input

#

i'll work on my types to try to optimize it further though

zenith wyvern
#

Depending on what you're doing you might be able to let the job run for part of the frame at least

broken cradle
#

i think i'll have to find out some way to tell the units a direction to take before having the response of the pathfinder to fake the smoothness of the response

zenith wyvern
#

If you're just calling complete immediately you might as well just use .Run instead, that will be faster (unless it's a parallel job). Also make sure you're adding the [BurstCompile] attribute to your jobs. A lot of people seem to miss that

#

And y'know, make sure burst is actually enabled in the editor. Another easy one to miss

broken cradle
#

yup i added burst compile

#

without burst the whole job thing actually made me lose exec time 👀

zenith wyvern
#

Scheduling can be expensive

#

Relatively speaking

broken cradle
#

i still have a few things to optimize, thanks for the help though

broken cradle
#

is there a way to use some sort of list in a job using burst ? NativeList does not seem to work either since for some reason they are ReadOnly and i can't use the Add() operation

broken cradle
#

this is made to allow sorting inside a native container, but i don't need that i need some container which allows addition. I could use a very huge array but it would be too big

coarse turtle
#

So you don't need sort?

is there a way to use some sort of list in a job using burst ?

#

Ah nevermind i misunderstood that question

broken cradle
#

no i mean some kind of list

coarse turtle
#

Yeah NativeList<T>/UnsafeList<T>

#

dunno how your jobs are structured, but if a NativeList ends up being readonly, why do you need write access

broken cradle
#

Native list throw this when i use Add() :
InvalidOperationException: The UNKNOWN_OBJECT_TYPE has been declared as [ReadOnly] in the job, but you are writing to it.

coarse turtle
#

Yea you'll need to show the job because idk how you're structuring it

broken cradle
coarse turtle
#

Can you show the full struct?

broken cradle
coarse turtle
#

you never allocated toVisit

#

NativeList<DijkstraTile> toVisit = new NativeList<DijkstraTile>();

#

There's no allocation supplied here

broken cradle
#

oh indeed

coarse turtle
#

Which makes the internal pointer invalid

broken cradle
#

ok it works now thanks

#

that's very strange that declaring with no allocator works tho

coarse turtle
#

structs always have default constructors

#

you just can't override them in C#

broken cradle
#

now that you mention it yes i did not think of it

acoustic spire
#

are Entity structs actually stored in memory or are they just a representation of indices?

zenith wyvern
#

Entities are just an id and a version. Components are what actually exist in contiguous chunks of memory

acoustic spire
#

so, for example if I create an entity with a single byte component I'll have to have (1 byte + 2 int)*Count memory space, correct?

broken cradle
#

@hard wagon hey so does it work with convert and destroy for you ? It does for me on unity 2020.3.16f1 with the hybrid renderer v2

hard wagon
#

I even make sure that Hybrid rendering v2 was working (Console logs)

broken cradle
#

it's normal to be removed since it's no more a gameobject but an entity, however you should still see it when you launch the scene

frosty siren
hard wagon
zenith wyvern
broken cradle
#

ok maybe it's a thing with HDRP who knows

#

i'm on URP

hard wagon
#

Hmmm need to try URP then... will try this later after work.

cerulean pulsar
#

Hi, given math determinism and a lack of player input, what could cause a NetCode misprediction?

digital kestrel
#

how do i get a child entity given its parent entity

#

when i spawn my prefab, it doesnt update its references to its child prefabs :/

safe lintel
#

are the child entities rigidbodies?

digital kestrel
#

no

#

they're transforms

#

im using [GenerateAuthoringComponent]

#

not IConvertGameObjectToEntity

#

for the prefab which I instantiate with command buffer

digital kestrel
#

ok nvm, it does spawn correctlyh

#

the problem is that Translation Component does not match its LocalToWorld Component

#

because it's linked to another entity

whole gyro
digital kestrel
wraith urchin
#

Hi ! anyones know what is the best way to start learning netcode for dots ?

karmic basin
#

Hello ! Yep, follow & dig through these samples

#

ALready having network games knowledge will help a lot

#

vis2k (from the Mirror team) also works on a netcode asset (a paid one), looking very promising ! Called DOTSNET if you don't want to figure things out

#

aaaand honestly I don't know other useful resources as a first start. Maybe people have started blogging about it ... ?

kindred star
#

issue of RaycastCommand

#

maxHits > 1 not works

#

only returns 1 hit

sour atlas
#

Uh so if i have a SharedComponentData component that holds a float value and i add that to two entities is there a chance they are assigned to different chunks due to float inaccuracy ?

#

more specifically i have this

            QuadVertices vertices = new QuadVertices
            {
                V0 = new float3(localOrigin.x - extends.x, 0.0f, localOrigin.y - extends.y),
                V1 = new float3(localOrigin.x + extends.z, 0.0f, localOrigin.y - extends.y),
                V2 = new float3(localOrigin.x - extends.x, 0.0f, localOrigin.y + extends.w),
                V3 = new float3(localOrigin.x + extends.z, 0.0f, localOrigin.y + extends.w)
            };
            dstManager.AddSharedComponentData(entity, new RenderVertexData()
            {
                Vertices = vertices
            });
#

actually i just realised that since im using shared component data components i can just use a mesh lol

safe lintel
#

@kindred star seems to be an undocmented limit of that particular api

cerulean pulsar
#

Hey guys, I'm getting prediction error when moving a player character toward a waypoint, even without player input. In this GIF you'll see the player character (red) move toward a waypoint (orange). When it reaches the waypoint it should stop, but instead it gets snapped back to the server's position (white) and reaches the waypoint a second time. Does anyone have any thoughts or ideas about how to prevent that snapback? Minimal repo posted here: https://forum.unity.com/threads/prediction-error-even-without-player-input-minimal-example.1162142/

north bay
#

@cerulean pulsar added and removed components are not rolled back
You will end up removing your component in the first prediction tick that reaches the waypoint and therefor invalidate all further prediction ticks

coarse turtle
#

Hmm does EntityManager.MoveEntitiesFromWorld work decently with SharedComponentDatas that do not contain blittable data?

cerulean pulsar
# north bay <@768561883774320690> added and removed components are not rolled back You will...

Hi @north bay! Thanks! I removed the RemoveComponent block and it stopped the invalidation. However, when I tested this no-structural-changes version with two waypoints, I get invalidation again. As you can see in this new GIF, when the red object reaches the orange waypoint, it starts to head toward the yellow waypoint from the server's position, instead of from the orange waypoint. It snaps to the server's position on its way

molten flame
#

Looking for general advice, has anyone had any luck creating save games with Netcode?
How did you do it? Serialize an entire world or component wise? How did you go about loading it back up with ICustomBootstrap?

cerulean pulsar
ocean eagle
#

Any references / links with getting started with .17 DOTS? Super new to this concept

safe lintel
#

@ocean eaglesee the pinned post but ignore the wiki. honestly the wiki should be removed

ocean eagle
#

Appreciate it. I’ll check it out

low oyster
#

Hello! Is someone already dive into NetCode and Subscene a bit more than the samples provided?

ocean eagle
low oyster
toxic crest
#

Hey all. I'm just curious if anyone here is using the 2021 editor for working with DOTS? I'm just about to get started with DOTS and wondering if there's anything extra in 2021 to help with DOTS work

sour atlas
#

I did use 2021 for DOTS but it was very unstable. 2020 LTS is recommended.

toxic crest
#

appreciate the feedback. Probably best to stick with LTS for now anyway

#

I seen some mention that the 2021.2 beta has a decent performance increase for burst via internals but other than that, 2021 didn't seem to offer any major benefits that I could find

sour atlas
#

Well i just had some really strange issues regarding sub scenes that made it impossible to use 2021, it might be fine it might not be 🤷‍♂️

low oyster
#

Most of DOTS packages are not "compatible" with 2021 atm stick with 2020 LTS

glad kernel
#

This is more related to jobs and burst compiler, but here it goes:

I want to run an expensive algorithm during runtime. To avoid blocking the main thread, I would assume that launching it in a new job would be a good ideia. However, after scheduling a job with that expensive task, the main thread blocks.

I'm afraid that I might have not understand how the jobsystem works or that the main thread is blocking because it is allocating too much memory (narrative arrays for instance).

If someone could guide me in the direction to troubleshoot the problem, I'd be grateful! 🙂

cerulean pulsar
glad kernel
#

I'm gonna try that.
Still, does it make sense to consider allocating memory inside the actual Job, rather than from the main thread?

cerulean pulsar
glad kernel
#

Ok, so if it is for job data, it can be allocated and dispose inside the job. Glad to know that.

#

And, is it possible to access (read only) the data from the main thread while the job is still running?

cerulean pulsar
sour atlas
#

I am pretty sure it isnt and even if it is that sounds like a pain to work with.

cerulean pulsar
glad kernel
glad kernel
glad kernel
#

Now, I just need to find a way to access from the main thread the data on the job while it is running.

#

Is there a way to change the ownership of the data, or briefly stop the job execution?

cerulean pulsar
# glad kernel Now, I just need to find a way to access from the main thread the data on the jo...

I wonder if you could have an additional native array, of length one, that holds an index that signals which portion of the target native array is ready to be read from. When you want to read from the continuously updating target native array, you could first check the index to see what's safe to read. So the job would write to the target array normally but also write to the index to continuously signal what's safe to read. I've never tried reading data this way but I don't see why the main thread can't just look in memory. Might need to disable some job system safety features for this system but it could work

#
  • Main thread: Allocate data array and singleton index array. Pass to job and schedule job
  • Job: Update data and then update singleton index array. Repeat for each iteration of algorithm
  • Main thread, while job is running: Read from singleton index array to know which portion of the data array is safe to read from. Read from safe portion of data array
#

i.e. share the data array and also share an imaginary line that marks which portion is ready to be read from and which is not ready to be read from

sour atlas
#

okay so uh i have a problem with shared components

#
Debug.Log("Convert");
            dstManager.AddSharedComponentData(entity, new RenderVertexData
            {
                V0 = new int3(localBounds.x,   0, localBounds.y),
                V1 = new int3(localBounds.z, 0, localBounds.y),
                V2 = new int3(localBounds.x,   0, localBounds.w),
                V3 = new int3(localBounds.z, 0, localBounds.w)
            }); 
#

i'm adding this in a Gameobjectconversionsystem

#
Vertices.Clear();
            EntityManager.GetAllUniqueSharedComponentData(Vertices);
            foreach (var vertexData in Vertices)
            {
                Debug.Log(vertexData.V0);
                Debug.Log(vertexData.V1);
                Debug.Log(vertexData.V2);
                Debug.Log(vertexData.V3);
            }
#

use this for debugging

#

i only have one entity that holds this component

#

however in the console theres 8 print messages, first 4 being 0,0,0 for all 4 verts while the other 4 are the correct values

#

whys that ?

#

Im a little lost on this one.

zenith wyvern
sour atlas
#

Oh alright. That seems about right thank you 😄

#

I was going to do that but if its by design then even more of a reason.

cerulean pulsar
#

It seems that PhysicsShapeAuthoring.ForceUnique doesn't work when instantiating prefab entities. Does anyone know another way to get two equivalent PhysicsColliders to be independently changeable?

hollow sorrel
cerulean pulsar
safe lintel
#

maybe its a bug and needs to be reported?

#

the havok guys are pretty good at responding to issues

hollow sorrel
#

@cerulean pulsar seems it uses the GetInstanceId() to determine physicsshape hash which is unique for spawned gameobjects, but I guess on a prefab would be always the same?

cerulean pulsar
#

@safe lintel @hollow sorrel Thanks for the replies. I think it's working as intended, because it says "ForceUnique: If set to true, then this object will always produce a unique collider for run-time during [GameObject-to-Entity] conversion." It does not say "during entity instantiation" post-conversion.

(edited out mystery thing, need more thoughts on it; don't want to mislead)

Looking for a way to clone a PhysicsCollider.value given a reference to it to make it independent, without knowing its details (without knowing its capsule height for example)

robust scaffold
#

Something too good to be true, might be a scam. That is the most suspicious website I have ever seen.

#

Holy shit, wow that is a very expertly crafted scam site let me tell you.

#

Almost fell for it but the hyperlinks werent lining up.

#

<@&502884371011731486> Can you please ban whoever posted that link I replied to earlier. Was advertising a scam site.

solar spire
#

Hard to tell who you've replied to, but we did just ban a user

robust scaffold
#

Ah thank you. Just watch out for it. Dont know how it operates on the discord site but regex check for Discord-airdrop.com links.

solar spire
#

Any nitro gift is a scam, it's extremely common

#

There's hundreds of websites with different url s that get created constantly

robust scaffold
#

Heh, I'm not very street savvy on discord things. Luckily I wasnt stupid.

#

Yea, the website popped up literally an hour ago.

remote crater
#

Game is Starfighter General on Steam, going Action MMORPG very soon.

You can also come to like the only positive zone of the Internet I know: www.twitch.tv/VGMCrazyJim The Bro Zone Layer. (temp)

The #1 video gamer who ever lived with proof! I just missed tourneys due to life problems(college for Starcraft thinking my email invite to Korea was ...

▶ Play video
#

Game is Starfighter General on Steam, going Action MMORPG very soon.

You can also come to like the only positive zone of the Internet I know: www.twitch.tv/VGMCrazyJim The Bro Zone Layer. (temp)

The #1 video gamer who ever lived with proof! I just missed tourneys due to life problems(college for Starcraft thinking my email invite to Korea was ...

▶ Play video
#

Some experiments with me automatically allocating and converting to Entity via Resources in a class ready to object pool.

#

I'm not sure why everyone discourages the use of the Resources folder, it freaking rules, like old school coding where you can get massive amounts of efficiency for being an intermediate coder or above. All this scene specific garbage takes far too much time for advanced software architects.

remote crater
#

I only have one DOTS/ECS Question: What is the best way in a systemBase, to find and identify one specific entity? I want to a class variable 'Entity playerEntity' which I know how to do.

zenith wyvern
#

GetSingletonEntity<Player> where player is a component you tagged the player entity with when you created it

remote crater
#

Much obliged Sark

#

I think I asked this question 3-4 times. Now I'm good to go!

remote crater
#

Wait one more! If I have thousands of component tags, does it performance hit the system if under Standard Assets, or is it better to have one component tag and in that an index. Then cycle through all entities with this component tag until it is the right index? I'm thinking the later is better, but I don't know how Unity works.

remote crater
#

I'll go with the later because I can deal with it in my code. The previous is Unity specific and most general systems aren't set up for efficiency there.

mint iron
#

There are some advantages to using components as tags, mostly that you can easily filter with them using queries. But every extra component you have on an archetype will tend to slow access since most calls have to search through the components by type, since they can't really assume they wont move/change at any point.

sour atlas
#

Uh is it correct that its impossible to add a callback to the camera functions through systems ?

#
        protected override void OnCreate()
        {
            Camera.onPreCull += DoInstancedRender;
        }
        public void DoInstancedRender(Camera camera)
        {
            Debug.Log("I got called");
        }
#

never getting that debug log

#

also is there a way to take an EntityComponentData array and turn it into an array with just the values of that component data

#

e.g if i have something like ```cs

public struct FooData : IComponentData { int bar = 0; }

and then query for that 
```cs

var query = EntityManager.CreateEntityQuery(typeof(FooData));

I want an array with just [0,0,...,0]

sour atlas
toxic crest
#

I seen it mentioned that you need build config files for each target platform when creating a DOTS project but I don't see any references to how I set that up. Can someone shed some light on that?

#

the dots getting started docs say nothing about creating it either. 😕

zenith wyvern
hot basin
toxic crest
zenith wyvern
#

Just remember components are value types, you can't write back to them and expect it to change the components on the entity. But you can use query.CopyFromComponentDataArray to push back to the original entities.

sour atlas
#

I only need to read so thats fine.

sour atlas
pliant pike
#

I don't suppose anyone knows the correct way to access a Blobasset inside a struct inside another method is?

#

I get the error specified cast is not valid in unity

coarse turtle
sour atlas
#

urp

coarse turtle
sour atlas
#

ah that would make sense. i had suspected it didnt work because i was using hybrid v2 but removing that didnt fix it

#

ill test if what you suggests works later, thanks

remote crater
#

query = GetEntityQuery(ComponentType.ReadOnly<AssignData>());

    NativeArray<Entity> ne = query.ToEntityArray(Allocator.TempJob); 
    
    Entity playerEntity = ne[0]; 

    ne.Dispose();
#

How do I read any data what so ever off playerEntity such as AssignData.identifier (a long)?

#

I see there is no systembase GetComponent... So how do I read any data off a specific entity?

#

In a systembase.

sour atlas
#
NativeArray<T> = query.ToComponentDataArray<T>(alloc)
#

ah

#

that should work

remote crater
#

I already have that

#

It works

#

I have an entity

#

How do I read data in an entity?

#

I want to have my drones face my player

#

But I can't figure out which entity is my player until I can read variables from player to id it.

#

It has an assigndata component with a long named identifier

#

Player is 1, others are other data

sour atlas
#

if you have the entity index you can use GetComponentDataFromEntity<>()

remote crater
#

Thank you.

sour atlas
#

thought that might be slow since its random access

remote crater
#

Is theer a way to store info in a systembase?

#

I tried doing a global class variable and it wasn't happy

#

I want to find the playerentity once and store it

#

Its okay if it is micro slow for one frame when loading

sour atlas
#

i am pretty sure you can just do something like

public class System : Systembase
{
  private Entity _player;
  protected override void OnCreate {
    _player = <whatever you need to do to find it>
  }
}
remote crater
#

Cool

#

Thats super awesome

#

playerEntity.GetComponentDataFromEntity<AssignData>(); says Entity doesn't have that GetComponentDataFromEntity on Entity

sour atlas
#

though i think you might just want to attach a tag such as player tag when you first loop over all entities to find the player

#

that way you can easily filter for the player every time

sour atlas
#
ComponentDataFromEntity<Component> foo =
                GetComponentDataFromEntity<Component>();
remote crater
#

ty

#

This is extremely helpful

#

I might have a 50,000 drones shooting lasers at me by tonight

sour atlas
#

there might be a better way of getting the component data for a single entity but i am not sure.

remote crater
#

Then tomorrow slap in the networking

#

DOTS ECS = thankful anything works

zenith wyvern
#

GetSingleton<DataType>

remote crater
#

then later efficify it 🙂

sour atlas
#

heh i got my co worker to work on networking so i can save myself the pain from that

remote crater
#

My networking is unbelievable...

#

Literally no one thinks it is possible

#

But I had it working in 2004 in a dif game

#

Won't let me paste a single line of code, sec, going to pastebin

remote crater
sour atlas
#

its not

#

you are calling playerEntity.GetComponentdata

#

you need to remove the playerEntity.

remote crater
#

How does it know what entity to get it from then?

sour atlas
#

also im pretty sure the GetSingleton is a better approach :)

#

this is why its slow

#

it get ALL the components from ALL entities with that data

remote crater
#

Ty

sour atlas
#

and you use the entity as a lookup for the data to get

remote crater
#

Ok so then i toss the query I had before

#

where I looked up all entities with that component.

#

got it, I'll google this GetSingleton thing

#

It is weird right..? That if I have an Entity, I can't actually read any data on it in a SystemBase?

#

You'd think you could do Entity player; player = SomeEntity; Then use player.GetComponent<x>.variable

#

Maybe it has to do with multithread safe...

zenith wyvern
#

You're thinking in an OOP way. An entity is just an id, it has no actual data attached to it. The ECS is basically a database that associates the data to the entity. Queries allow you to get the data from the entity id.

#

Any time you need to access entity data you use a query.

#

Even convenience functions like systemBase.GetSingletonEntity or systemBase.GetSingelton work using queries under the hood.

remote crater
#

So it is due to multithread safe. I have a query, but I don't know how tor ead the data.

#

sec, I will paste code

#

I do a query, I get an array of entities. I don't know how to read any data except references to entities.

#

I assure you I will not ask many questions after this. I should be good to go.

#

I'm able to move stuff around in ECS, rotation/velocity/position/etc it is very cool, but to access variables on a component on any entity, that is a mystery.

zenith wyvern
#

var componentArray = query.ToComponentDataArray<AssignData>(Allocator.TempJob);

remote crater
#

Then that componentArray will be the data of the entity array? So entity[0] will have its data found in componentArray[0]

#

Is that correct?

zenith wyvern
#

Yes, if you got the entity array as well the component and entity indices will match up

remote crater
#

Sweet!

zenith wyvern
#

Assuming you're getting them both from the same query

remote crater
#

Alright Tronman and Julien, you helped me muchly. I'll see if I get this working then take a break.

#

Remember, if I become made in the shade with my mmo, and you find me, I'll buy you lunch and or give you manila envelope of green stuff.

#

God bless all younz.

toxic crest
#

<-Witness

#

:p

remote crater
#

Worked bros!

#

I can't wait to try and fight against 5,000-100,000 drones tonight

#

Boids had .5 million working on the last demo. But with lasers and some thinking, maybe 100k is my target

sour atlas
#

youre streaming your development right ? dm me a link and ill tune in every now and then

#

@remote crater

remote crater
#

Its not dev at the moment

#

thatw as stressful so I am doing a lol game first

#

I am still threading some networking in, so I won't be streaming it every time I dev for the next 3 days or so

#

But I want to have a MOBA out in 2-5 days, then a MMO in 2 weeks or so after

light mason
#

Why was the notice on dots compatibility locked ?!?!

#

What is the plan ?

zenith wyvern
#

They said at the start there would be no news until the end of the year

#

No reason for people to keep getting all stirred up in the thread I guess

remote crater
#

This is a super super pro tip: If you have a game that works and you want to add a zone using ECS/DOTS, the proper Design Pattern is keep your gameObject player controller to control your entity, and just have the Entity that represents your player in the ECS/DOTS zones to simply mirror your player gameObject and turn the player gameObject rend off. This works super super super well, and keeps your code aligned with the philosophy of write one method not many methods.

#

I actually have sample code that makes this transition very simple at:

#

I wrote that for a dude who showed up on my stream personally over a few hours. It is amazing.

remote crater
#

Is it possible to call a function(aka Method) in a Lambda expression Entities.ForEach

pliant pike
#

No, jobs are like black boxes, data can only go in and out of them in specific constrained ways,(if you want to use them properly)

#

You can use a struct and create and pass that in like a method though

coarse turtle
#

or burst function pointers

hot basin
#

any ideas how to approach behaviour trees in DOTS?

safe lintel
#

pretty sure I saw a github project for that very thing

hot basin
#

I saw one but was not burst compatible

safe lintel
hot basin
#

yeah, thats the one

karmic basin
#

Check forums

#

Maybe

#

Probably :)

safe lintel
#

maybe you can get some inspiration, alternatively dataflowgraph might be of some use

remote crater
#

Calabi I called my method static and it ran inside

safe lintel
#

DataFlowGraph is burst compatible and seemingly could do stuff a behaviour tree can. theres support for attaching a graph directly to an entity and reading/writing component data inside the graph, but its a bit tricky and super verbose. hard to keep track of everything with there being no ui when connecting nodes up to each other.

robust scaffold
#

On the dots networking forums, someone new was hired to write documentation for DOTS. I'm getting a feeling an update is gonna be coming in 2 or 3 months.

#

2 or 3 months might be a bit optimistic for me though.

remote crater
#

They should hire 10 people.

#

Every raw code listing that makes no sense should have as many use case samples as possible.

#

Updated as stuff goes out of date. (easy to do if documentation foundation architecture links the terms to active terms in game)

sour atlas
#

the main issue is -- at least what i gathered from talking to some unity devs is that noone wants to take the time to write documentation when its going to be obsolete in a few months

remote crater
#

yup, this is why you hire interns for nearly free

#

documentation isn't something any coder wants to write

#

but interns are a dime a dozen and they don't need to know how to code entirely cromulent, just have smelled a compiler once.

sour atlas
#

Id crowdsource it 🤷‍♂️

remote crater
#

Unitardpedia

#

I love dots, don't think its slander. I love this tech.

sour atlas
#

the tech is fun, actually using it is hell

remote crater
#

The two major things in my book they could do to boost their stock through the sky is the documentation, free base projects in unity store and my long term idea for a Value Added Unity Store where you can upload stuff using Asset Store assets and people who buy em need to buy em too.

#

Hell is other people engineering APIs.

#

Using someone else's API is like how coding is to telling time. You might have trained on a clock since 5 yrs old, be a master of digital, analog and clock hands. But you buy an Electronic Honda and the clock is off by an hour. How do you set it? Buttons for it? Dial the radio preset? Knobs? Turn signals? Windshield wipers? Plug a diagnostic tool in? Plug in your phone? No one reads the mind of engineers, but low an behold you told everyone you can read time so why can't you do this?

#

I know what is gonna happen... I'll have a working game, a game that kicks ass, and they'll depreciate a very core feature, so I'll be stuck on Old Unity for years, until it won't even work... Happens all the time.

sour atlas
#

oh yeah theres a few major changes planned afaik

#

i dont know what exactly and if i did know i wouldnt be able to tell you but its definitely going to happen 😛

remote crater
#

You could tell me

#

you'd just have to kill me

#

which is preferable than the current documentation

safe lintel
#

@robust scaffold they hired brian will afaik to do dots docs too, but that was ages ago. wouldnt get my hopes up for anything less than 6 months tbh.

karmic basin
#

Well I'm sure something will happen by the end of the year

#

I mean, that's what they say themselves actually

safe lintel
#

@sour atlas hell I'd totally write docs for them, not joking at all. at the pace of things I truly doubt it would be obsolete any time soon

sour atlas
#

🤷‍♂️ i get why they dont want crowdsourced docs but with how DOTS is currently going that would be the best option

#

also

             _vertices.Clear();
            //NOTE: First index is always populated with default struct values
            EntityManager.GetAllUniqueSharedComponentData(_vertices);
            _vertexBatchQuery = EntityManager.CreateEntityQuery(typeof(RenderVertexData),                                                              typeof(RenderTranslationData));
            foreach (RenderVertexData batch in _vertices)
            {
                _vertexBatchQuery.ResetFilter();
                _vertexBatchQuery.SetSharedComponentFilter(batch);
                

is this the "proper" way of doing an operation for all unique shared components ?

safe lintel
#

yeah looks correct. i dont understand why the first result is default values(annoying when I didnt know that at first)

#

id do the query not in the main loop though, start/awake or oncreate

sour atlas
#

took me hours to figure out and i wouldnt even have figured it out if i havent been told.

#

yeah im just going to update the query when a new static renderer is introduced

#

for now its in update 🤷‍♂️

safe lintel
#

@karmic basin I wish I could share that optimism 🥲

sour atlas
#

//TODO: implement on demand query updates
here wrote a todo 😛

#

also

#

int batchSize = _vertexBatchQuery.CalculateEntityCount();

#

this calls something called syncfiltertypes

#

which relies on a few dependencies

#

does anyone know if calculate entity count is faster than just populating a native array of entities and getting the length of that ?

sour atlas
#

my EditorLoop is taking up about 95% of the frame time, does anyone have a similiar issue with DOTS ?

fossil obsidian
#

To use DOTS I can't use 2021.1 right?

safe lintel
#

yep @fossil obsidian

timber ginkgo
#

Anyone have advice for using persistent native lists? I'm specifically wondering what is the most performant way to dynamically resize them. Do they just automatically resize when I add or remove elements?

If I need to add a butt load of new elements on a given tick, should I always be using the AddRange function? Or is it somehow better to use Resize and then AddNoResize/AddRangeNoResize?

coarse turtle
toxic crest
#

resizes copy as well. best to pre-allocate

timber ginkgo
toxic crest
#

if you know it'll always be within a certain size (and the upper bound isn't ridiculously larger than the normal)

timber ginkgo
#

it's going to be lists of ints up to around 1k in size, so having it preallocated isn't necessarily the end of the world

#

and it would save copying costs if they're large

#

the actual counts might be somewhat dynamic though

toxic crest
#

well, I'm still new to DOTS but my question I'd ask in that case is, is it frequent and is it going to be on the main thread

coarse turtle
#

you can always write a job to resize if in the event the upper limit is too small

#

as long as you avoid doing list.Add(...) and surpass your current capacity

toxic crest
#

^

timber ginkgo
#

@toxic crest it's going to be both on and off of main threads; it's sort of a custom ECS system for rigidbody related stuff, constant lookups and iterations every fixed update

coarse turtle
#

because that will allocate a new list with Capacity + 1

timber ginkgo
#

yea that's exactly the sort of thing i was worried about

#

that's great info!

#

i should note im not using dots physics

#

just jobs and native collections

toxic crest
#

if their native array/list behavior is the same as standard .net, it would allocate the pre-existing size + an amount of new elements as a percentage of the existing size

#

so it can be even worse if thats how they do it too

#

I haven't peaked under the hood of unity collections though

timber ginkgo
#

generous preallocation of some kind seems like the best bet

toxic crest
#

man, I'm really on the fence about getting that Orbis DOTS terrain from the store. It looks pretty sweet and would save me a buttload of time doing that on my own

timber ginkgo
#

i was considering that too actually

toxic crest
#

anyone here play with that yet? I'm curious if it can do holes in the terrain out-of-the-box

timber ginkgo
#

my project is using spherical planets and gravity

toxic crest
#

nice.

timber ginkgo
#

hollow planets too lol

#

i have looked at different ways of making procedural planets with internal structure, but to be honest some kind of voxel based system seems the best

#

a 3d quad-tree optimized grid of some kind

#

AFAIR Orbis uses quadtree 2d grids mapped to a sphere

toxic crest
#

It says orbis uses quad trees for dynamic LODs and for skirts blending between LODs

#

heh, yea

timber ginkgo
#

the dynamic surface geometry with the quadtree optimization is def powerful

#

im more focused on editability and internal structure though

molten flame
#

Does anyone know how I can get some IComponentData using only Entity and an instance of System.Type, dunno if I'm blind but there is HasComponent(Entity, ComponentType) but no variant for GetComponent?

#

For context, I have a Type[] and want to get all the components of those types.

molten flame
coarse turtle
#

But you can use that to get the component data via EntityManager.GetComponent(entity, ComponentType)

molten flame
coarse turtle
#

Yea you're right

molten flame
#

I'm probably going about this the wrong way anyway.

                foreach (Type type in componentsToSave)
                    if (EntityManager.HasComponent(entity, type))
                    {
                        // Get component?
                    }

Its for a serialization system

coarse turtle
#

well the closest would be to use the internal API if anything cause you can use EntityManager.GetCompnentDataRO/RW(Entity, int)

#

since you have the type...you can get the type index via TypeManager

molten flame
#

Oh cool, I didn't know about TypeManager, thanks 🙂

toxic crest
#

what about public T GetComponentData<T>(Entity entity) in EntityManager?

#
Gets the value of a component for an entity.```
#

@molten flame

molten flame
#

@toxic crest It's not that trivial unfortunately. Cant get a static T from Type[].

foreach (Type type in types)
    GetComponentData<type>(Entity) // ???
toxic crest
#

it has to be static?

#

if you just need a valid instance, you could use Activator class to create one but it'll nuke your performance lol

#

I don't think there's a prettier way without reflection

molten flame
#

I think you are misunderstanding, it isn't static.

#

I have Type[], not T.

toxic crest
#

Sorry, I thought thats what you meant from "Cant get a static T"

#

yeah I know.

molten flame
#

No worries, I appreciate the interest 🙂

toxic crest
#

I'm sure I'll be encountering all this stuff soon enough as well lol

molten flame
#

I suspect I'm doing it wrong if I'm asking these odd questions

toxic crest
#

Literally just started into DOTs

molten flame
#

What are ya planning make?

toxic crest
#

builder/crafting sandbox.

molten flame
#

nice, I'd love to see more takes on the building/crafting genre, I think there is so much unexplored potential there

rugged grove
#

hello. is there a simple way to get a class IComponentData. I have a singleton component class. Get singleton doesnt work for those so I tried GetComponent<InputActionsReference>(GetSingletonEntity<InputActionsSingleton>()); (where InputActionsReference is a class and InputActionsSingleton is a struct)
And it's the same. Wasn't there sth like GetManagedComponent?

#

wow, this discord is not very active XD

#

ok.. EntityManager.GetComponentData worked. feels like overlooked (missing) API feature

pliant pike
sour atlas
#

Dont want to make a build every time i want to test 😛

zenith wyvern
sour atlas
#

I doubt that thats the issue, im getting awfully low framerates without the profiler too

#

at least awfully low for what they should be.

rugged grove
sour atlas
#

Yeah I saw some people having that issue too, thats why i set the editor repaint rate to be limited to my monitors refresh rate and that didnt fix anything

#

but profiling the editor sounds good. i have a hunch what might be causing it but it really shouldnt be happening

sour atlas
#

I have no Idea how the editor actually works though.

hot basin
sour atlas
hot basin
#

I don't have proof but I think there is a memory leak in the editor so after a some time performance decreases. Restart seems to fix the issue.

sour atlas
#

oh no it did not

rugged grove
sour atlas
signal flicker
#

hi, so im experimenting with the jobs system because i am looking into multithreaded procedural generation

#

i have a test script set up to do a LOT of trig functions using the jobs system

#
public class jobsTest : MonoBehaviour
{
    JobHandle handle;
    randomByte byteJob;
    bool completed = false;
    public uint count = 10000;
    byte[] bytes;
    NativeArray<byte> j_bytes;

    bool started;
    private void Update()
    {
        if (completed || !started)
        {
            return;
        }
        if (handle.IsCompleted)
        {
            Debug.Log("completed");
            completed = true;
        }
        else
        {
            Debug.Log("not completed");
        }
    }
    public void click()
    {
        started = true;

        bytes = new byte[count];
        j_bytes = new NativeArray<byte>(bytes, Allocator.Persistent);
        byteJob = new randomByte()
        {
            _bytes = j_bytes
        };
        handle = byteJob.Schedule(bytes.Length, 64);
    }
    static uint t = 0;
    struct randomByte : IJobParallelFor
    {
        public NativeArray<byte> _bytes;
        public void Execute(int index)
        {
            _bytes[index] = (byte)Mathf.Sin(t);
            t++;
        }
    }
}
#

the only issue is, while the job is active, my fps drops by like half

#

my understanding is that it shouldnt make a difference, is there something im doing wrong?

rugged grove
sour atlas
#

👍

#

thanks

#

gonna check it out tomorrow

signal flicker
#

im working on terrain generation, and when i use jobs for the foliage (which is completely unrelated from the mesh generation, except it uses the same height function), i get these large mess ups in the terrain generation

#

right now im using noise from the unity.matematics namespace, and these abnormalities happen way less often then when i used mathf.perlin noise

#

does anyone know what might be happening?

signal flicker
#

its probably also worth mentioning that not all my grass gets spawned.

#
struct foliageJob : IJobParallelFor
    {
        public NativeArray<float4x4> matricies;
        public float4 boundsMinMax;
        public uint foliageLength;
        public NativeArray<ushort> length;
        public void Execute(int index)
        {
            float3 position;
            quaternion rotation;
            float3 scale;
            position.x = random.NextFloat(boundsMinMax[0], boundsMinMax[1]);
            position.z = random.NextFloat(boundsMinMax[2], boundsMinMax[3]);
            position.y = getHeight(position.x, position.z);
            //position.y = 0;
            rotation = Quaternion.AngleAxis(random.NextFloat(0, 360), Vector3.up);
            scale = Vector3.one * random.NextFloat(.6f, 1);

            //matricies[a] = float4x4.TRS(position, rotation, scale);
            matricies[index] = float4x4.TRS(position, rotation, scale);
        }
    }
zenith wyvern
#

I forget what it's called and I'm not at home but there's a drop-down, you can see it in the screenshot above where it says "Hierarchy". You want the one that shows the time each job takes, I think it's called timeline.

signal flicker
#

well, my job shouldnt affect frame times since i am allowing it as many frames as it needs to finish

#

each frame i check if my grass matrices are done computing

#
void startFoliageJob(chunk _chunk)
    {
        ushort[] lengths = new ushort[foliagePrefabLength];
        for (ushort i = 0; i < foliagePrefabLength; i++)
        {
            lengths[i] = (ushort)(spawnAmountPerGrid / foliagePrefabLength);
        }
        Debug.Log(spawnAmountPerGrid);
        foliageJob job = new foliageJob()
        {
            matricies = new NativeArray<float4x4>(spawnAmountPerGrid, Allocator.Persistent, NativeArrayOptions.UninitializedMemory),
            boundsMinMax = new float4(_chunk.bounds.min.x, _chunk.bounds.max.x, _chunk.bounds.min.z, _chunk.bounds.max.z),
            foliageLength = foliagePrefabLength,
            length = new NativeArray<ushort>(lengths, Allocator.Persistent)
        };
        foliageJobHandler handler = new foliageJobHandler(_chunk, job);
        handler.handle = handler.job.Schedule(spawnAmountPerGrid, 64);
        _foliageJobs.Add(handler);
    }
#

this is where i start my job

#

i think its a memory allocation issue

#

and sometimes this happens

#

and sometimes the grass just floats way above where it should

#

i should also mention that when i disable "use jobs threads" it works fine

#

so i dont think my code is the issue

languid axle
#

i've downloaded all packages neccesary for DOTS but i cant add using Unity.Entities
(this is brackeys from 2018)

signal flicker
signal flicker
#

yea ig u already have it

#

ig try to restart ur editor

languid axle
#

solved it had to regenerate the project files

zenith wyvern
#

I will say it seems weird to allocate persistent arrays every time you run a job, shouldn't you be re-using them?

signal flicker
#

also i only run the job once per chunk, so there isnt really a good reason to re use them

zenith wyvern
#

If you have native containers that are used often in jobs it can help to allocate them outside the job and clear and re-use them. You can even make a pool of containers if you have a lot of jobs. Saves you from having to allocate new ones

#

But yeah, I'd strongly suggest you take some time to get familiar with the profiler. Forget about jobs and just do it with a simple non-dots project if you think that will make it easier

signal flicker
#

i know how to use the profiler

zenith wyvern
#

It's really the only way to track down performance issues

signal flicker
#

its not a performance issue

#

its an allocation issue

solar spire
#

Are you disposing your arrays?

signal flicker
#

yes

zenith wyvern
#

Okay, can you show the profiler data showing your allocation issue?

signal flicker
#

hold on, ill send more of the script

zenith wyvern
#

If it is from allocations the profiler will show it.

signal flicker
#

i thought the profiler only showed the main thread

solar spire
#

Like, your jobsTest class you posted earlier, where does it dispose of the array?

zenith wyvern
#

In the timeline view you can scroll down and there's a dropdown for jobs

signal flicker
#
void checkFoliageJobs()
    {
        chunk chunkInQuestion;
        for (ushort f = 0; f < _foliageJobs.Count; f++)
        {
            if (_foliageJobs[f].handle.IsCompleted)
            {
                _foliageJobs[f].handle.Complete();
                chunkInQuestion = _foliageJobs[f]._chunk;
                chunkInQuestion.foliageSpawned = true;
                float4x4[] _matrix = _foliageJobs[f].job.matricies.ToArray();
                _foliageJobs[f].job.matricies.Dispose();
                for (ushort i = 0; i < foliagePrefabLength; i++)
                {
                    uint length = _foliageJobs[f].job.length[i];

                    float4x4[] matrix = new float4x4[length];
                    Array.Copy(_matrix, 0, matrix, 0, length);
                    ComputeBuffer buffer = new ComputeBuffer((int)length, stride);
                    buffer.SetData(matrix);
                    chunkInQuestion.materials[i].SetBuffer("_PerInstanceData", buffer);

                    args[0] = (uint)lods[0].meshes[i].GetIndexCount(0);
                    args[1] = (uint)length;
                    args[2] = (uint)lods[0].meshes[i].GetIndexStart(0);
                    args[3] = (uint)lods[0].meshes[i].GetBaseVertex(0);
                    ComputeBuffer argB = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
                    argB.SetData(args);
                    chunkInQuestion.argsBuffers[i] = argB;
                    chunkInQuestion.length[i] = length;

                    System.GC.SuppressFinalize(buffer);
                    System.GC.SuppressFinalize(argB);
                    chunkInQuestion.foliageSpawned = true;
                }
                _foliageJobs[f].job.length.Dispose();
                _foliageJobs.RemoveAt(f);
            }
        }
    }
#

this is where i check the completion of the job for this task

#

and ill ss the profiler in one sec

solar spire
#

if this is just managed allocations, I can see a ton of them

signal flicker
solar spire
#

.ToArray(), new float4x4[, new ComputeBuffer(, all of these things allocate

signal flicker
#

i dont think that would cause an issue, i have 32 gb ram and do the same things in my non jobs version

#

well, very similar

#

and i do the exact same things when i disable "use jobs threads"

#

could that still matter?

#

im sorry if im asking stupid questions here lol

#

one of my buddies who knows jobs said he thinks its a bug

solar spire
#

I mean, if you're having FPS issues, what does the profiler say about it?

signal flicker
#

im not having fps issues thats the thing

#

the calculations are coming out wrong

zenith wyvern
#

I would assume the performance issue and your job results are two different issues

signal flicker
#

again, there is no performance issue

#

my FPS is fine

#

i converted to jobs so that i could generate chunks in the background without freezing the program

solar spire
#

If you're having issues when you enable threading then I imagine the issue is access collision

zenith wyvern
#

You said "the only issue is, while the job is active, my fps drops by like half" earlier

solar spire
#

where your data is being accessed as it's being written or written out of the expected order

#

but I can't see if you've disabled any safety checks

signal flicker
#

well heres the thing, the issue used to be way worse when i was using Mathf.perlin noise. i switched to unity.mathematics and its nowhere near as bad as before

zenith wyvern
#

Then all I can suggest is to continually reduce what you're doing until you can track down the error in your code

signal flicker
signal flicker
signal flicker
zenith wyvern
#

No worries

#

If you force your job to run in one thread (call it with .Run or .ScheduleSingle) does it affect your results?

solar spire
#

What is random in your job?

signal flicker
solar spire
#

Ah

signal flicker
#

setting the seed in awake

signal flicker
#

since my job is an IJobParallelFor

#
struct foliageJob : IJobParallelFor
    {
        public NativeArray<float4x4> matricies;
        public float4 boundsMinMax;
        public uint foliageLength;
        public NativeArray<ushort> length;
        public void Execute(int index)
        {
            float3 position;
            quaternion rotation;
            float3 scale;
            position.x = random.NextFloat(boundsMinMax[0], boundsMinMax[1]);
            position.z = random.NextFloat(boundsMinMax[2], boundsMinMax[3]);
            position.y = getHeight(position.x, position.z);
            //position.y = 0;
            rotation = Quaternion.AngleAxis(random.NextFloat(0, 360), Vector3.up);
            scale = Vector3.one * random.NextFloat(.6f, 1);

            //matricies[a] = float4x4.TRS(position, rotation, scale);
            matricies[index] = float4x4.TRS(position, rotation, scale);
        }
    }
#

though my code works as expected when i disable jobs threads

zenith wyvern
#

That doesn't look right to me, random is static?

#

You shouldn't be accessing mutable static data from a job

signal flicker
#

let me try to create a random instance within the job

solar spire
#

Yeah, I'm unsure whether you can thread Random - but I'm not familiar with it

zenith wyvern
#

It's just a value type so it's fine to pass to jobs but no job should access mutable static data

#

Everything a job accesses should be local if it's mutable or const if it's static

signal flicker
#

it didnt let me when i used random.range, though mathemetics.random seems to work for the foliage that does spawn

solar spire
#

Also, I imagine there's logic in getHeight that's relevant seeing as it seems to be y position which is off?

signal flicker
#

im gonna give replacing it a shot tho

signal flicker
#
static float getHeight(float x, float z)
    {
        float y = 0;
        for (int i = 1; i <= instance.iterations.Length; i++)
        {
            float2 P = new float2((x / instance.iterations[i - 1].divisor) + instance.offset, (z / instance.iterations[i - 1].divisor) + instance.offset);
            y += instance.iterations[i-1].evaluator.Evaluate(Unity.Mathematics.noise.snoise(P)) * (instance.iterations[i - 1].height / i);
            //y += instance.iterations[i-1].evaluator.Evaluate(Mathf.PerlinNoise((x / instance.iterations[i - 1].divisor) + instance.offset, (z / instance.iterations[i - 1].divisor) + instance.offset)) * (instance.iterations[i - 1].height / i);
        }
        return y;
    }
#

oh god that came out ugly

#

im gonna screenshot it

zenith wyvern
#

What is "instance"?

signal flicker
#

just a reference to the terrainGenerator object

#

since its a static method

solar spire
#

This seems like a case of accessing data across threads in a way that causes collisions

zenith wyvern
#

Again, everything that happens in a job needs to be local to that job

signal flicker
#

thats weird

zenith wyvern
#

You can't access static data or member functions or anything like that

signal flicker
#

it doesnt tell me that unless i enable burst

#
[System.Serializable]
public class heightIteration
{
    public float height = 3;
    public float divisor = 100;
    public AnimationCurve evaluator;
}
#

and this is all height iteration contains

solar spire
#

Unity can't analyse your statics to understand what's being written and read from afaik? It can only protect you from collection collisions

signal flicker
zenith wyvern
#

Think of your job as a black box. You pass your data in and it doesn't touch anything else. It's not quite that strict, like I said you can still access static data if it's read-only, but for learning purposes you need to move away from the idea of your job reaching out for the data it needs

solar spire
#

well, burst cannot access certain things so I imagine there were other warnings

signal flicker
#

also, if thats the case, then why does the issue get worse when using perlin noise vs the new method?

signal flicker
#

is there a way i could use the same random object for all of the calculations?

zenith wyvern
#

Well if I remember right all yoru jobs messing with shared data where they shoouldn't be is undefined behavior so it's pointless to speculate about the results beyond that I would think

solar spire
#

I would populate an array of random values that you then pass to your job personally

signal flicker
signal flicker
zenith wyvern
#

Yeah that's the way if you want them all to run in parallel

signal flicker
#

im dealing with millions of blades of grass drawn indirectly instanced here

solar spire
#

I'm not super familiar with random in jobs so there might be someone around who knows some tricks that helps 👀

zenith wyvern
#

It's tricky since random is a value type. I'm not sure of an easy way aside from pre-generating your data and passing it in

signal flicker
#

if i have to resort to that then whatever, thats not a huge pain

signal flicker
#

wouldnt it be super slow to pass all that into the job? and what am i even supposed to do about an animation curve?

zenith wyvern
#

I don't think you can use an animation curve in jobs, since it has managed data

#

People have come up with dots friendly animation curves on the forums

coarse turtle
#

you might want to sample the curve into a native container and write some methods to do what AnimationCurve does or derive mathematically what your curve is 👀

signal flicker
#

thats really disappointing to hear

solar spire
#

Yeah, I'm using a non-parallel job for that sort of thing:

public struct FlattenAnimationCurveJob : IJob
{
    public AnimationCurve Curve;
    public NativeArray<float> Output;

    public void Execute()
    {
        int length = Output.Length;
        float lastIndex = length - 1;
        for (int i = 0; i < length; i++)
        {
            float v = i / lastIndex;
            Output[i] = Curve.Evaluate(v);
        }
    }
}```
I wasn't sure whether it was needed, but I'm just keeping it safe
signal flicker
#

alright, well it looks like i have alot to rework here

#

thanks for the help guys

languid axle
digital kestrel
#

anyone else's build crash on run? I used com.unity.platforms windows build configuration

#

my scene is the default empty scene

karmic basin
karmic basin
sour atlas
#

but that seems to be due to some other thread beingslow

#

the entity debugger is also causing a ton of repaints

#

makes my pc sound like its going to blow up.

rugged grove
sour atlas
#

i tried pinpointing it by going by the common profiler markers pages advice but I cant find a thread ends shortly before?

#

Contains a sample that depicts a synchronization point on a thread. To find the thread it is waiting for, check the Timeline view for samples that ended shortly before this one.

#

every other thread is also in a waiting state

#

seems to be an Editor UI issue from what i can tell ?

amber flicker
sour atlas
#

Yeah the GPU is being used by whats labelled as "other" and the stack trace is really really deep to the point where I cant tell whats actually causing the issue in the first place

amber flicker
#

My guess is (knowing nothing about your project) trying to render a lot of things 🤔

sour atlas
#

that would be correct but it shouldn’t be an issue

#

its about 1k gpu instanced quads

amber flicker
#

Expensive frag shader? What are your gpu timings?

sour atlas
#

urp unlit

#

theres nothing expensive in there yet

amber flicker
#

Opaque rather than transparent I assume?

sour atlas
#

maybe draw instanced procedural is broken ? im grasping at straws really

#

yup, all opaque

amber flicker
#

Without getting stuck in to it myself the procedure I would follow is to either pair down until it doesn’t happen or repro in a new project. Unity has bugs but usually not this kind - they would cripple a lot of what’s out there

sour atlas
#

yup. it might be a weird issue with the hybrid renderer but im not sure honestly. gonna try swapping the call for a indirect draw, if that fixes it great, if not ill have to dive deeper

#

I just cant quite imagine why drawing 1k gpu instanced quads would be an issue

sour atlas
languid axle
#

@agile dome hello how are you?

agile dome
#

Were you reporting the spam or what? 👀

languid axle
#

Idk was I?

#

Btw can you look into the error

languid axle
agile dome
#

Don't tag people out of the conversation

languid axle
#

K but it was about the scam

karmic basin
#

I'm lost, your IDE complains that you can't pass it at T0, though there's another param as first. Maybe the IDE lags behind and it's an old error 🤷‍♂️ ????

pliant pike
#

I don't suppose anyone knows how or if you can pass a Blobasset into a method inside a struct

languid axle
#
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
class Gravity : ComponentSystem, IComponentData
{
    struct Com
    {
        public Transform transform;
        public Attractor a;
        public Rigidbody rb;
        public List<Attractor> attracted;
        public void Attract()
        {
            foreach (Attractor attractor in Attractor.Attracted)
            {
                //some code
            }
        }
    }
    protected override void OnUpdate()
    {
        Entities.ForEach((ref Gravity g, ref Com c) =>
        {
            c.Attract();
        });
    }
}
#

im still getting the error

karmic basin
#

No, don't inherit as a system and component at the same time

#

public struct Com : IComponentData {

#

and you're trying to pass a system inside the foreach lambda ?

#

You're messing with my brain :p

languid axle
#

im new to this, any other tutorials with hybrid didn't cover similar

pliant pike
#

yeah you should maybe try looking at the docs @languid axle

karmic basin
#

yeah

#

DId you see the Entities package documentation ?

#

Start here