#archived-dots
1 messages · Page 226 of 1
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
why wouldn't you just not add it until the player has pressed the button
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
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 
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.
https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstancedIndirect.html
if i understand this correctly i need to depth sort everything drawn by this manually, correct ?
If you use DrawMeshInstancedIndirect than yes
Any reason why you do not want to use Hybrid Renderer?
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
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 ?
ah thats great! gonna have to figure out how that works then :)
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
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 :)
Did you use Bursted Jobs in your previous attempt?
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.
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
its going to be more flexbible. i need flexibility AND performance not just performance haha
That is usually the case 😆
cant expect the environment artists to create a render pass order for every single layer lol
Is it 2D or 3D you are doing?
2D but with a Z-Axis
So a simple sort on the z-axis per material is not possible?
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
Is it a lot of static meshes or quite dynamic?
well the bulk is probably going to be environment related
so static for the most part.
i think.
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)
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
@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
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)
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
roger that.
had a better idea.
instead i use a single material and add the texture in a shader
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
hard to say if that would be an issue, you'd probably just have to profile it and figure out a soln once you notice some degradation
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));
}```
additional question: is there a way to quickly set every value in a hash map without affecting the keys?
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
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)
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 ^^
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
oh okay so Jobs and Collections
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
Did it went scope creep ? 🙂
🙂
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;
}
}
}```
I love everything you do 😛
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 ?
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?
If I understand correctly. pretty sure this occurs at every sync point.
So if you make no structural changes the query will still be valid.
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();
}
}```
I just wish unity would give us some update...
ignore the passing arguments in constructor though I'll have to use some kind of Init function ofc
Another thing, can code inside OnSystemACall() be burst compiled?
Did you try with .GetValueArray() ?
You're not supposed to call a system from another, that's not the intended use of the ECS pattern
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)
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
don't be passive aggressive like that
i think i had some strange issue with that but im gonna give it a go
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.
nevermind, not sure how i thought itd implement an array
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 🤔
You can access by key if you know it, no need to iterate over all values
What do you need?
could you give me an example ?
Just like an array, access by index
I mean key
thats for a NativeHashMap not a NativeMultiHashMap
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
but building the container one value at a time is really really slow for large containers
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 ^
That's the kind of hassle i never go through but good to know 👍
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 ?
no but you can make an assembly definition reference and write an extension function
public static void GetNativeArrayForKey<T, U>(this ref UnsafeHashMapBase<T, U> self) {
// Do some logic here
}
This isn't entirely correct, some times there is no way around it and Unity also does it internally
Alright good to know too 👌. I'd still keep it for a few cases only, not build everything around it :)
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)
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
I wouldn't depend on it
i dont think entity indices are even guaranteed to stay the same during run time
Are you sure? If they didn't it would mean all references would need to be remapped
Not sure how that would work
hmm, probably the entitites will be moved if I change archetype, right? (eg add a tag)
They will be moved, but the entity id and index shouldn't change afaik
yeah right
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 ?
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.
Thanks ! I guess i just mark them and ignore those marked ones 😄
is there a performant way to set all the values in a native collection (without affecting keys) without iterating through the whole thing?
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
}
}
}```
not sure, i just vaguely remember reading somewhere that reliance on entity indices is bad because they don’t necessarily stay constant, whether thats true or not i never checked
i think you can use a foreach ? but afaik thats the way to do it
don't think for each is supported in NativeHashMaps 🤔
I think they stay consistent, otherwise I don't understand how entity references would work.
I wouldn't rely on it because it isn't what they are meant for. If you need to identify stuff I would make it truly unique, like a guid
🤷♂️ maybe it was in the context of bad practice, i really don’t remember
🤷
Unless you mean the "version" part of the entity, and not the "id" part.
Because the version changes all the time
deleted nonsensical reply
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.
Sorry you’re right. I was thinking about ordering within chunks. Shouldn’t be replying when I should be sleeping 😴
that might be what i was thinking of. i honestly dont remember but im gonna try find out, not sure if i’ll find anything though
How does this play out with entity references? Wouldn't it incorrectly reference a different entity?
(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
Entity References are unsafe, version allows some leeway - in practice you'll probably never end up with reference to wrong entity - but generally speaking you can. Its like manually managing memory. Once you destroy an entity you better make sure that nothing references it.
How are they unsafe?
in the sense I've described
you can theoretically end up with a reference to another entity
I don't understand, how are you ever going to get an incorrect reference if the version increases each time (barring an overflow)
overflow exactly
Well yeah ok, but besides that they should be stable
yeah
namespace ExtensionMethods
{
public static class NativeMultiHashMapExtensions
{
public static void GetNativeArrayForKey<T, U>(this ref UnsafeMultiHashMap<T, U> self)
where T: struct, IEquatable<T> where U: struct
{
// Do some logic here
}
}
}
uh like this ? sorry not very familiar with c#
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
ah alright, i think i got it 😄
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
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
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
assembly defintiion references allows you to access internals since your script will be compiled 'into' Unity.Collections
Can I print the name or any entity data of an entity in a "public class ObstacleHitSystem : JobComponentSystem" ? More here: https://pastebin.com/8HJN2XiJ
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i might be doing something wrong but my IDE is not letting me use it
You'll probably need to make sure .csproj files are generated for those packages too
👍 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 ?
Just stick in your Assets/Scripts directory or whereever you want
you're going to reference the Unity.Collections assembly
That's not an assembly definition reference, that's just an assembly definition, they're 2 different things 🤔
Unity.Physics' package doc for ray casts in DOTS is outdated/inaccurate 🤦♂️ nothing in ECSSamples either, anyone know how to raycast with DOTS??
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
is there no way around being unable to schedule jobs from other jobs ?
Is there a way to tell an entity's name from ECS/DOTS/ SystemBase ?
like after:
https://pastebin.com/3297kJU3 Just 2-3 lines
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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
why not include it as your value in the NativeHashMap?
what do you mean?
NativeHashMap<int, YourStructType> map
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
the struct has to be blittable, which is pretty much the only requirement
so class references aren't allowed
im assuming a Rigidbody component reference isn't blittable lol
Yeah it's not
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
Well even then you won't be able to include it in a NativeArray
since your structs have nullable fields and such
I was considering having my rigidbody list sit in an old fashined array
and put an index reference in the structs
ah yea that's fine
right now im using a dictionary which i hate for some reason
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
I didnt realize that a native array could use keys (figured it was just an ordered list)
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
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!
np
ummmm
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?
It becomes an entity, no longer a game object @hard wagon
Look in the entity debugger in runtime, it should be there.
I understand that, but how do I make the entity have it's own rendering property so that I can see them in game?
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?
no tuples in Native Containers?
Doc is here https://docs.unity3d.com/Packages/com.unity.physics@0.6/manual/collision_queries.html#ray-casts
You mean this is inaccurate ?
Also for physics examples dont search in ECSSamples but UnityPhysicsSamples instead (same repo/project)
where to get started on DSPgraph?
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
Make a copy with EntityManager.Instantiate(srcEntity) then delete the old entity. I guess you'll have to update references to your old entity to point to the new one though
yeah the point was to make entity replacement hidden from all other entities
Any news on the ECS lately?
we're still using it!!
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!
are you doing all of the steps here https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.11/manual/creating-a-new-hybrid-renderer-project.html
@hard wagon do you have the hybrid renderer package installed?
Yes, reading through the docs
hybrid renderer also requires urp or hdrp
This does not solve the issue. It seems like the requirement to setup the hybrid settings has already been setup properly.
@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 😦
im having the same issue right now.
Check there positions maybe, that they aren't flying of somewhere
They're not going anywhere afaik
They're "There", but invisible.
well, convert and destroy is not right, if you want to keep the gameobject around
which I thought you mentioned earlier
Then that wouldn't be a pure ECS?
definitively not
but weren't you talking about rigidbodies earlier?
that's not pure ecs either
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
ecs is not feature complete
it is a preview package
it is on equivalent to classical unity
*not
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 🤔
yeah i'd wonder about material instancing as well
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.
you can totally render entities without gameobjects
but it's not ready to go straight out of the box
for me adding the URP asset to the graphics settings fixed the issue.
@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
Apparently the covert to entity was destroying the gameobject. Using the Inject gameobject method works, but going to put that on a hold for now.
the samples repo is a good starting place to get familiar with the current concepts of dots
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...?)
Thanks! Pretty sure that's where I got the examples from, but will try again.
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
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 ?
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
this is fixed size fortunately, i have to rewrite my whole code to use a flattened array and it's kinda huge 😢
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
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
I wrote https://github.com/sarkahn/dots-roguelike/tree/master/Assets/Lib/Pathfinding which is job/burst friendly if you want a simple reference. I found it gets pretty damn slow on very large maps and probably not suitable for anything but the most simple of games though
do I need to declare dynamic buffers as readonly?
In what context?
in ForEach job
If it's a parallel job yes. For single threaded jobs you can safely write to them in the ForEach
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.
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
If there was a way to do EntityManager.GetReadOnlyBuffer() to declare it readonly that way...
They only make sense being accessed via the entity they reside on
I'll dispose, no problem
You shouldn't dispose them either. The whole point is the ECS manages them so you don't have to
thanks for the ressource it will help me
the use case:
it doesn't. you have to dispose your own containers
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
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
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
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?
No. You're accessing the buffer as read/write when you use EntityManager.GetBuffer
oh..
That was my solution
With a lot of extension methods to access the relevant data from all the different buffers
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
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
thanks for the.. encouragement.. X)
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..
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
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)
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
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 🙂
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
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..
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
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
That doesn't really sound right, you're saying looping over a buffer of entities was faster than a plain array?
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
the reads from the array probably were random as well
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."
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
yeah it runned fine, then i added burst and it told me i had an error
why do you need to reassign node array with grid? Are you double buffering?
no but i need to store the result of my job inside this class to be accessed later by other monobehaviour classes
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?
You would have to track the job handle and force complete it before you pass it in
what is though the job made a copy of the array and did not modify it directly, i am wrong ?
yea that'd be the caveat
It doesn't make a copy, native containers are pointers
NativeArrays contain a pointer internally
So your struct copy still points to the same memory
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
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.
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
Depending on what you're doing you might be able to let the job run for part of the frame at least
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
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
yup i added burst compile
without burst the whole job thing actually made me lose exec time 👀
i still have a few things to optimize, thanks for the help though
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
NativeSortExtensions.Sort
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
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
no i mean some kind of list
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
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.
Yea you'll need to show the job because idk how you're structuring it
this is a dijkstra algorithm :
https://pastebin.com/6u9t54ty
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Can you show the full struct?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
you never allocated toVisit
NativeList<DijkstraTile> toVisit = new NativeList<DijkstraTile>();
There's no allocation supplied here
oh indeed
Which makes the internal pointer invalid
ok it works now thanks
that's very strange that declaring with no allocator works tho
now that you mention it yes i did not think of it
are Entity structs actually stored in memory or are they just a representation of indices?
Entities are just an id and a version. Components are what actually exist in contiguous chunks of memory
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?
@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
No it does not. leaving the convert to entity as Convert and Destroy removes it completely. it's invisible when played. I had to use Convert and Inject GameObject in order to see it in scene.
I even make sure that Hybrid rendering v2 was working (Console logs)
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
i think at least version of entity should stored somewhere
The screenshot I posted awhile ago basically shows what I'm seeing in unity.
That sounds pretty much right, yeah
Hmmm need to try URP then... will try this later after work.
Hi, given math determinism and a lack of player input, what could cause a NetCode misprediction?
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 :/
are the child entities rigidbodies?
no
they're transforms
im using [GenerateAuthoringComponent]
not IConvertGameObjectToEntity
for the prefab which I instantiate with command buffer
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
Translation is in parent space. The LocalToParent should be updated to reflect any changes to the Translation.
yeah, Translations are in local space just like you said ^^. I fixed this by getting its LocalToWorld.position instead of translation.Value
Hi ! anyones know what is the best way to start learning netcode for dots ?
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
- official documentation https://docs.unity3d.com/Packages/com.unity.netcode@0.6/manual/index.html
aaaand honestly I don't know other useful resources as a first start. Maybe people have started blogging about it ... ?
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
@kindred star seems to be an undocmented limit of that particular api
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/
@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
Hmm does EntityManager.MoveEntitiesFromWorld work decently with SharedComponentDatas that do not contain blittable data?
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
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?
@north bay Works now. Needed to 1. Avoid structural changes like you said; and 2. Make sure I'm syncing waypoint data in such a way that it's robust to rollbacks. One solution is to store the data in commands as mentioned by timjohansson. Another solution is storing it in a ghosted component. Thanks so much
Here's it working by the way
Any references / links with getting started with .17 DOTS? Super new to this concept
@ocean eaglesee the pinned post but ignore the wiki. honestly the wiki should be removed
Appreciate it. I’ll check it out
Hello! Is someone already dive into NetCode and Subscene a bit more than the samples provided?
Yeah follow the thread a couple swipes up. Someone ask for some net code references
@ocean eagle Actually I found some very interesting post about NetCode, SubScene and World Management: https://forum.unity.com/threads/subscene-questions.995572/
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
I did use 2021 for DOTS but it was very unstable. 2020 LTS is recommended.
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
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 🤷♂️
Most of DOTS packages are not "compatible" with 2021 atm stick with 2020 LTS
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! 🙂
if allocating memory is the cause of the block maybe you could allocate once during the bulk load of the application and then re-use the arrays
I'm gonna try that.
Still, does it make sense to consider allocating memory inside the actual Job, rather than from the main thread?
You could allocate and dispose from a job for intermediate job data, but you won't be able to get that data out to the main thread once the job is finished
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?
Hmm. If the job is running, and presumably writing to the native array, and you're trying to read from it from the main thread at the same time, that sounds like a race condition. Also I dunno how the main thread would know where to read from unless you allocated the native array from the main thread first and passed it to the job
I am pretty sure it isnt and even if it is that sounds like a pain to work with.
Maybe you could split your big job into multiple smaller jobs. When the first job finishes you could, say, know that the first part of the native array is no longer being written to and you could read from it safely. While you're reading it and using it from another thread (e.g. main thread), the second job could write to the rest of the native array
for the data that needs to be shared, this would be allocated outside the thread.
It would have worked perfectly if the job is parallelized, unfortunately, it is not. 😦
But at least I know that it should not be accessed at the same time from outside the job, even if it is just a read operation.
Seems like a large portion of the blocking was due to the memory allocation.
After segregating the two parts (allocating memory and scheduling job) it is clear that the allocation was blocking the main thread
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?
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
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 ?
https://hastebin.com/nadateyapu.csharp
in case it helps heres the entire conversion system
Im a little lost on this one.
GetAllUniqueSharedComponentData populates your list with the "default" value (in this case the default is all zeroed out vectors) and then with any existing data. It's been reported as a bug but apparently it's by design. If you don't care about the default you can just skip index 0
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.
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?
wdym by prefab entities? is it still going through the conversion system?
Yeah, the GameObject prefab is part of a NetCode ghost prefab collection and gets converted to an entity prefab and then instantiated with EntityManager.Instantiate(prefabEntity)
maybe its a bug and needs to be reported?
the havok guys are pretty good at responding to issues
@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?
@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)
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.
Hard to tell who you've replied to, but we did just ban a user
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.
Any nitro gift is a scam, it's extremely common
There's hundreds of websites with different url s that get created constantly
Heh, I'm not very street savvy on discord things. Luckily I wasnt stupid.
Yea, the website popped up literally an hour ago.
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 ...
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 ...
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.
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.
GetSingletonEntity<Player> where player is a component you tagged the player entity with when you created it
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.
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.
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.
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]
after some testing this does seem to work it just doesnt work for my specific system ? I'm really confused.
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. 😕
var q = GetEntityQuery(typeof(FooData));
var arr = q.ToComponentDataArray<FooData>(Allocator.TempJob).Reinterpret<int>();
here is the configuration, but don't know much more about configuring it
Oh cool thank you. Thats a start 🙂
ohhh thank you!
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.
I only need to read so thats fine.
anyone got an idea where this issue is coming from ?
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
Are you using built in render pipeline or urp...?
urp
don't think camera.onprecull works in the same fashion as built in renderpipeline, you might need to use this: https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html or a render pass
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
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.
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
if you have the entity index you can use GetComponentDataFromEntity<>()
Thank you.
thought that might be slow since its random access
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
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>
}
}
Cool
Thats super awesome
playerEntity.GetComponentDataFromEntity<AssignData>(); says Entity doesn't have that GetComponentDataFromEntity on Entity
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
uhh it works slightly differently, hang on
ComponentDataFromEntity<Component> foo =
GetComponentDataFromEntity<Component>();
ty
This is extremely helpful
I might have a 50,000 drones shooting lasers at me by tonight
there might be a better way of getting the component data for a single entity but i am not sure.
GetSingleton<DataType>
then later efficify it 🙂
heh i got my co worker to work on networking so i can save myself the pain from that
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
This code does not work Julien, if you notice, its syntax is the same as when I had an error.
its not
you are calling playerEntity.GetComponentdata
you need to remove the playerEntity.
How does it know what entity to get it from then?
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
Ty
and you use the entity as a lookup for the data to get
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...
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.
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
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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.
var componentArray = query.ToComponentDataArray<AssignData>(Allocator.TempJob);
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?
Yes, if you got the entity array as well the component and entity indices will match up
Sweet!
Assuming you're getting them both from the same query
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.
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
youre streaming your development right ? dm me a link and ill tune in every now and then
@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
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
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.
Is it possible to call a function(aka Method) in a Lambda expression Entities.ForEach
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
or burst function pointers
any ideas how to approach behaviour trees in DOTS?
pretty sure I saw a github project for that very thing
I saw one but was not burst compatible
yeah, thats the one
maybe you can get some inspiration, alternatively dataflowgraph might be of some use
Calabi I called my method static and it ran inside
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.
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.
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)
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
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.
Id crowdsource it 🤷♂️
the tech is fun, actually using it is hell
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.
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 😛
You could tell me
you'd just have to kill me
which is preferable than the current documentation
@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.
Well I'm sure something will happen by the end of the year
I mean, that's what they say themselves actually
@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
🤷♂️ 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 ?
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
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 🤷♂️
@karmic basin I wish I could share that optimism 🥲
//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 ?
I would hope it would be
my EditorLoop is taking up about 95% of the frame time, does anyone have a similiar issue with DOTS ?
To use DOTS I can't use 2021.1 right?
yep @fossil obsidian
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?
I've usually just set the capacity if I need to do a like a bulk add (which I think is pretty much Resize done internally)
resizes copy as well. best to pre-allocate
do you mean preallocate a list large enough to accomodate some upper maximum?
if you know it'll always be within a certain size (and the upper bound isn't ridiculously larger than the normal)
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
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
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 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
because that will allocate a new list with Capacity + 1
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
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
generous preallocation of some kind seems like the best bet
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
i was considering that too actually
anyone here play with that yet? I'm curious if it can do holes in the terrain out-of-the-box
my project is using spherical planets and gravity
nice.
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
It says orbis uses quad trees for dynamic LODs and for skirts blending between LODs
heh, yea
the dynamic surface geometry with the quadtree optimization is def powerful
im more focused on editability and internal structure though
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.
Cast it into ComponentType
That'll get me ComponentType not the component data.
But you can use that to get the component data via EntityManager.GetComponent(entity, ComponentType)
I think you misunderstand, there are no variants afaik for EntityManager.GetComponent(Entity, ComponentType)
Yea you're right
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
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
Oh cool, I didn't know about TypeManager, thanks 🙂
what about public T GetComponentData<T>(Entity entity) in EntityManager?
Gets the value of a component for an entity.```
@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) // ???
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
No worries, I appreciate the interest 🙂
I'm sure I'll be encountering all this stuff soon enough as well lol
I suspect I'm doing it wrong if I'm asking these odd questions
Literally just started into DOTs
What are ya planning make?
builder/crafting sandbox.
nice, I'd love to see more takes on the building/crafting genre, I think there is so much unexplored potential there
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
its a Sunday even us DOTS fanatics need a day off 🤷♂️
still having this issue, tried looking it up but nothing fixed it
Dont want to make a build every time i want to test 😛
Not sure if it's the case for you but I found keeping the profiler window open when I didn't need it was slowing my editor down a lot
I doubt that thats the issue, im getting awfully low framerates without the profiler too
at least awfully low for what they should be.
at the same time, try to profile the editor and see what's causing it. also if you are using some custom editor UI code, it might be bad. recently I had a hierarchy window extention that was calling Repaint() ON Repaint() I noticed it by hearing my CPU fan going crazy while using it XD
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
I have no Idea how the editor actually works though.
in time like this I just reset editor and that fixes the problem
what do you mean by that
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.
oh no it did not
Well, Profiler it'self takes half of the frame time and brings you down to 10 fps. Without it, the player loop updates at 20fps. I'd click on that PlayerLoop to see what is going on there
nothing happens when i click on it ? not sure if i just dont know how to use the profiler though lol
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?
apparently I forgot how to use it myself. so you need to go into hierarchy mode, can also enable deep profile, and you can go very deep into the call hierarchy and see if there is anything specific causing the issue
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?
What does the profiler say?
where should i be looking? im new to jobs
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);
}
}
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.
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
i've downloaded all packages neccesary for DOTS but i cant add using Unity.Entities
(this is brackeys from 2018)
try to add package com.unity.entities in the package manager from git url
this one?
its visual studio which isnt working, if i write it unity doesnt bring error but vs does
solved it had to regenerate the project files
Profile it. If you're not profiling then you're just guessing.
I will say it seems weird to allocate persistent arrays every time you run a job, shouldn't you be re-using them?
im rather new to jobs so i dont really know what im doing. however, the issue persists even when i use tempjob
also i only run the job once per chunk, so there isnt really a good reason to re use them
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
i know how to use the profiler
It's really the only way to track down performance issues
Are you disposing your arrays?
yes
Okay, can you show the profiler data showing your allocation issue?
hold on, ill send more of the script
If it is from allocations the profiler will show it.
i thought the profiler only showed the main thread
Like, your jobsTest class you posted earlier, where does it dispose of the array?
In the timeline view you can scroll down and there's a dropdown for jobs
i wasnt done with that one yet, this is completely different
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
if this is just managed allocations, I can see a ton of them
this is called from update btw
.ToArray(), new float4x4[, new ComputeBuffer(, all of these things allocate
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
I mean, if you're having FPS issues, what does the profiler say about it?
im not having fps issues thats the thing
the calculations are coming out wrong
I would assume the performance issue and your job results are two different issues
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
If you're having issues when you enable threading then I imagine the issue is access collision
You said "the only issue is, while the job is active, my fps drops by like half" earlier
that was a different issue
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
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
Then all I can suggest is to continually reduce what you're doing until you can track down the error in your code
not that im aware of, where should i check?
im really sorry, i just realized you did reply to my first question
yea thats been fixed, my new question is related to this
No worries
If you force your job to run in one thread (call it with .Run or .ScheduleSingle) does it affect your results?
What is random in your job?
static Unity.Mathematics.Random random;
Ah
setting the seed in awake
afaik i cant use either of those
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
That doesn't look right to me, random is static?
You shouldn't be accessing mutable static data from a job
let me try to create a random instance within the job
Yeah, I'm unsure whether you can thread Random - but I'm not familiar with it
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
it didnt let me when i used random.range, though mathemetics.random seems to work for the foliage that does spawn
Also, I imagine there's logic in getHeight that's relevant seeing as it seems to be y position which is off?
im gonna give replacing it a shot tho
right, ill post that here
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
What is "instance"?
This seems like a case of accessing data across threads in a way that causes collisions
Again, everything that happens in a job needs to be local to that job
thats weird
You can't access static data or member functions or anything like that
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
Unity can't analyse your statics to understand what's being written and read from afaik? It can only protect you from collection collisions
it could when i add [burstcompile] ontop of it
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
well, burst cannot access certain things so I imagine there were other warnings
also, if thats the case, then why does the issue get worse when using perlin noise vs the new method?
that sounds right
is there a way i could use the same random object for all of the calculations?
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
I would populate an array of random values that you then pass to your job personally
and is there a way i can use the same variables for height for the calculations
thats what i needed the jobs for in the first place
Yeah that's the way if you want them all to run in parallel
im dealing with millions of blades of grass drawn indirectly instanced here
I'm not super familiar with random in jobs so there might be someone around who knows some tricks that helps 👀
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
if i have to resort to that then whatever, thats not a huge pain
what is a pain is this
wouldnt it be super slow to pass all that into the job? and what am i even supposed to do about an animation curve?
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
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 👀
thats really disappointing to hear
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
i could define it mathematically actually
alright, well it looks like i have alot to rework here
thanks for the help guys
anyone else's build crash on run? I used com.unity.platforms windows build configuration
my scene is the default empty scene
What is Com ? Unity doesnt recognize it as a component
Last time I used it, it worked. A while ago but nothing should have changed much since ^^. Check build log to trace the source ?
works for me
alright so i found out its Gfx.WaitForPresentOnGfxThread -> Semaphore.WaitForSignal
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.
yes that just GFX thread waiting, you need the main, I don't remember how to view threads in hierarchy view
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 ?
This means you’re gpu bound usually - ie it’s waiting for the gpu
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
My guess is (knowing nothing about your project) trying to render a lot of things 🤔
Expensive frag shader? What are your gpu timings?
Opaque rather than transparent I assume?
maybe draw instanced procedural is broken ? im grasping at straws really
yup, all opaque
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
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
https://assetstore.unity.com/packages/tools/utilities/debug-log-extensions-162798
Does anyone know if this is compatible with DOTS ?
A struct
@agile dome hello how are you?
Were you reporting the spam or what? 👀
This
Don't tag people out of the conversation
K but it was about the scam
inheriting IComponentData, right ?
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 🤷♂️ ????
I don't suppose anyone knows how or if you can pass a Blobasset into a method inside a struct
[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
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
im new to this, any other tutorials with hybrid didn't cover similar
yeah you should maybe try looking at the docs @languid axle