#archived-dots
1 messages Β· Page 197 of 1
on what object?
I guess its a member of SystemBase
honestly im not sure
i think GetBuffer can get rewritten by the code gen
so safer to use
Oooo docs have updated
yea use GetBuffer
alright cool thanks
Keep in mind with GetBuffer you can't specify your access as readonly
You need to manually pass in a BufferFromEntity for that
What would you need a readonly buffer for?
will the job system complain even if you don't write to it?
Like any component how you access it in a job determines the scheduler's ability to parallelize your jobs
Plus if you wanted to access a buffer that isn't in your query inside a parallel job in the first place, the safety system will complain if it's not read-only
theres samples tho π
Ooo fun
unfortuantully all their curve stuff is blobs which are read only π¦
so im wanting to stream out data (replay info) as it gets old
I have a dynamic buffer per type im recording which is the keyframe info that builds up as the game goes on
So far i havnt seen anything in DOTS that would help with this
My current thoughts are to write it into a native stream as it gets old and use a long lived Thread to handle writing it to files
Any ideas on this?
Can I use native collections in old Threads?
Ah I see that now, so how do you use BufferFromEntity?
var bfe = GetBufferFromEntity<ABuffer>(true); // <-- Bool specifies read-only
Pass that into the job
And use WithReadOnly(bfe)
The most common reason is you want to run some rendering code at a specific point in the rendering pipeline. A place your code is not executed. So you record a (rendering) command buffer and attach it to that point of execution. That was the way to extend the built in pipeline, and scriptable render pipelines are built the same way, making it possible to interweave C# driven rendering code with C++ work without jumping back and forth between and doing callbacks
Not very DOTS related though π
So... voodoo. That's all you had to say. Voodoo.
@zenith wyvern worked thanks.
whats the difference between math.select and just using a ternary operator?
am i doing this right? how come i cant use the allocatestring with using (BlobBuilder)? it makes me manually dispose [Serializable] public struct RoomInfo { public string Name; public string Description; public BlobAssetReference<RoomInfoBlob> ToBlob() { BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp); ref RoomInfoBlob roomInfo = ref blobBuilder.ConstructRoot<RoomInfoBlob>(); blobBuilder.AllocateString(ref roomInfo.Name, Name); blobBuilder.AllocateString(ref roomInfo.Description, Description); BlobAssetReference<RoomInfoBlob> blob = blobBuilder.CreateBlobAssetReference<RoomInfoBlob>(Allocator.Persistent); blobBuilder.Dispose(); return blob; } }
In this system can be something potential wrong ?
im not sure but i have random crashes on android and in systems which Run on main thread with EntityManager so potential there are no errors should be
is it legal to use async in systems?
probs the async method
yes im not sure about this too but can't find info to confirm of usage async methods
i would expect async to not be supported
problem that this methods working and crash happens randomly on systems not directly depends on this
Probably silly question. If data components are pure data then where am I supposed to store methods for that data? Extension methods?
as sometimes its faster, or slower
wait the crashes are in other systems?
@acoustic spire what sort of methods?? your mainly writing your methods in systems as ForEach's
Yeah but I mean some common operations on same data component that is going to be used in multiple systems
weirdly i dont really have many of those
the few i did i made into a normal static method
but im not sure thats correct
@half jay If you remove that system do you still get the random crashes?
Maybe do more testing and see if you can narrow down exacly what system is causing issues
yea, static method is the most obvious way. however, it's not so good for code organizing
Yes crashes on other systems. This systems print logs and working. I'm trying test case without this system and got crash too.
then its probably not that code π
i would replace the async at some point, as it seems risky to me
also we are using this event system and i hope this is not reason why its crash
https://gitlab.com/tertle/com.bovinelabs.event
Crash log
one of the crashes
and how there can be an error if query exists
there's a ternary behind, but it's Burst powered π
yes data only but "helper" methods for that data is okay
@half jay I didnt think you could WithBurst entity manager stuff?
I would change that whole system to use a command buffer
then you can definitly burst
and use schedule
ye im testing this without Burst. But log with crash that im show above one of the cases.
singleton?? only 1?
yes im sure its only one entity with ArVoxelGridComponentSingleton
will there only ever be one?
yes
then delete all the system stuff
no point really for 1 entity create step
sorry not delete sysem, delete the foreach
and use the singleton entity manager methods to get to the data
but i need combination of existing this component
a manual entityquery.tonattivearray.first??
and singleton entity really shoudn't break there anything or im mistaken?
ill try this
same crash
crash log
weird...
yes
definitly that system?
yes
Please use code tags for posting code
I don't see anything wrong with it, I can only assume it's from some interaction between that system and something else in your game
it has a bunch of removecomponent log messages...
I'm confused for some reason before I destroy an entity after a job I have to create a sync point is that normal π
this.CompleteDependency();
if (HasSingleton<FindNeighborCellEvent>())
{
var tempevent = GetSingletonEntity<FindNeighborCellEvent>();
EntityManager.DestroyEntity(tempevent);
//Debug.Log("It's not destroying the entity for some reason");
}```
You're destroying an entity after you've scheduled a job. So the job hasn't happened yet
its outside the job so I dont think that applies
yeah if I don't use this.CompleteDependency(); then I either get a compiler error or it doesn't destroy the entity at all
What compiler error?
Although even if there was no error, by destroying an entity on the main thread you're forcing a structural change so it's going to cause a sync point anyways
The previously scheduled job FindNeighbourSystem:FindNeigbourCell writes to the BufferTypeHandle<FlowfieldNeigborEntities> FindNeigbourCell.JobData._lambdaParameterValueProviders.forParameter_flowbuff._typeHandle. You must call JobHandle.Complete() on the job FindNeighbourSystem:FindNeigbourCell, before you can deallocate the BufferTypeHandle<FlowfieldNeigborEntities> safely.
Meaning effectively it would force your job to complete immediately anyways
use a command buffer from the job
yeah I know destroy an entity creates it's own sync point but its just weird that it requires the job to complete before allowing it to destroy a completely unrelated entity
everything will be happy then
@pliant pike doesn't seems to have anything to do with the destroy π€
mind sharing more code?
I'm not sure but to me it feels like you might be accessing that NeighbourEntities component/buffer on the main thread somewhere else
By forcing a sync point immediately after scheduling a job that accesses it you're just by coincidence triggering some dependency issue with how it's trying to schedule your jobs
Entities.WithName("FindNeigbourCell").ForEach((DynamicBuffer<FlowfieldNeigborEntities> flowbuff, in FlowFieldData fluffydata, in CellData tempcelldata) =>
{
//NativeList<int2> tempint2list = new NativeList<int2>(Allocator.Temp);
FixedList64<int2> tempint2list = new FixedList64<int2>();
//NativeArray<int2> tempint2list = new NativeArray<int2>(4, Allocator.Temp);
tempNeigbourindices.Execute(tempcelldata.gridIndex, fluffydata.gridSize, ref tempint2list);
for (int i = 0; i < tempint2list.Length; i++)
{
flowbuff.Add(tempint2list[i]);
}
//tempint2list.Dispose();
}).ScheduleParallel();```
that's the job just above the code I already posted
@karmic basin wouldnt slapping burstcompile on a job that contains a ternary do the same thing?
I mean, the entire OnUpdate functions would be better
Are you accessing FlowFieldNeighbour on the main thread anywhere in your game?
Not just in that system, anywhere
I don't think so π
@safe lintel I belive the math.*** functions have some extra magic when it comes to burst
I haven't forced the order of the systems though
Well it sounds to me like what I was hitting when I was getitng buffers on the main thread to pass into other jobs. It created very annoying and hard to track dependency errors
I fixed it by never accessing a buffer on the main thread
Outside of a ForEach at least
the only other place its mentioned is where I create it
@ocean tundra hmm, it didnt have a math.select for quaternions/float4x4 π€·ββοΈ
does your singleton entity with FindNeighborCellEvent happens to be the same one that have the DynamicBuffer<FlowfieldNeigborEntities> on it?
the magic of the math class... maybe not everything exists
nope its a single entity with just that componentdata
maybe its just because systems at the beginning are running in the wrong order
although it should just run when that singleton entity exists
@safe lintel @ocean tundra yeah it has a directive to optimize the SIMD instructions. I guess the compiler does a not so great job on its own with a ternary
it does it in another job as well, it seems like it doesn't like structural changes after the jobs
I will say if forcing your job to immediately complete fixes the error - that's fine. Like I said it's going to happen anyways since you're causing a structural change
I've tried destroying the entity before the job and that seems to have fixed it
that's probably the better place
I mean the real best solution is what Roycon suggested, use a command buffer. Unless you have a good reason not to
Putting a structural change in the middle of your update loop should be avoided if possible
you can use commandbuffers outside a job
Yeah
is there some trick to finding jobs in the profiler?
according to the profiler the above job is only run once before all the entities are created and yet somehow it still fills in all the correct values
also Bursted jobs appear and disappear seemingly at random from the profiler
yeah it might help if I didn't forget I'd already made a similar named system 
i dont think its changed
π
so whats the old way?
cause subscenes is all about the actual entities right? not prefabs?
oh the updated docs have a bit on prefabs
well subscenes mostly preconverting stuff so no need to do it on the start of the game/scene etc
Looks like i should have a IConvet that has a list of all my prefabs, and that will call DeclareReferencedPrefab
that way they will all end up in the subscene
though doesnt have to be in a subscene(if you slap a convertotentity on it)
i read somewhere that convertotentity is on the way out
will be removed in a future version
yeah but that future could be a long way away π₯²
so def dont want to rely on it
i know π
i heard about it being removed like last year
i dunno, all you gotta do to update something with convert to entity(assuming one day it vanishes) is move it to a subscene, boom done π
it seems this whole subscenes and conversion flow is where unity is investing their time in, so eventually it should be good to go π
true
anyway there are issues with subscenes and uitoolkit and some other people have other probs so just saying it can be temporarily avoided if you also have issues with em
convert to entity is runtime tho?
yes, like start, should happen just once at the beginning
ill probably just try to make it work with subscenes
untill i run into issues
π
it would be good to be able to assign unique Ids to the prefabs all in the editor
I mean they still use ConvertToEntity with the new dots editor that is being actively worked on
I don't think it's going away any time soon
yea probably not
Wondering if someone could help me with a project tiny question
Seems like my webGL build fails when using IConverGameObjectToEntity ?
Can I not sure that interface ?
Why do I get this error in my component on startup but in official Unity example it's valid code that uses mesh in component?
ArgumentException: Client.Dots.ChunkComponent contains a field of UnityEngine.Mesh, which is neither primitive nor blittable.
Example:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Assets/Advanced/ManagedComponents/SimpleMeshRenderingAuthoring.cs
It worked for me last time I was messing with Tiny. Make sure you have all your authoring scripts in a separate assembly that isn't in your root assembly, as per the getting started guide
Ah
Let me try that
@zenith wyvern
Do you have your root assembly in script and then move authoring above it ?
Sorry I don't understand the question. Your root assemblies exist alongside your scripts. You need your authoring scripts in their own folder with their own assembly that isn't included in the root assembly that gets referenced by your build configuration
Ok let me try thank you
What could be causing Entity Doesn't exist exception in this code? It doesn't tell me where its happening at unfortunately :(.
private void SpawnPeds()
{
if (pedCount >= 40)
return;
var archeType = pedArchetype;
BufferFromEntity<Node> buffer = GetBufferFromEntity<Node>(true);
var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter();
var peds = pedCount;
Entities.WithReadOnly(buffer).ForEach((Entity entity, int entityInQueryIndex, ref Path path) =>
{
var rand = Unity.Mathematics.Random.CreateFromIndex((uint)entityInQueryIndex);
foreach (var node in buffer[entity])
{
if (peds >= 40)
break;
int next = (node.index >= buffer[entity].Length - 1) ? 0 : node.index + 1;
int prev = (node.index >= 1) ? node.index - 1 : 0;
var pos = math.lerp(node.position, buffer[entity][next].position, rand.NextFloat(0, 1));
var e = commandBuffer.CreateEntity(entityInQueryIndex);
commandBuffer.AddComponent(entityInQueryIndex, e, new Coord() { position = pos });
commandBuffer.AddComponent(entityInQueryIndex, e, new Ped() { nodeIndex = node.index, needsNewDestination = 1 });
commandBuffer.AddComponent(entityInQueryIndex, e, new NeedsCompanion());
}
}).ScheduleParallel();
}
private void SpawnCompanions()
{
Entities.WithStructuralChanges().WithAll<NeedsCompanion, Ped>().ForEach((Entity entity, int entityInQueryIndex, ref Coord coord) =>
{
var agent = GetPedModel();
agent.transform.position = coord.position;
EntityManager.RemoveComponent<NeedsCompanion>(entity);
EntityManager.AddComponentObject(entity,agent);
pedCount++;
}).WithoutBurst().Run();
}
protected override void OnUpdate()
{
SpawnPeds();
barrier.AddJobHandleForProducer(Dependency);
SpawnCompanions();
}
In your lambda, you are only querying for entities that have the Path component
So when you write foreach (var node in buffer[entity]) <- Are you sure that all entities with Path component have a Node buffer?
Also you can't use foreach statements in jobs because they rely on try catch. I don't think Unity has support for try catch statements in Jobs.
Yes they do
and
i ll try with for loop now
but all path entities have a node buffer
You can access DynamicBuffers like so to: Entities.ForEach((DynamicBuffer<Node> nodes, ref Path path) => {})
change the foreach to a for loop
then the query will be all entities with <Path> & <Node>
awesome thanks guys!
also i dont see you adding a dependancy for that command buffer
is it a built in one?
oh its in that last bit of code π
Well that got rid of the error but i am having the weirdest issue, I think might be a race condition
var pos = math.lerp(node.position, buffer[entity][next].position, rand.NextFloat(0, 1));
the entity is set to this position
then I create a gameobject to mirror its position
and its not going to the same spot
private void SpawnCompanions()
{
Entities.WithStructuralChanges().WithAll<NeedsCompanion, Ped>().ForEach((Entity entity, int entityInQueryIndex, ref Coord coord) =>
{
var agent = GetPedModel();
agent.transform.position = coord.position;
EntityManager.RemoveComponent<NeedsCompanion>(entity);
EntityManager.AddComponentObject(entity,agent);
pedCount++;
}).WithoutBurst().Run();
}
that would randomly position it between those 2 pos?
Thats what its supposed to do
but
there aree four nodes
and it only spawns at 1 of them
and
the value of the companion gameobject
is being set to something random its not setting it t o the value that ped is being set to in the parralel job
check the entity inspector
is it creating all the enitities it should?
do they have the right position in the entity inspoector?
cause that SpawnCompanions bit is the part that looks odd to me
first bit looks right but may keep spawning forever as i dont see you removing Path
the SpawnCompanions part tho, looks like it will loop over all peds that have needsCompanion and attach them all to the same entity/agent
@ocean tundra
private NavMeshAgent GetPedModel()
{
return GameObject.CreatePrimitive(PrimitiveType.Cube).AddComponent<NavMeshAgent>();
}
its not the same agent
so you should have a cube at every path point??
That is what I am attempting
but its just putting them all at every point in index 0 of the buffer
so its actually spawning them all?
and youve confirmed the entitys in the entity inspector are correct?
They have the right ocmponents and stuff
but you can't see the values
or im just dumb
how do I see the values of entities components in entity debugger
change the foreach to a for and use the for index not node.index
ummm they just show...
show your node component code
public struct Node : IBufferElementData
{
public int index;
public float3 position;
}
yea thats fine
you see this?
https://forum.unity.com/attachments/insp1-png.781201/
your node should look like child in that pic
after you have selected your entity
ah I had the inspector hidden
ok one sec gotta restart unity
the values are correct
the cubes are spawning at this position though
Vector3(58.3333359,0.691762924,31.5)
Vector3(58.3333359,0.691762924,28.3)
current code
private void SpawnPeds()
{
if (pedCount >= 40)
return;
var archeType = pedArchetype;
var commandBuffer = barrier.CreateCommandBuffer().AsParallelWriter();
var peds = pedCount;
Entities.ForEach((Entity entity, int entityInQueryIndex, DynamicBuffer < Node > buffer, ref Path path) =>
{
var rand = Unity.Mathematics.Random.CreateFromIndex((uint)entityInQueryIndex);
for (int i = 0; i < buffer.Length; i++)
{
var node = buffer[i];
int next = (i >= buffer.Length - 1) ? 0 : node.index + 1;
int prev = (i >= 1) ? node.index - 1 : 0;
var pos = math.lerp(node.position, buffer[next].position, rand.NextFloat(0, 1));
Debug.Log(pos.ToString());
var e = commandBuffer.CreateEntity(entityInQueryIndex);
commandBuffer.AddComponent(entityInQueryIndex, e, new Coord() { position = pos });
commandBuffer.AddComponent(entityInQueryIndex, e, new Ped() { nodeIndex = i, needsNewDestination = 1 });
commandBuffer.AddComponent(entityInQueryIndex, e, new NeedsCompanion());
}
}).ScheduleParallel();
}
private void SpawnCompanions()
{
Entities.WithStructuralChanges().WithAll<NeedsCompanion, Ped>().ForEach((Entity entity, int entityInQueryIndex, ref Coord coord) =>
{
var agent = GetPedModel();
agent.transform.position = coord.position;
EntityManager.RemoveComponent<NeedsCompanion>(entity);
EntityManager.AddComponentObject(entity,agent);
pedCount++;
}).WithoutBurst().Run();
}
im going to
Maybe I'm blind but it doesn't actually look like you're using that rand
just not yet
@zenith wyvern ```
var pos = math.lerp(node.position, buffer[next].position, rand.NextFloat(0, 1));
ok what about the enitities the command buffer is spawning
in the enitiy inspector
as that code looks ok
They are good
the cubes are spawning at this position though
Vector3(58.3333359,0.691762924,31.5)
Vector3(58.3333359,0.691762924,28.3)
and
i removed node.index
replaced it with i
in SpawnCompanions print out coord position
and do you have any other systems messing with coord?
no
anyone know if DOTS Animation is supposed to allow for retargeting animations in any capacity?
I tried manually constructing a rig using the rig authoring, but it doesn't seem to like the different bone positions
@ocean tundra The position its printing in SpawnCompanions is fine.
@gusty comet wtf
what about another system that runs AFTER SpawnCompanions that messes with the component object
how?? nothings racing
idk
hows it putting the cube at a random position
nothing moving it
The place its spawning isn't even anywhere near any of the nodes on the path either
step 1 frame 1 you schedule spawn peds... frame 1 then ends frame 2 your scehding spawn peds again, and then SpawnCompanions would run
whats stopping spawnPeds from running again and again?
that should be spawning millions of entities
if (pedCount >= 40)
return;
its only spawning 40
That check is in spawnpeds job
then i increase ped count each time it spawns a cube in spawncompanion
even if it spawns crazy numbers it should be ok
hmm
if i pause the editor
and then press play
and go through frame by frame
they spawn at the correct position
then teleport randomly later
i don't π¦
I had one
but i deleted it
i wonder if
its still accessing it somehow
let me
delete solution
let unity recreate it
check the systems window
check the files too
Ok i fixed it
Not sure how I fixed it
I changed like 4 things and now its working xd
Are you using subscenes by chance?
I am not
can each entity only have one buffer?
or can you create multiple buffers?
of different types
One per type, you can have multiple types
how do i declare referenced assets? it says i can't do it in uh.. IConvertGameObjectToEntity and the IDeclareReferencedPrefabs is for gameobjects only. I wanna declare scriptable objects as referenced assets if possible
nvm i think i have to make a system for it
conversionSystem.DeclareAssetDependency
Its actually a joke how hard it is to get reliable "random" numbers using dots.
I've never had an issue with rng producing the same numbers before using it.
If you only have one entity of a certain type CreateFromIndex isn't usable, and
idk how you'd go about getting a seed for Unity.Mathematics.Random in a job
i would use time but its going to be so close every loop that it wont make a diff
This is basically the solution I use when I need reliable RNG in jobs https://reeseschultz.com/random-number-generation-with-unity-dots/
How to idiomatically generate random numbers in Burst-compilable jobs with Unity DOTS.
Using extensions methods can make it pretty clean
Gives you a single seed point and you always have good distribution since you're reusing the same RNG
I mean RNG is just a struct. So you could just attach it to a singleton entity in a component if you wanted to
I guess you would still have to get it on the main thread and pass it in though so I guess that wouldn't make it any more convenient than what he's already doing in that article
@zenith wyvern I think I am just going to pass the applications mem usage as the seed for unity.mathematics.random
You mean inside the foreach?
No matter what you do if you're not re-using the same rng you're just not going to see good distribution, afaik
But I'm no expert on the subject
Whats a OrderVersionFilter ? it exists on Entity Query SetOrderVersionFilter ?
Filters out entities in chunks for which no structural changes have occurred.
Sounds like ChangeFilter but explicitly for structural changes
so change filter will fire when a component is added or the id has changed??
Whenever a component is accessed as read/write. Including when it's created
sweet
On a per-chunk level, mind you
Hmm whats an example use case of that lol
how come Dependancy still isnt public on System?
am i making a mistake by making it public and using it?
It's used by the framework to handle dependencies between systems. The physics systems expose it to be able to force other systems to run before or after them
I think it should be fine as long as you don't try to write over it between updates
Yea i have a system that builds up a nice unique list of ids that i need to access, to make that safe i need the write job dependancy
no ill never write to it
only use it to combine dependancies in another system
My roguelike is turn based, so if the game is waiting for player input there's no reason for any systems to be running. I use change filters for that purpose, so my render system doesn't update until something in the game changes
In my case rendering a new game state involves rebuilding a mesh so there's a good reason to minimize it as much as possible
@zenith wyvern even the article you linkeds way is still always producing 0
Entities.WithNativeDisableParallelForRestriction(randomArray).ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex,DynamicBuffer < Node > buffer, ref Path path) =>
{
int val = randomArray[nativeThreadIndex].NextInt(0,1);
Debug.Log(val.ToString());
}
I feel like the probleem is
I only have 1 path entity spawned
so nativethreadindex
is the same always
It's not inclusive
If you want 0-1 you need to put 0-2 in the range
And don't forget to assign back to the array
Still just produces 0
Remember it's a struct so you need to manually write it back to the array after you use it
var rnd = randomArray[nativeThreadIndex]
//use rnd
randomArray[nativeThreadIndex] = rnd
ah
i see
sec
That worked
awesome!
thank you!
@zenith wyvern is NextFloat inclusive?
Not sure, I think so. It would be weird if it wasn't given how floats work
Lmao its odd to me that NextInt isn't inclusive but nextfloat is
yep
it is inclusive
UnityEngine.Random.Range is the same way
The way I always think of it is that if you pass in the length of an array as the second number you won't get an out of range exception
lmao I been passing length of array - 1
rip me
time to fix a ton of bugs
in a ton of diff projects
Hahah
I never noticed that the second value is exclusive in unityengine.random.range
Yeah I was confused by it a lot too for a while. The array thing always helps me remember
And for floats, it just doesn't make sense for it to be exclusive. What's "-1" for a float? Could be anything
So do I need to regenerate randomArray every now and then or will it be fine?
You should be fine to use it for the whole game
Alright also
do I need to do randomArray[nativeThreadIndex] = rnd
every time i use it
or just once after I use it 3 times
You need to do it before it leaves scope
As long as you're not using it directly from the array yeah. Assign it to a local variable first like Roy showed, then assign that back to the array at the end
alright awesome
You guys are both legends
Also that blogged you linked
is a goldmine
I was looking at it earlier for how to spawn entities
Yeah he knows what he's doing for sure
ToNativeArray is a copy, so slower than the alternative AsNativeArray, which just gives "less safe" access to the underlying data
Would it be a bad idea to take do something like
var arr = Array.Sort(buffer.AsNativeArray());
then read the data from the array?
or even
arr = Array.sor....
buffer = buffer.FromArray(arr);
Well Array.Sort is for managed arrays. There are native array extension functions for sorting that should work
Not sure though
Array.Sort works fine on native arrays
You would be sorting the actual buffer though so as long as that doesn't mess you up anywhere else I tihnk it's fine
just wondering if it would break something internally
I don't think so. You can write to the arrays you get from AsNativeArray without any issues, so I can't imagine a sort would do anything harmful
Thats fucking awesome.
yea i used to sort dynamic buffers by using as native array
you can even limit the sort to only run on X items
how?
this is how i am sorting now
public struct DistanceComparer : IComparer<Node>
{
float3 value;
public DistanceComparer(float3 distanceToTarget)
{
value = distanceToTarget;
}
public int Compare(Node a, Node b)
{
var targetPosition = value;
return math.distance(a.position,targetPosition).CompareTo(math.distance(b.position, targetPosition));
}
}
var pos = Camera.main.transform.position;
Entities.WithAll<Path>().ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, DynamicBuffer<Node> buffer) =>
{
buffer.AsNativeArray().Sort(new DistanceComparer(pos));
}).ScheduleParallel();
Looks fine to me. Assuming you're passing that buffer as Ref
NativeSlice maybe?
yea thats what i was just thinking
I don't think you can use that in jobs though
i think i must have sliced the bit i wanted and sorted that
Unless I'm remembering wrong
When you use Job.WithCode..... and Schedule it wont parallel it right?
like only 1 job with that code runs?
Yeah it runs on one job on a single thread
Why is this job causing InvalidOperationException: The BufferTypeHandle<Node> has been declared as [WriteOnly] in the job, but you are reading from it.
private void SortPeds()
{
var pos = Camera.main.transform.position;
Entities.WithAll<Path>().ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, ref DynamicBuffer<Node> buffer) =>
{
var arr = buffer.AsNativeArray();
arr.Sort(new DistanceComparer(pos));
buffer.CopyFrom(arr);
}).ScheduleParallel();
}
I'm not sure but buffer.CopyFrom(arr); Doesn't make sense. arr is the buffer
They both point to the same data
it copies arr into buffer
yes but don't I have to since buffer is a struct?
No, if you were reading an element out of the array at some index, and changing that element, then you would have to write it back to that same index. But you're changing the array itself
Ok fixed
lets see if it stops the exception
it did
thanks!
AsNativeArray doesn't take count into consideration and my loop was reading default(Node)
just something to note in case you ever run into some weird bug with it
Native Stream, Does every AsWriter... BeginForEachIndex also need a AsReader BeginForEachIndex?
I'm getting : BeginForEachIndex can only be called once for the same index (0). errors
Yeah, I think essentially it's saying that when you read with BeginForEach then the contents for that index are annihilated as soon as you end reading
That's my guess anyways
Any good ideas on how to even disperse entities in an area around a vector?
right now I am just sorting an array of points then looping through it until I spawn the max amount
this is causing the entities to have less than desired spawn points
When that happened to me I ran a second "UnstickFromWalls" system that runs after spawning. It had better awareness of the map so could make better decisions on how to place entities
so that would explain the error, im not reading so never resetting that index
Well its not that they are sticking to walls, but since its random sometimes the area to my left will have tons and it will be a ghost town where the cameras looking
If you're using random correctly it should be evenly distributed across an entire area
At least from what I've seen
well its random
sometimes that is true
sometiems rng doesn't work out
and more 3's than 2's generate
and then you have more entities in one area
Can i write system like this With burst and structural changes ?
Entities
.WithStructuralChanges()
.WithBurst()
.ForEach((Entity e, in RayHitComponent hit,in CalculateHitComponentSingleton comp, in SelectBlockInputComponent selectedBlock) =>
{
var requestEntity = EntityManager.CreateEntity();
EntityManager.AddComponentData(requestEntity, new BlockPipelineTag());
EntityManager.AddComponentData(requestEntity, new GhostTag{IsGhost = true});
EntityManager.AddComponentData(requestEntity,new AddObjectPlanComponent{Id = selectedBlock.BlockId,Matrix = comp.CurrentLocalMatrixInGrid});//TODO should set from SelectBlock component
EntityManager.AddComponentData(e, new SelectedObjectComponent{Id = selectedBlock.BlockId});
EntityManager.RemoveComponent<SelectBlockInputComponent>(e);
Debug.Log("SelectBlockUserActionSystem");
})
.Run();
Im getting no error or something but want make sure that this is legal
I was under the impression you can't use burst on the main thread
but i could be wrong
You can use burst on the main thread, but WithBurst and WithStructuralChanges are mutually exclusive
i modify example. to be clear how my system look like
it was clear if unity throw some exception or warning if using WithBurst and WithStructuralChanges
If it works then it means that it's just silently disabling burst. You can't use the entity manager in bursted or non-main-thread jobs
You should be able to see for yourself in the menu ->Dots->Dots Compiler->Open Inspector
dam i wish we could attach native containers to entities
What's wrong with dynamic buffers
I neeed native streams
yea basicly just want to produce/consume messages
so bursted will be marked with attribute [BurstCompile] ?
Yes
would this be too much work for a component system?
-Update
--Calculate viewport on main thread;
--list of used spawnpoint indexes
--Entities.Foreach through all possible spawn points (there are a lot of these) parralel
--- if spawn point is on screen spawn entity
--- add index of spawnpoint to spawnpoint indexes list
-- if number of spawned entities is less than max entities
---Entities.Foreach through all possible spawn points (there are a lot of these) parralel
---- loop through entiteis that have already been sorted by distance and spawn them if the spawn point has not already been used
I'm not sure about the exact setup but you should minimize job scheduling as much as possible
It sounds like a lot of job scheduling in one frame
Unless I'm misreading
Oh okay, I thought you were scheduling in a loop
Then yeah, it seems fine to me. Profile it though, don't make any assumptions
Sometimes the dumbest things you could never think of turn out to be bottlenecks
just didnt' want to waste time writing code if it was absolutely too much work for a single system
Burst can generally tear through thousands of entities in a fraction of a millisecond, especially in parallel jobs
Depending on the work being done of course
woah
navmesh obstacles are really expensive
putting a navmeshobstacle on each agent dropped my framerate by half xd
i might stop trying to combine ecs and built in navmesh and just make it work with navmeshquery
How do you get a query in a parralel job?
Is there a HasSingleton equivalent for queries? There is GetSingleton like with SystemBase but no HasSingleton
CalculateEntityCount != 0 I think
I haven't looked at the source but I think !IsEmpty might be be better?
yeah, need to check out, probably it is
I guess thats IsEmptyIgnoreFilter now
either with 0.17 at least
good to know. should probably update. I am still on 0.14
Good time to upgrade π
im converting two rooms from scriptable objects to entities, and when i look in the entity debugger, the entity field references seems off. Idk why. the entities are created fine but their Entity field references are wrong
am i somehow using createadditionalentity wrong
weird i keep doublechecking and it seems right... i also stopped it from creating entities for rooms at coordinates it's already converted... so idk
hmm yeah something weird is going on
when i reference the assets everything is fine.. only when i use createadditionalentity do things get weird
createadditionalentity is returning the primary entity... weird
Is it not possible to create a new entity query in Entity.Foreach().ScheduleParralel()
I need to get some other entities in a system already querying different ones
create your queries in OnCreate, afaik its something you dont want to be doing constantly due to the performance of it
Then it tells me I can't access unsafe pointers in entities.foreach
InvalidOperationException: SpawnPeds_LambdaJob0.JobData.q.__impl uses unsafe Pointers which is not allowed. Unsafe Pointers can lead to crashes and no safety against race conditions can be provided.
@gusty comet are you saving the query into a local var in OnUpdate?
yes I am capturing
i dont think you can use a query directly in a job outside of when you are scheduling it
not really sure what youre trying to do though
I am looping through some entities
with entities.foreach
and I need to loop through a group of different ones
well not even loop through
prior to the job you can get a copy of the entities or component data with something like query.ToComponentDataArray(Allocator.whatever) || query.ToEntityArray
I need to figure out how many of the other entities exist
and then use the resulting nativearrays inside your jobs
alright thanks
relating to that: in Systembase you need to do the queries and put them in NativeArrays before Entities.ForEach correct? What if some query results may need to be had only in certain situations and others in other situation in the same ForEach? Is it possible to have some queries get results only if those certain conditions meet or do the yneed to be queried regardless if they are used or not?
Thats what I was trying to figure out
Don't think you can do it i n entities.foreach
The issue I am having now is
Ahhhh didn't get that from your writing sorry π
Woke up from a nap just right now and thought I'd chime in
So if you're querying to see how many things are spawned then spawn x amount if its less than a desired value
you wind up with extras
you need to plan in 'frame' delays
Is the difference neglible of having 6 (or more) queries and nativearrays compared to like only 2 that are needed?
I thinnk as long as you create the queries at init and not runtime it would be fine
idk tho
as the update cycle works like this:
OnUpdate, - all code runs, but any Jobs or ForEachs DONT run then (unless they are .run)
Then any Jobs/Foreachs run
For example I have a query for my characters hand position, but I only need it if I am going to spawn an item there. So if the system doesn't need to spawn there it still queries it but doesn't need it.
I think you're fine just creating the query at startup and not using it till its needed
could be wrong
I think so too so it shall stay that way. If it works, don't touch it π
Anyone has any experience from spawning entities from xml or json?
@celest wraith kinda, I was loading up data json files
not really spawning entities tho, i would create a prefab of the data type (eg unit, building) then load in all the simple values
dynamic stuff was much harder, as you have to add components with its actual type, cant really use refelection or anything fancy to create the components
Can you even create a new component from a name (string) and give it value? For example in pseudocode:
String compName = *string from json*
Var xComponent = *new Component from name*
Honestly no
was a pain
the trick was to reverse that adding of compoents
like this...
Type typeToAdd = FIND TYPE FROM JSON
typeToAdd.FIND STATIC METHOD
STATIC METHOD = (JSONDATA data, ENTITYMANAGER em, ENTITY e)
inside the static method you do entity manager add your type and set values
its not pure dynamic but its closeish
so you never dynamicly create Components
Can't you just use reflection?
yea but not to directly create a IComponent
Activator.CreateInstance ?
you can but the issue is with entity manager
what do you store the result from CreateInstance as?
a object would make it a reference type and the entitymanager add component wont accept that
generics are a compile time thing, not runtime/refelction
CreateInstace<Spawn>
but spawn is dynamic
The issue here is when you are trying to add components completly dynamicly, eg from a user list of string type names
oh
if you have a list of X types that you allow you can just make a switch
yup, but thats again just a nicer switch
then it wouldn't be dynamic to the user
well way better then a switch
but same core issue, not pure dynamic
my goal was to allow the users to add new IComponents, eg via dynamic c# code compiling
That should be possible though no?
yea the way i said earlier
you need a static method on the componet, that takes a entity manager, and the user has to code em.AddComponent<TheirType>()
this is where lua would come in handy
Yeah definately, I tried to use a bridge to the pawn language in c# and it was unusable
I had to create the abstract machine in a c++ app then use a memory map file to perform ipc to make it at all usable
I wound up abandoning that and just having the host app in c++ host a netcore dll
so would something like a behaviortree work good with ecs?
I've made thhem before but they rely so heavy on things we can't use in ecs like delegates and inheritance i don't see how it would work
OOo thats tough
pure ecs i would say no
but you should probably hybrid it somehow
have your tree object graph
that you construct and cache
then run like X number per frame that needs updating
not every one
Might just make it so
yep
however you should look at the new AI planner
again its very alpha
but its all DOTs under the hood
Have you tried out the animation package yet btw?
yea
it looks better now
and theres a specific sub fourm for it
but i usualy just leave my units in a T pose
π
is it a bad idea to have methods in your components?
I wouldn't put too much logic into functions on your components, but if it's just like converting the data a bit for use, I think it belongs on the component.
anyone want to venture a guess to why my breakpoint isn't being hit?
(top screenshot is in "CharacterControllerInitAndCleanupSystem")
if I make a breakpoint on the "Entities" line it hits it. just the query never returns anything. any ideas?
(bottom screenshot is the entire entity, there's nothing else on it)
@zenith wyvern sorry to bug you again but ur so smart and helpful π
I assume you have burst disabled when trying to debug.
Entities.ForEach is known to not trigger breakpoints. In my experience it seems rather random if breakpoints inside them actually trigger
so I've assumed it's okay to have multiple entity queries in the same system. is that okay? let me check burst....
ok turned off burst... it runs once but doesn't actually remove the component....
the entity is still there... what the heccc
is there like a special way to remove system components?
or does remove component not work if the entity is in the destruction process or something?
yeah I dunno. it just leaves the entities like this wtf
Entities
.WithNone<CharacterControllerComponentData>()
.ForEach((Entity e, ref CharacterControllerCollider collider) =>
{
collider.Collider.Dispose();
for (int i = 0; i < 10000; ++i)
{
ecb.RemoveComponent<CharacterControllerCollider>(e);
}
}).Run();``` i got nuthin
it wont work
@slim nebula are you sure the system is able to find your entity?
it does run once. I guess I should check the entity index/version...
wait no these are different entities wtf
Anyone have examples in tiny how to click and spawn game object. I have no idea where to start
I think I have some direction now. thanks guys
@light mason right click in project folder, create > input actions. Add things and generate. Create a variable of the generated type on a system. reference said variable in OnUpdate: if (InputSystem.inputMaster.Player.Use.ReadValue<float>() > 0) for example, then create an entity with EntityManager
I dunno if you need any special packages for it tho
how to check if entity has buffer from entitymanager?
@slim nebula ok thanks you let me try it out
@warped coral I'm pretty sure you just use HasComponent, but you can test it to be 100% sure
oh ok. i tried using hascomponentdata and didnt realize that only accepted icomponentdata
Do I need the new input system ?
uhh yeah I think what I"m using is the new input system. I dunno how to use the old one
I think in the options you need to have both enabled
I think there's still some backend unity junk that doesn't support the new stuff just yet
i forget what tho
Ok I will shoot from the hip and see what happens
cant have both input system enabled. Have to chose one
will unity be the best engine cuz of dots
there's no absolute best engine. More like one or two that better suits your needs, and that can change with each new project.
I don't think you can dispose inside burst
not really
Unity will absorb all other engines and become the Ur Engine
err well I disabled burst in the menu too
Hail the giga engine, well all say
so unity's plan was world domination all along
Yeah it will probably break of you enable burst I would think
Ok so tiny has Tiny.Input?
Whats the catch here
Is seem to just work
Wait ... does ECS have a pure dots input too?
No
Also Tiny input is kind of terrible compared to the new input system. I love tiny - or did before i hit a bug that killed my project. But the input system is just the bare minimum they could do. Which is fine, it's still early
All I need is click to create distort and connect
Also I don't think it's really ECS at all is it? You're just calling into a system
Iβm not sure for some reason to canβt find the system file
Never mind was in the wrong ide
Ok looks like it has all I need does all the basics
If I author entity in the editor how do I respawed that entity archetype. I want to build the library of different antitu and have a way to create many of a certain type in a system
Iβm not really clear on the workflow here
you create a prefab, then you drag it onto the field in the editor for your authoring component
then you can reference that prefab in code and instantiate it with entitymanager
Do you know where I can see an example
i learned it from here: https://www.youtube.com/watch?v=pk-C_h0WJZs
β
Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=pk-C_h0WJZs
Let's check out how we can build Game Object Prefabs and Convert them into Entity Prefabs that we can then Instantiate.
Unity DOTS / ECS Tutorials
https://www.youtube.com/playlist?list=PLzDRvYVwl53s40yP5RQXitbT--IRcHqba
Getting Started with ECS
https:/...
Ah thank you , man you guys deserve a beer or something

I don't drink sooooo... apple juice is fine for me
In that code monkey video he used static field, Iβm to so keen on that. Do I need library entity ?
I don't know about that video, but the samples give a very simple example of how to go from a prefab gameobject to a prefab entity https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/c13d4eb831d9794ac00d4f11f8209b50db7ef25b/ECSSamples/Assets/HelloCube/5. SpawnFromEntity
That example is basically how I do all my authoring
I guess what Iβm struggling with is whatβs the best way to store them for later using in a system
Like a library of trees to spawn
In my game I just store the entity prefabs on a component and attach it to my map
Ah awesome thank you going to read through this
Obligatory "I'm new here", but you typically only have one EntityManager per World, right? Can you access/render from multiple worlds at the same time? The reason I ask is that I want to make my tiles entities, because I want to play with dynamic terrain systems. It seems very foreign to have my tile "entities" lumped in with my entity "entities". I assume that is the standard solution, and then just handling it with components. I just don't expect there to be many or any overlapping systems between what will be run against the entity entities and the tile entities. Would it be beneficial or detrimental to create a second World, and a second EntityManager, to handle my tiles? Or am I an insane person.
I'm not sure what the benefit of having a separate world is, it seems like it would make it hard to read your terrain data from your normal world
I assumed I was overthinking it.
AFAIK worlds are generally meant to be completely self contained, typically the only interaction between them is to copy entities over from one to another
So they're good for staging entities and stuff. And netcode uses them to separate client and server logic
Thanks. The only reason I asked was because I had read something alluding to the benefit of multiple worlds in cases of rendering and netcode
But I'm inventing problems I don't need to solve so I'll just go do the obvious thing.
Using a separate world for rendering is interesting, I wouldn't know how to do it personally
A World owns both an EntityManager and a set of Systems. You can create as many World objects as you like. Commonly you can create a simulation World and a rendering or presentation World. - https://docs.unity3d.com/Packages/com.unity.entities@0.16/manual/world.html
Yeah but in order to render in the rendering world wouldn't you just have to copy over all your data from the sim world and re-interpret it for rendering?
You can see why I'm asking questions in here.
I can think of ways to do it but it's complicated (from what I know of communcating between worlds which isn't much) and I'm not sure what the gain is
Well right now it was a shiny engineering question to distract me from actually writing substantial code. And I need to start tinkering or I'm never going to learn anything.
@rugged lark yea you can
one benefit of using seperate world is that it has its own sync points so they don't have to wait on eachother
and if you're doing things like deterministic simulation for rollback you pretty much need seperate worlds
but other than that, most things you can do with seperate you can also do in a single world e.g. you can still use seperate 'logic' and 'render' entities in 1 world and things are a lot simpler
I'm just starting to mess with physics. As I understand it if I want to do an overlap test I get the CollisionWorld on the main thread, pass it in, and the overlap gives me indices in to the array of all dynamic bodies. Can I affect that list of bodies - like restrict it to a certain query of entities?
Using HasComponent/GetComponent/SetComponent for every entity in my overlap seems like it would be horribly slow
so from memory physics didnt really interact right with ECS
it still has Layers
and your meant to use layers (and layer masks) to define possible collisions and pass in target layers to the physics querys
it dosnt use any of your component types for any querys
kinda sucky i think, they could remove layers and use the compoent type index instead
Yeah my idea would be to grab an array of my components and pass it into the overlap job. But I'm not sure how to match up the indices from the overlap into my components array
Even using filters I would need to use HasComponent/SetComponent which I want to avoid
umm again all from old memory, you get back indexs to the bodys array, bodies array has a entity field somewhere
that will get you to the main entity
where you can do your own extra collision stuff
for me i found a collision job callback thing, that would take all collisions and turn it into a dynamic buffer
and i could query that buffer (with change filter) instead to handle collisions
This isn't for collision handling, but rather to just grab a group of entities in an area around eachother and affect velocity. It's for flow fields. And yeah I know I can get the entities from the bodies array but again I'm trying to avoid the random access if possible
hmm i see
i fell like no matter what with physics your gona have random access
goal would be to minimise it
maybe get a native array of entitys (overlaps) and batch add component to them?
that way your next system can quickly loop over them
depends on if you need to work with them all together or not
I need to affect every single entity based on the data of N entities in an area around it. I guess I could use some kind of spatial partition container and push into that from the overlap tests to be used in the next job
Would still need to do radius tests per bucket but it should reduce the work
If I understand it correctly anyways
Ehh but then I still have no way to translate from the dynamic bodies array to my components array
Unless I just make sure there are no bodies in existence that don't relate to my overlap test so the component array would match up to the bodies array, since they would use the same query...
Surely all the physics lords on here have some kind of solution
oh i really dont think the bodies array order would match your entities order
physics is this weird black box that kinda breaks ecs
i would fully expect it to do something really annoying like reorder the bodies array
This is the query that builds the bodies array:
DynamicEntityGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
typeof(PhysicsVelocity),
typeof(Translation),
typeof(Rotation)
},
None = new ComponentType[]
{
typeof(PhysicsExclude)
}
});
From the source
Annoying to make my own entities match up to it but not impossible
yea i remember messing with that
But yeah I guess I have no guarantee they don't shuffle it around, now that you mention it
i hacked it to not destory parents and childen
it was ruining the transforms and driving me crazy
also excludes you from updates
not a big deal but still
so bring it back to its core
you have a grid?? of entities and you need to do a overlap?
The entities themselves aren't on any kind of grid really. That's why I was hoping to use physics for this, to avoid having to build some kind of fancy spatial partitioning system myself
yea makes sense
Plus they are already physics entities so I figured why not use it if it's there already
I think I'll just try it out with HasComponent/SetComponent and see how slow it is. Maybe it will surprise me
No worries, I appreciate the advice
Oh, hahah, the hit data you get back from the overlap already includes position data, so that solves the problem right there
https://forum.unity.com/threads/entities-0-17-changelog.1020202/page-2#post-6774380 - doesn't sound like "enabled bits" are coming this year π
If only we could have some sort of roadmap
With them moving the Graphics packages into Core due to so many things relying on it. I wonder if they will be moving DOTS/Entities into core
Or something similar to Tiny, make it it's own "engine" entirely
pretty sure that's always been the plan - to move dots/ecs into core... I guess burst & jobs may be quite soon.. entities.. 202...5? π€
if it moves into core then would classic be replaced by dots?
classic? If you mean monobehaviours, they won't be going anywhere
shame...
How so? It's not like ECS is a solution for all problems, far from it
Anyone get a feeling for what the vibe is regarding DOTS within the Unity org? AFAIK it's always been the CTO's baby, is he still as bullish as ever now that he's seen what it looks like in practice?
This is a relatively recent answer from him regarding the direction of dots https://forum.unity.com/threads/state-of-ecs-dots.1044877/#post-6761749
thanks!
definitely still seems very bullish about DOTS
And CTO gets what CTO wants, so that's where things are gonna keep moving
Did the .NET Core DOTS server runtime end up happening? I'd love to use DOTS more extensively in my project, but my gameplay code has to run in the cloud for multiplayer reasons so I can't depend on the full runtime. My main gameplay assembly doesn't even link Unity .dll's at the moment.
Joachim mentioned ".NET Core based DOTS runtime later this year" in 2019 >_>
That's exactly what our game needs, and I can't find anything more recent about it.
Is that what you are looking for https://docs.unity3d.com/Packages/com.unity.tiny@0.23/manual/index.html ?
Somehow the more recent versions are missing the manual idk what's up with that
Not really. Project Tiny still includes a bunch of Unity stuff. What I'm looking for is the ability to deploy DOTS by itself in a barebones .NET Core environment.
Looks like it should be used by the NetCode project as soon as it's ready. https://docs.unity3d.com/Packages/com.unity.netcode@0.6/manual/client-server-worlds.html
References to the "server build" option haven't changed since mid 2019, though, so they're probably still deploying as a headless Unity server, not the full .NET Core experience that's planned.
How do you handle VFX with DOTS atm? I have several approaches but nothing feels quite right. I think it should be systems separate from the game logic. But should those systems create and destroy converted VFX objects? And how would they know when to spawn/destroy them without such a thing as an event?
I'm currently using a EffectCommandBuffer that supports playing sound or creating particle systems. Those command buffers are processed by a effect system which handles pooling, etc.
When creating a sound or particle system the command buffer returns me a handle to the effect which I can later use to check if the effect is still playing or to modify other stuff related to it.
This has worked pretty good for me for the past year
That sounds pretty solid. Is the EffectCommandBuffer an EntityBuffer or a custom thing you built yourself?
That's a custom thing
The logic and chaining of commands looks like the EntityCommandBuffer
Just with custom actions/commands
Thats a good starting point I guess. And how do you spawn the effects from the Effect system? Is it just a system running on Main Thread spawning GameObjects or do you convert the effects to DOTS somehow?
The system runs on the main thread and uses standard game objects
I also have a really old effect system that supports VFX graphs from the FPS sample...
sounds reasonable
I just took a look at the EntityCommandBuffer. Sadly its a lot more complicated that I anticipated π¬
@zenith wyvern Out of curiosity, why not a collision query or overlap query ?
What do you mean? I am doing an overlap query
No worries
My brain stopped at the part where you were looking for a spatial query
@pulsar jay https://pastie.io/doksqh.cs this might be useful as a reference
@north bay wow thats great. Thx π
Can someone explain how the category names filters work? I assumed this would map to (Actor == 1 << 0) (Wall == 1 << 1)
But if I print out the filter for this collider I get Wall: BelongsTo: 3, CollidesWith 4294967295
Basically if I'm writing a filter in code for an overlap test I need to know how to match against the filter I set in the editor
I figured it out. I had normal monobehaviour collider components attached to my gameobjects alongside my physics shape/physics body scripts. Apparently the conversion system accounts for both of these and creates a compound collider
So I was getting the weird filter from conversion combining the built in gameobject layers and my own custom layers
Very annoying to figure out
I remember reading something on the physics forum about exactly that issue
Yeah I just posted in a forum thread I found about it, hopefully they will add a warning message or something in the inspector
If I remember well they specify it in the docs that it's a really bad idea to have both legacy & new physics stuff
but yeah a warning in editor would be nice
Iβm a little stuck, I have a dynamic buffer on an entry, the buffer contains prefab entities
How do I Instanciate in entities for each
Should this not work
well if you want burst(which you do) then yeah
Ok let me do that , thank you
one thing you might want to check though is if instantiate inside a job is actually faster though
there's a slight possibility using a simple for loop may be faster(though maybe in later version now its not)
how to use multidimensional arrays with jobs? is there an alternative to flattening them?
Iβm testing GetWorldInputPosition in tiny.input but it always returns 0
from my exp, no. you have to flat them.
That method is a TranslateScreenToWorls(GetInputPosition())
oh ok, thanks
Wait it just returns 0 in translateToWS .. what am I missing here
You technically can. NativeArray<UnsafeList<UnsafeHashMap<int, UnsafeMultiHashMap<int, UnsafeArray<int>>>> works as unsafe arrays are implemented as a integer pointer. However, accessing this will wreck your cache access and murder performance. If you really need to and dont care about performance, you can use this. Well, not this deep of a hierarchy. I've used NativeArrays<UnsafeHashSet<int>> before in loading to get a true Multiple HashMap with unique keys (index) and values.
I was wondering referring to earlier to earlier discussion about spawning entities from xml, is it feasible to create a new world for creating entities from xml there and then instantiate them from there to the defaultworld? or is it better to have them straight in the default world?
@celest wraith yeah that's basically also what subscenes/conversion workflow does
that way you prevent sync points in one world affecting the other
Any up to date guides on how to use DOTS?
Hello friendo's! This library might be able to help you out in your DOTS adventures.
https://github.com/DennisCorvers/UnsafeCollections
old docs + overrides by changelog π
and Unity samples
I see. Is it relatively simple to make 1000 blocks with triggers, and they interact with the player etc. I know DOTS is preview, how does it work with materials and shaders?
@gusty comet what are the main differences with fholm's?
Extended API, fixes, performance, more collections
o nice
And the entire Native namespace models the collections after the .Net API
as in extensions for unity's native collections? or your own version of native collections
nvm just looked into it, they're wrappers for the unsafe versions right?
Yes, they are. Passable by value and strong typed
i'd try to avoid the naming conflict if you're targeting unity devs but other than that seems nice π
Cheers!
Any advice in rendering sprites with DOTS?
Yes relatively simple if you're familiar with the oriented data pattern. You can access materials through ECS Components, and use ShaderGraph for URP and HDRP
You gonna lack other basic Unity API stuff though, do your homework and check every DOTS package you need before committing for a real project. If it's for trying or learning, then go ahead right now, it's already fun (though a lot of frustrations with each update)
Cool. What about the 2d...project tiny...is that ready to go
I heard that was all ecs
has anyone had any luck using GetOrCreateUnmanagedSystem within a SystemBase ?
Yeah
because SystemRef is a ref struct it can only exist on the stack
so you just keep fetching it in OnUpdate()
ooooh... cool.. lemme give that a go - that rings a bell you already mentioned that actually
You can do like a ref getter but I haven't really looked into that haha π€
hmm.. what I actually want to do is get a reference to some NHMs. I want to reference those NHMs from both SystemBases and ISystemBases. I was thinking I could put the NHMs in an ISB then have an SB that OnCreate set it's NHMs to the ISB ones - then GetSystem<SB> or GetSystem<ISB> depending on whether I'm in managed or unmanged land. I have no idea if any of that makes sense
I get what you mean, I had a similar situation in wanting to a store a spatial map. So what I had was a pointer to an UnsafeHashMap in the ISB and I just grab the pointer in other ISBs.
struct SomeSystemA : ISystemBase {
public UnsafeHashMap<T, U>* Container;
...
}
struct SomeSystemB : ISystemBase {
public void OnUpdate(ref SystemState state) {
var refState = state.worldUnamanaged.GetorCreateUnmanagedSystem<V>();
unsafe {
UNsafeHashMap<T, U>* ptr = refState.Struct.Container; <- I just reference like so
}
}
}
dunno of any other ways, I just iterate π€
Awesome but any idea how I'd then be able to get e.g. Container from a SystemBase too?
pretty sure you can do it the same way
i think it's World.Unmanaged.GetOrCreateUnmanagedSystem<T>()
question:
is it possible to use Unity ECS for architectural reasons rather than what it's intended for?
yea I realise now I think the error I was getting may have been throwing me off .. going to experiment a little more, much appreciate the help
i.e. keep using monobehaviour stuff and classic physics
but also have the ability to use SystemBase to loop through monobehaviour components.
I could use entitas tbh, but I'm too damn lazy
i dont think there's a really easy way, I guess you can try to grab all the components in a IConvertGameObjectToEntity script and just do EntityManager.AddComponentObject(component)
what's the downside of ConvertAndInject?
you pay for the conversion cost on runtime generally, so it gets more expensive the more objects you need to convert during runtime iirc π€
but after that? would it equal to having 2 of the same object though?
so meaning more stuff to process
(jesus i'm drunk more processing power to process, wtf was that?)
I'm not sure what you mean by
would it equal to having 2 of the same object though?
well afaik, convert and inject basically has 2 version of the same object. 1 as an entity and 1 as go
Oh, does it? I haven't used convert and inject in a long time. I'm not too sure tbh
Huh as far as I know convert and inject only creates an entity that references the objects not create additional ones
imo you can use it just fine for looping through gameobjects, but you will always have that kind of duality that could make things a bit confusing if you need to dip into entities and back to gameobjects
How is one meant to handle NPC movement in NetCode? When the movement is simulated on the server only it's not smooth on the client, and it can't really be ghost simulated because the client doesn't own it.
Are you talking about the interpolation not being smooth?
Ish. LEt me get you a clip. I use destination type movement
I don't think we'll use entity specific components.
So in theory using SysBase for running the Updates of normal go's should work just fine along with classic physics
the confusing bit will be you will obviously need to rely on monobehaviours for their event stuff like OnTriggerEnter OnCollision, possibly fixedupdate etc so you sorta cant make a clean break and just use systems for logic
I don't know if it's visible on video
How are you handling the NPC movement? Are you just moving them on the server and the client only interpolates?
Hrmmm so I guess I need to understand how Entitas works huh
no idea how entitas works, i found it confusing π
yeah I find it confusing too
Well so far the NPC uses the same System as the player to acutally move, in the GhostSimulationSystemGroup. So I assume the client only interpolates yeah
The current interpolation time calculation is known to be pretty broken see this thread https://forum.unity.com/threads/netcode-prediction-jitter.985701/#post-6762562
Are you seeing small jitters in the movement or is more extreme?
Quite small. It's not much of a problem but I'd like it to be as smooth as client predicted movement
I made this for 0.5 which is a lot smoother https://pastie.io/uhnbtz.cs
Is there an alternative atm? Like maybe I can simulate its movement both on the server and client
I sadly do not have a version for 0.6 yet since I'm not using it
That's not something I would do
NPC movement in most games is just interpolation right?
You're saying it's NetCode's implementation that causes the jitter?
Yes I do
Okay then we can probably expect that to be fixed in the future? So I won't bother with it too much for now. THanks!
We are fighting since October to get attention on that problem...
Can I offer support somewhere? ^^
Probably not, they are aware of it but they are not giving it priority.
Ha okay
The snippet I've sent works pretty good for us tho
I don't know if I'm comfortable enough to use my own implementation of network time :/
I'll wait a bit and if I become desperate I'll look into it π
so I was right
Convert and Inject doesn't destroy the GO when the entity was made
fuck
It looks like you're using hybrid renderer too?
So it's going to convert that injected gameobject to be subjected to a hybrid renderer
Is there a way in tiny to get a world position with mouse click. Is this something I need to do with tiny physics ?
Is using non burst systems the best way to handle UI in DOTS?
@light mason if its a pure 2d game you can do some maths ( i dont know it) to get world pos
same maths as in normal 2d unity i would guess
but if its 3d then you would likely need to use physics to do a ray cast
@fluid kiln yea thats what i would do, often i wouldnt even have a entities foreach
eg for my selected units (rts) i would have a entityquery and use toEntityArray and component array to extract all the data and then send it to UI
it wasnt very optmized tho, i could probably have used change filters and run that system at a lower update frequency
Thanks I'll look into it!
i wasnt sure what to do about world UI tho
World UI? Wouldn't it remain GOs?
the 'selected' outline was a entity i would spawn and attach to each selected entity
but things like heath
yea it would likely need to be a GO, but if you selected like 1000 units,,, it would probably die from all that GO creating/linking/updating
this is gonna sound crazy
but would using hybrid component on the entity make it be affected by the classic physics?
Tiny camera question, so I donβt see a camera entity in the tiny3D example or a conversion, tryin got query it also doesnβt exists,
How is this working ?
Idk much about Unity's DOTS Physics system. But if they have a ConversionSystem which reads BoxCollider and adds a component, or if they read RigidBody and adds whatever physics body components to the entity, then yes it would be subjected
if they solely rely on IConvertGameObjectToEntity and you don't attach those authoring components to the GameObject - then no.
I don't plan on using DOTS physics though
yeah if you dont have the package installed, then it wouldn't be subjected
aaaaaaaaah.
hrmmmmmm...
so at best, I can probably make an authoring and hybrid the rigidbody...
weeeelp
so Hybrid RigidBody doesn't work out of the box
yeah - Hybrid Companion Objects are entity driven
other than Entitas
what other ECS architecture for Unity out there?
Unity ECS is literally in it's own world
and trying to mesh them is gonna give me lots of headaches
nice which one do you recommend me first diving into?
sebas is pretty active on the Svelto C# Framework Discord - so you can ask there for help.
I've honestly only found DefaultEcs today from a post by sebas in his discord server so I haven't looked at it. I've messed a bit with svelto, but haven't dived into it too deeply
so my bias is towards Svelto.ECS, but again can't say too much about it - he has some examples you can comb through via github