#archived-dots
1 messages · Page 153 of 1
Check also task manager
If the GPU isn't near 100% in any category, that is a sign of something not being right.
On the other hand, if it is 100% (somehow), then you have your answer.
Oh yeah task manager... I forgot about that
Oooooookay....
I'm just standing
not pressing anything
and my gpu went 100% on it's own
XD
wait... is there a delay with task manager though?
Shouldn't be a significant one, at least.
As in, should be sub-second.
hrmmmm
then... AAAAAAAAAh

for now I'll believe whatever fraps said.
and this is me moving spamming my directional keys
since the min didn't go to the 30 fps range
Fraps adds some overhead, but I don't think it uses the 3d-part of the GPU that much - it should mostly be using the video encode.
If you have a tool for that, you can check if the unity program actually changes between frames - it could very well be that your overall FPS is higher than the specific one of the game window
huh did anyone notice this before?
https://packages.unity.com/com.unity.timeline.dots
it also has a samples package(inside the package), just tested it and it works though animation spits out conversion warnings in the editor
Can you send a screenshot? Does it do anything clever or with queries etc?
How do I process only a few entities of a certain archetype every frame? (e.g. pause a job for a while akin to Thread.Sleep etc., or only iterate a limited number of entities, and resume next frame)
I would like to spread out some o(n²) processing loads, and I'd like some kind of rolling buffer system that just updates a couple hundred per frame, instead of tens of thousands of decisions.
I could do it with a shared component data, but that only works for one such "buffer" builder/consumer, and it is also an abuse of that system.
use a system just for it and keep your data inside the system as properties
stateful systems are really common
@warm panther
you can't stop jobs that you already scheduled, but you can spread your scheduling manually
Hmmm but some of the entities might get removed etc. But I'll think about it.
could you have just a counter that forces a job to ignore any work beyond a certain count?
Yeah and next frame? 🙂 And I'd still have to "return" for each entity I want to do no work for.
oh i thought this was somethign where you would destroy or remove them from the query
@safe lintel I'm guessing 0 docs for the timeline package?
@warm panther Throw all your entities into a native queue and then use a job to process instead of a ForEach?
Are unmanaged systems supported yet? I'm seeing alot of references to them in the core entities code
nope, at least its not released
hopfully soon
tho all it would give us is faster systems right?
also are generices completely not allowed in SystemBase?
its, but generics are not allowed in bursted jobs
and yeah, faster systems, at least 0.04 ms faster 😄
what about manual jobs? can they have generics?
idk, never tried it, you should search in forums
i mean.. burst is very important for ECS, so i never tried to schedule a job without it, except when on main thread
it works on Editor, it wont work in build
in Editor it works as JIT, while in build it works AOT
hmm
will make a test then
i think actual jobs should work
How do you manually Create systems?
Im trying to new up a group and add a bunch of systems to it
making group seems happy, i just have to call OnCreate before i start using the new group
but systems dont have a public OnCreate
what are unmanaged systems?
bursted systems
when Unity is calling your systems there are some checks being done, this is why systems can take 0.04-0.04 ms while real job takes 0.01 ms
so with bursted systems we will avoid that downtime
Is there an equivalent to "PostUpdateCommands" in SystemBase?
no, you should use command buffers now, or run in main thread/without burst and use EntityManager directly
Ok.
I now have a weird error.
InvalidProgramException: Invalid IL code in Jovian.Systems.Control.BindDummyManualAiming/Jovian.Systems.Control.<>c__DisplayClass_OnUpdate_LambdaJob0:OriginalLambdaBody (Unity.Entities.Entity,Jovian.Components.Focus&): IL_008d: endfinally
namespace Jovian.Systems.Control
{
public class BindDummyManualAiming : SystemBase
{
private EntityCommandBufferSystem _ecbs;
protected override void OnCreate()
{
base.OnCreate();
_ecbs = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
var batteries_and_guns = GetBufferFromEntity<EntityListElement>(true);
var ecb = _ecbs.CreateCommandBuffer();
Entities.WithAll<SingleTargeting>().ForEach(
(Entity entity, in Focus focus) =>
{
foreach (var battery in batteries_and_guns[focus.entity])
{
foreach (var gun in batteries_and_guns[battery.entity])
{
ecb.SetComponent(gun, new TargetProvider()
{
entity = entity
});
}
}
}
).Run();
}
}
}
Is this nesting invalid?
(the error occurs at runtime)
creeping suspicion is that it's the foreach...
Unity being Unity again.
Ok it works with for loops. This is a tad disgusting; I don't even have Burst enabled.
Interesting, does AddComponent not fail if the component is already there?
SetComponent fails in the case there's no such component.
(I like it, but I'd like to have all 3 options, really)
You have burst enabled. It enabled by default.
Ah you disabled it for whole project, yep then disabled.
```C:\Projects\protojovian\Assets\Jovian\Systems\Control\BindDummyManualAiming.cs(27,59): Burst error BC1037: The try construction (e.g foreach/using) is not supported
Yeah with Burst it rejects the construct.
hopefully they add that.
Yep it always was the thing with burst, only error was less user friendly 🙂
I submitted a bug report, without burst it should work.
OR throw an error.
Not at runtime, though.
That said, I really like SystemBase, it makes the boilerplate competitive with MonoBehaviours.
I think they should rename EntityCommandBuffer(System) to CommandBuffer(System), because they already are in namespace Unity.Entities 🙂
I program on a portrait screen and man, does ECS strain my line break and indentation discipline with its long identifiers, initializers, parameter lists, and lambdas.
Moar Questions 🙂
namespace Jovian.Systems.Weapons
{
public class PickTargetsFromProviders : SystemBase
{
//Aiming Entities observe TargetProviders as subjects and pick their favourite target
protected override void OnUpdate()
{
var targets = GetComponentDataFromEntity<SingleTargeting>(true);
var lists = GetBufferFromEntity<TargetListElement>(true);
Entities
.ForEach((ref Aim observer, in LocalToWorld localToWorld, in TargetProvider provider) =>
{
//Reset Aim positions...
observer.position = localToWorld.Position + localToWorld.Forward;
//Try to find targets and write fresh aim positions
//Trivial case.
var target = targets[provider.entity];
observer.position = target.position;
//List case
//var list = lists[owner.entity];
// ... then do some selection math...
}).ScheduleParallel();
}
}
}
This says "InvalidOperationException: <>c__DisplayClass_OnUpdate_LambdaJob0.JobData.targets is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type."
Targets is readonly. How do I properly declare it as such?
Figured it out, maybe: Entities.WithReadOnly(targets)
yep
Yes system works, now to figure out why my raycast system stopped hitting stuff since the Unity.physics update x.x
I think they should rename EntityCommandBuffer(System) to CommandBuffer(System), because they already are in namespace Unity.Entities 🙂
@warm panther naming is completely fine for ECB. Moreover they already have graphic CommandBuffer in core module.
Nah.
Then they should rename that to GraphicsCommandBuffer 😛
See? That's what namespaces are for.
Same naming even in different namespace inside same product - always terrible idea.
I maybe agree with GraphicCommandBuffer as now with entities it will be suitable.
Then... Commands or something. EntityCommandBufferSystem makes me reminisce my time as a Java developer
I mean, My System.TimeFactory.TimeProvider.Reminisce(DeveloperProvider.Java)
Anyway, I'll focus more on coding and less on ranting, I'm having a good time with ECS really.
Thanks for your kind help ^^
Hey, quick question, does Console.WriteLine() not work out of a system?
What's the most efficient way to get Entity's data fed to Monobehaviours ?
I'm doing a massive army thing, and each unit must play animation/sound/particle/whatever depending on what they are currently doing.
My bottleneck (by a large margin) is the various GetComponentData I need to extract just to read what's the unit current status.
Is there some much faster way to exchange data between what's happenning in Entity world and apply it to Monobehaviour world ?
how would you go about doing non-singleton inventory in dots ?
- from items that are scriptable objects
wouldn't it need some codegen of some kind ? :/
@scenic oracle maybe .WithChangedFilter() would help
Didn't knew about that one. Will look into it, although google doesn't seem to have much about it.
Oh sorry, its WithChangeFilter, not Changed with a D
Even so theres not much about it, even in the api docs
I think conventional wisdom used to be, if its not documented by Unity, its kind of internal and we're not supposed to use it
ECS is kind of an exception to that of course
Yeah, I really wish there was some proper doc for ECS.
Especially since they change stuff constantly so the example you find on the net tend to be massively obsolete ...
I have a conspiracy theory they are keeping ECS hard to learn for now, so they only hear from devs with a minimum level of proficiency
and they are not wasting their time on people trying to debug their first Hello World but using ECS
Wait, .WithChangeFilter is something you can only slap on your Entities.ForEach.
There is a way to use that inside a Monobehavior ?
'cause that's where I need to read the data to apply the proper response to my Animator/AudioSource/etc.
Your MonoBehaviours can access EntityManager and make calls I believe
I assumed you were working from Entities to Monobehaviours
How are you currently getting your entity data to put into monos?
My approach would be, create a SystemBase that schedules Entities.ForEach queries that use WithChangeFilter, so whenever an entity moves (or whatever changes), the query picks it up, uses EntityManager.GetComponentObject() to get the monobehaviour, and set the new data
... I was probably doing this the super wrong way then.
My current setup for all my "GameObject System", is to keep a list of all the Entity that will be concerned (grabbing them during the conversion phase), and then just do a regular loop inside a Monobehavior on that, calling GetComponentData for each one to get my data.
That sounds like it would work too
Unless each unit is a gameobject with the monobehaviour, and the monobehaviour loops through ALL entities to find the matching one?
It does, but it's super slow due to the GCD.
I suppose Monobehaviour.Update() is on the main thread so it could be that
If there are like 1000s of GCD per frame
3000s actually. 1000 units, with around 3 different components I need to extract for everything >_<
Oh yeah that could maybe be too many
There is also something called liek a GameObjectCompanionSystem that I think automatically propagates changes in ECS space into a managed component, maybe
Is it a DOD-way of approach to have multiple entities refer their data from a dynamic buffer that is being held by 1 entity? Sort of like having a look up table.
@ocean tundra yeah no docs(just the package manager template :D) but there are a few samples. it seems a bit crash happy and anim package gives warnings in editor but it works
ive honestly never used timeline so i really cant tell how far along this is or even how to use it 🙃 i should probably have learned it by now..
@deft stump both blobasset plus looking up some entity work fine
tho when reading data from global-ish entities like that, make sure you grab the component data outside of the loop/job or similar
GetComponentDataFromEntity() is quite expensive to call
okay...
so am I doing this right?
I want to set the stuff I need first in the inspector then convert it to a blobasset.
looks right
could be better?
can't really think of any way for it to be better, it's been a while since I used blob assets extensively 🤔
Anyone know if it's possible to execute ICollisionEventsJob in parallel somehow ?
Or if anyone has any idea how to solve dependencies for <>c__DisplayClass_OnUpdate_LambdaJob0.JobData.PhysicsWorld.CollisionWorld.m_Bodies.
I have several jobs that apparently use it, and I can't find a way to make all of them happy outside of having most them use .Run() - and I really need all of them to use .ScheduleParallel for performance reason. At best I can manage to get one in parallel without everything exploding, but the docs about dependency doesn't really give any examples to figure what I need to do to have everything work as expected.
Is there still no way to do NativeArray inside of NativeHashMap?
or nativehashmap & unsafearray
@scenic oracle you have to add to EndFramePhysicSystem's input dependencies, i think it should be .AddToInputDependency()
I can't find anything about either (well EFPS has a small article confirming that it exist, but that's it), neither on Google nor in Unity's ECS/Dots samples.
Do you have any examples about that ?
I think it's called AddInputDependency and was added in the latest version
Before that you had a List to which you could add your handles
how did you guys learn how to implement save/load in DOTS? info seems scarce
@onyx mist yea save load is annoying
@onyx mist Heres my save bit
object[] clientReferenceObjects;
NativeArray<EntityRemapUtility.EntityRemapInfo> remapArray =
world.EntityManager.CreateEntityRemapArray(Allocator.Temp);
using (var clientWriter = new StreamBinaryWriter(worldFilePath))
{
SerializeUtility.SerializeWorld(world.EntityManager, clientWriter,
out clientReferenceObjects, remapArray);
}
the issue is clientReferenceObjects will contain a bunch of Unity.Objects, things like Mesh's and materials
also entity names are not saved, as they dont exist at runtime, so i save those cause they make debugging WAYYY easier
var allEntityies = world.EntityManager.GetAllEntities(Allocator.Temp);
List<EntityName> entityNames = new List<EntityName>();
foreach (var entity in allEntityies)
{
var targetEntity = EntityRemapUtility.RemapEntity(ref remapArray, entity);
if (targetEntity != Entity.Null)
entityNames.Add(new EntityName()
{
Entity = targetEntity,
Name = world.EntityManager.GetName(entity)
});
}
since blob assets are allocated. I also need to dispose them right?
where do I dispose them gracefully?
i guess if you can tell when your done with them just call dispose wherever
but otherwise im not sure
theres that blob asset store if your converting at runtime
you can dispose that on game quit or something
blobs allocated during conversion belong to the scene their in, no need to delete them manually if you don't need to.
Not sure about ones made purely at runtime
So if I use the GameObjectConversionSystem to build my blob. It's fine if I dont dipose of them?
Ehh, just try - you should get a warning if you don't dispose when you should?
but it's persistent. I get the feeling that it wont throw me a warning because of it
Oh... it does throw me an error when i play it again.
I have asked about net code in #archived-networking but this could be a better place to ser my question because of the dots!
Hello guys im trying to figure how can i connect to my server build from a client
I followed the manual of NetCode, but i ca get it working using my game as client and server,
What i want to do is to have a server build so connect from different clients,
but i am not able to figure how to do that
Also the networkEndPoint let you et the port but not a custom IPV4 Address, so i will not be able to set my server in a custom ip
the manual doesnt explain anything about server builds
just that can be done!
what i just want to do is to be able to move a cube throug a client that connects to the server, and be able to connect other clients to it and each of them move a cube
What is the performance overhead of scheduling a job via the Run() function?
is there a way to use ecb on editor mode ?
How much time does it take between calling Run() and having the job's burst code to start executing?
from my testing... scheduling takes 0.10ms than Run
on run. my systems run around 0.08ms.
on job. it runs on 0.18ms.
is there a way to use ecb on editor mode ?
@undone torrent someone knows ?
entity command buffer in editor?
yep
not that I know of
stupid question, but how the f*** do i get a mesh from code only working?
Entity bla2 = entityManager.CreateEntity(typeof(Translation), typeof(RenderBounds), typeof(RenderMesh));
RenderMesh rm = new RenderMesh();
rm.mesh = new Mesh();
rm.mesh.vertices = new Vector3[] { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 0) };
rm.mesh.triangles = new int[] { 0, 1, 2 };
rm.mesh.RecalculateNormals();
//rm.mesh.subMeshCount = 1;
//rm.subMesh = 1;
//rm.layer = 1;
entityManager.AddSharedComponentData(bla2, rm);
the entity is there with the RenderMesh component, but bounds and mesh are not set or visible
Do you need localtoworld or some other extra component?
Have you checked which components the render system uses?
i have plugged localtoworld in also
and i dunno where to check which components are used/needed
Should be in the system list in entity debugger
halelulja
i got i
i dislike the random interactions in ecs
for meshes to render, you need the LocalToWorld (as stated int the wiki), but you also need a Translation
as otherwise LocalToWorld doesnt calculate its values
argh... I'm so confused.
How do I go about setting stuff in the inspector first and then convert that into a blobasset?
Should I go scriptable objects on this one?
What are you trying to achieve? Basically a prefab but in pure DOTS?
are you asking me Hod?
you could use authoring components
I'm trying though... and I'm following the example from the unity's github... but ugh...
mfragger


what what?
Couldn't not do this, of course.
please suggest better titles and make me feel like a fool for not thinking of them.
Yes, I was referring to you, mfragger. Yours were the most recent question.
Ok, my nerves....
if i comment that one line in, the RenderMesh isnt setup. Can somebody explain this to me? I cannot add Component and sahred component Data to one entity,?
Entity bla = entityManager.CreateEntity(typeof(LocalToWorld), typeof(Translation), typeof(RenderBounds), typeof(RenderMesh));
vd = new VoxelData() { Values = new NativeArray<float>(100, Allocator.Persistent) };
// entityManager.AddComponentData(bla, vd);
entityManager.SetSharedComponentData(bla, new RenderMesh {
mesh = mesh1,
material = mat1,
castShadows = ShadowCastingMode.On
});
Well no. I dont want a prefab in pure dots.
here's the high level:
I want to set a list of stuff i want in the inspector, preferably in my spawner GO that's about to be converted into an entity.
then convert that list of stuff into a blob asset.
"List of stuff" being...?
Arbitrary data? Components? Settings for known components?
a struct of data.
simon, are you saying that it if you uncomment the line, it stops working?
That does sound very strange. Have you tried creating the entity with the ICD and using set+set instead?
When uncommenting that line, The RenderMesh has no mesh setup etc. and doesnt render
not sure what you are telling me with the second part of the sentence
simon:
Entity bla = entityManager.CreateEntity(typeof(LocalToWorld), typeof(Translation), typeof(RenderBounds), typeof(RenderMesh), typeof(VoxelData));
//setup vd
entityManager.SetSharedComponentData(bla, vd);
entityManager.SetSharedComponentData(bla, new RenderMesh /*...*/);
mfragger, if its on a GO, then you should be able to (1)use a MB implementing IConvertGameObjectToEntity. That gives you full MB inspector features (including editor script if needed).
(2)In the convert you should be able to convert your data to blobasset as usual.
Am I correct in understanding that your issue lies in step 2?
vd is not a shared Component, and set shared Component Data also doesnt work with nullables
Ahh, VoxelData is a class ICD?
yes
Hmm, that might be the cause, but I have no clue why it would do that
The docs suggests using class ICDs is primarily for "bridging the gap" when moving from GOs, so in my own project I decided to go with a DynamicBuffer instead of that.
Not that that solves your issue 🙁
It's a possibility at least.
yea , i want the class cause it only stores a native array
my issue lies in step 2.
So you're suggesting in the convert method, i Just do this:
public void Convert(/*API stuff*/)
{
BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp);
//The rest of the blob making process...
}
BlobAssetReference might work? It's a helper for BlobBuilder as far as I understand it
Create a blob asset using a BlobBuilder or by deserializing a serialized blob asset
https://docs.unity3d.com/Packages/com.unity.entities@0.11/api/Unity.Entities.BlobAssetReference-1.html
var blobAssetReference = BlobAssetReference.Create<YourStruct>(yourStruct);
Out of curiosity, did you get builder to work, or did ya use the helper?
I used the helper you gave me
well not errors though.
Imma see if I can read data from it
now this becomes more and more akward
Entity bla = entityManager.CreateEntity(typeof(LocalToWorld), typeof(Translation), typeof(RenderBounds), typeof(RenderMesh), typeof(VoxelData));
vd = new VoxelData() { Values = new NativeArray<float>(100, Allocator.Persistent),test = 1 };
entityManager.SetComponentData(bla, vd);
mesh = new Mesh();
mesh.vertices = new Vector3[] { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 0) };
mesh.triangles = new int[] { 2, 1, 0 };
mesh.RecalculateNormals();
entityManager.SetSharedComponentData(bla, new RenderMesh() {
mesh = mesh,
material = mat1
});
this works!
setting the mesh by hand isntead of using a field and assigning one
Welp
this is beyond determinism
If nothing else you probably want to make an archetype to clean up the top part a bit...
The setting is a mess though
Well, at least progress was made
i need beer now
Whenever I get a day like that, the moment I verify it work I do the mental equivalent of flapping face down on a bed.
Whenver you try something new which has to fix your problem but doesnt, it feels like a mini heart attack and i feel the urge to slam my hand through the desktop
i will die eraly on a heart attack, im sure
The thing is, i dunno what i just learned Nicolas
why the fuck does it not work with a default mesh, but with a custom?
whats the goddamn relation between sharedcomponent data and an class icd
I haven't read the full context, but my approach is usually to make a prefab, convert it (live link mode often sufficient) and make sure i generate the same components from code.
mfragger, the not disposed error or something else?
You need to either dispose or save the blobreference
I suspect you get that error when it gets garbage collected
Just to be clear...
the Authoring Component gets destroyed because of the convert and destory when converting to entities right?
If you only want to use the blobasset in the method you make it, just plop "using" in front of the variable like using var = new SomeThing(); and it will dispose at the end of the method.
It's shorthand for "make a using block for the rest of this scope, but without the extra indentation
void SomeMethod(){
using var blobAssetReference = BlobAssetReference.Create<YourStruct>(yourStruct);
//other stuff
//blobAssetReference is automatically disposed here
}
//Equivalent to:
void SomeMethod(){
using (var blobAssetReference = BlobAssetReference.Create<YourStruct>(yourStruct)) {
//Unncessary extra indentation
//other stuff
//blobAssetReference is automatically disposed here
}
}
How long should it live?
Just for a method, or for however long the map/scene/whatever exists?
how long the scene exists
when I mean traditional way I mean this btw:
public class SpawnBulletDataBufferAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public List<SpawnData> spawnDataList;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
BlobAssetReference<SpawnDataBlobAsset> spawnBlobRef;
using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
{
ref SpawnDataBlobAsset spawnBlob = ref blobBuilder.ConstructRoot<SpawnDataBlobAsset>();
BlobBuilderArray<SpawnData> spawnArr = blobBuilder.Allocate(ref spawnBlob.spawnDataArray, 1);
spawnArr[0] = new SpawnData { minRotation = 10 };
spawnBlobRef = blobBuilder.CreateBlobAssetReference<SpawnDataBlobAsset>(Allocator.Persistent);
}
dstManager.AddComponentData(entity, new SpawnerData
{
spawnDataBlob = spawnBlobRef,
index = 0
});
}
}
Ah, so using the builder manually with extra boilerplate on top
Does it "belong" to a system (only used in particular systems?) If so, store it there, somehow.
I suggest not using static
Use dstManager.World.GetOrCreateSystem<YourSystem>() and have a non-static field or method to register it
And of course you just dispose it in the system's OnDestroy
systemVariable?.Dispose()
the operand ? cannot be applied.
so I tried not using that...
run and exit... And it says the BlobReference is null

manually check if it's null then
There's a class called BlobAssetStore.
It sounds like it's for meant for the editor, livelink, and the conversion pipeline specifically. Haven't touched it, though.
https://docs.unity3d.com/Packages/com.unity.entities@0.11/api/Unity.Entities.BlobAssetStore.html
I need some help:
i have few units - entities with unit tag
and i have few "task" entities like walk, eat, say those tasks have a reference unit that has to do that Entity TaskTarget , so when i want unit to do something i'm constructing a task entity that has a link to unit and task system reacts on it, animates unit way i need, and when done task is removed by task system
so my units can walk, eat and talk at the same time, but the problem is that units can't do two similar tasks at the same time, unit can't walk to two destinations at the same time, eat something when already eating, or say something when already speaking... so each time new task is assigned i need to check if task of the similar type already assigned to the similar target, and depending on that check to cancel previous task or skip adding new duplicate before previous is finished
so the question is: what is the right way to do that check DOD way?
@dry dune So I made a 'job/task' system for some of my units
A unit has a TastTaker component that says what tasks they can do
and a HasCurrentTask/No Tasks components
Then theres tasks in the world that my unit looks for and takes if they have the NoTask component
A task is a bunch of steps, so theres a walk to task step that moves my unit then they move on to the next step
But I dont have units that can do more then 1 task at a time
my inital design was full of generics for each job type, but system base destroyed all that
my next design (not done yet) will likly use bit fields to mark job types ect
yes when there is only one task possible at a time it sounds simple, but in my case i need to allow parallel tasks if all of them have different types, also i need to store that tasks on separate entity not on unit, because those tasks may be inactive (paused, scheduled for later)
a task category enum flag might work
i think your unit should have a list of tasks they are doing
and when you add/remove to that list you update check the flag
my inital design was full of generics for each job type, but system base destroyed all that
you still can have generic jobs in SystemBase, but you need to do it using IJobChunk
if its already set error you cant do that
Oooo I need to dig deeper into IJobChunk, thats also the fastest way to loop over entities right?
yes foreach is converted to IJobChunk under the hud
i think your unit should have a list of tasks they are doing
and when you add/remove to that list you update check the flag
yes i was thinking about it,
another option I'm considering is a centralized tracker of all active tasks with a possibility to look for active tasks by target/type pair
I wouldnt do a centralized
i was thinking of putting more data on my fog of war tile entities
so they could have a list of jobs within that tile
so that makes the search for new job bit faster as i can just check nearby jobs
but I'm not yet sure how to implement that centralized tracker way it'll be possible to use it in a job (i'm scheduling tasks creation from a jobs)
if you are going to centralize things, first make it a stuct, and only use more stucts and native collections
always pass it as ref
and i think you will need to store it on a system not a entity
yes, sure it'll be stored on a system, and repopulated on game load
public class SpawnBulletDataBufferAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
//public List<SpawnData> spawnDataList;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
BlobAssetReference<SpawnDataBlobAsset> something;
using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
{
ref SpawnDataBlobAsset spawnBlob = ref blobBuilder.ConstructRoot<SpawnDataBlobAsset>();
BlobBuilderArray<SpawnData> spawnArr = blobBuilder.Allocate(ref spawnBlob.spawnDataArray, 1);
spawnArr[0] = new SpawnData { minRotation = 10 };
something = blobBuilder.CreateBlobAssetReference<SpawnDataBlobAsset>(Allocator.Persistent);
}
dstManager.World.GetOrCreateSystem<BulletSpawnSystem>().spawnDataBlobRef = something;
dstManager.AddComponentData(entity, new SpawnerData
{
spawnDataBlob = something,
index = 0
});
}
}

I'm still gettng the native not disposed error!
okay wait what?
I just dispose the blob at OnStopRunning. and it'll work fine

Okay Finally... It works now!
Has anyone dug into the performance penalty of calling methods from a bursted IJobChunk?
I just cleaned up the Execute(..) of a IJobChunk by extracting a few methods and now I'm paranoid that there might be a performance impact 🙀
i dont think so, as long as they follow the burst rules
"burst rules"?
you can try putting the aggressive inline attribute on it
like structs only
native containers
that stuff
😛
no clue
but i see unity doing it
so i copy
and i would guess they profiled it
yeah in the math lib only though, right?
so referencing the blob in an ICD seems more "safer" than passing the blob's ref to a system.
Ability System Update, now with Area Of Effect :)
Propagates all effects of the ability/projectile to a radius around the cast/impact location 🔥
Now I have to merge that all back into my own game (or/and turn it into a unity package) 🤔
I fucking love ECS when it all works 🙂
does anyone know if or when the Hybrid Render will support MeshRenderer Priority? I really need it for controling the sorting of individual transparent meshes that are ontop of one another.
and in the mean-time, is there another way of doing it or would I have to write my own custom shader?
Sounds to me like a shader-thing, so the shader would need to support it. If GO rendering has it by default (ie. with no packages that affect rendering), I'd expect the hybrid renderer to support it as well, though...
GO rendering does support it
it's an SRP thing
in my case, HDRP
There are two possibilities. There's a Shader Property that lives on the material and a Renderer property.
Unfortunately the Shader Property cannot be adjusted in ShaderGraph, which leads me to believe it doesn't support instancing for some reason. https://cdn.discordapp.com/attachments/497874081329184799/724501523698286612/unknown.png
As you can see, it's not exposed, so I can't actually do anything with it with ECS as far as I know.
at least not with this experimental Hybrid Renderer V2 feature which allows me to set material properties without breaking the chunk system
yo, converting vfx graph to entities works 
ah, dang
yo, converting vfx graph to entities works :Yay:
@deft stump are you using hybrid component with an authoring component? Or just inside a prefab?
no. I just Convert to Entity it
I need some tips when working multi threaded.
Is there a way to have a system go through a players location, add coordinates to a list and then loop through that list and fill in which coordinates are missing?
I'm basically trying to make a world chunk spawning system which will work in a fully DOTS manner and only care about players position and the viewing distance for said player.
I'm afraid that if I would try to have lists of spawned chunks and change said list it would work badly with multi threaded code. So how would I best store this list of already spawned chunks?
Hi, first post here.
I'm trying to instantiate one player per connected device for local multiplayer. So I want to instantiate player based on Prefab. It works, but when I disable Burst Compiling, I get a lot of error comming from the BlobAsset. Does somebody know the right way to use ConvertGameObjectHierarchy ?
foreach(var item in devices)
{
//Entity e = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity();
//GameObjectConversionSettings settings = new GameObjectConversionSettings();
var blob = new BlobAssetStore();
var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blob);
Debug.Log(settings.BlobAssetStore);
var e = GameObjectConversionUtility.ConvertGameObjectHierarchy(playerPrefab, settings);
DeviceType type = item is Gamepad ? DeviceType.GAMEPAD : DeviceType.KEYBOARD;
World.DefaultGameObjectInjectionWorld.EntityManager.SetComponentData(e, new InputComponent
{
InputID = item.deviceId,
Device = type
});
var player = World.DefaultGameObjectInjectionWorld.EntityManager.Instantiate(e);
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(e);
blob.Dispose();
}```
I don't understand what I have to do with the blobasset
I have lot's of random crash too, is the package instable? I'm using the last version with Unity 2019.4.1. LTS. I did'nt worked with ECS since January, and it looks more instable now. Is it my code or does the package is currently in an instable state?
I think I'm pushing what I can do with my system
@deft stump same for me. I'm instantiating too many prefabs in a single frame occasionally. Need to figure out how to use the batched calls with "unknown" content.
@spark glade oh you're spawning too much stuff in a single frame too. XD.
and what do you mean batch calls?
Ah I see... Batch calling ECB...
@spark glade hook me up if you got that working.
I'm thinking queuing up a few jobs. One to group by "prefab id", one to allocate, one to instantiate, one to prepare component data, one to clean up. Or maybe just shove it all into one job.
Might actually use EntityManager directly, because I'm not sure if ECB does have batch methods. 🧐
My alternative is to just jitter the cooldowns of my units by a frame or two, so that the archers just don't all shoot in the very same frame 🙃
When ECS gives you lemons, make them a feature 😏
for me I shoved the instantiate and setting the ICD, since the ICD is already pre-added, into one job.
but wow, instantiating 1 stuff, setting their data, then repeat that 100 times is a huge block of an operation
I'm looking into ExclusiveEntityTransaction for just my Instantiation.
Isn't the whole reason you use systems so that you should not do it within a single frame?
you mean my instantiation system?
well, DOTS systems in general
I dont suppose when you are instantiating/setting data you are having to wait for some resources access? Like maybe reading from disk or unpacking an asset?
no.
the prefab is already an entity.
I just need to refer to it when I want to instantiate it to the world.
Isn't the whole reason you use systems so that you should not do it within a single frame?
@cursive cosmos it depends though... if it's a very large calculation then yes you want to spread it on multiple frames.
but for me, it's a bullet hell game. I need lots of stuff on that frame the moment I need them.
Plus with EM being the thing under ECB's hood, I'll eventually have to go back to the main thread.

Wait, so what you need is to not instantiate them, you need to move them, no?
You need a buffer of already spawned things that you instead move 😄
Didn't you say you had a problem spawning these bullets into the view every frame?
Yes. The problem is it's a giant blocking operation on the main thread.
Wouldn't it be better utilizing object pooling instead then and let the system only handle the moving of said objects?
I have a separate system that handles the movement.
My instantiation system just spawns the stuff and sets their ICD. It doesn't move them.
okay, but does it spawn stuff mid game?
As in instantiate the entities?
during OnUpdate? Yes
uff, that's rough though, you should probably try object pooling.
should work just the same, since instantiating the entities might be way heavier than just keeping most of them on screen in a deactivated state
worth a try at least if you really want a shit ton of objects on screen
I do want a shit ton of objects... It's honestly not a bad idea.
I used it for one of those block breaker games that had a ton of balls spazzing around on the screen, worked quite well performance wise
when my bullet reaches it's end-of-life... I just transport it back to the spawn point.
yep, hide it out of line of sight and deactivate any animation or even any visual aspect of it
I'll also stop the spawner system from spawning too once the first bullet reaches the end-of-life

Just to say... pooling isn't much of a thing in pure dots (can try and track down Joachim's post on the forums if interested). You should probably only think about pooling if you have a bunch of managed components like pfx etc.
on a desktop you can instantiate in the order of 1 mil pure ecs prefabs in 1ms I believe
that's also what i thought.
since the prefab is already in memory.
I can just create copies of that prefab
yes... though you want to be using the batch methods wherever possible
.Instantiate(nativearray) is many times faster than N times Instantiate(prefab)
so I'll have to EM it rather than use ECB to instantiate
yea - which I don't think should cause you any issues?
🙂 yea, know that feeling
oooh, didn't know about the batch methods 😮
So really what I should be doing is putting all my entities in a native array after creating them and instantiating them in that manner
But you are making a sync point with that method
For me. Since the movement sys is so efficient, it dont really mind syncing.
you pass an empty array to instantiate with the capacity of the number of entities you want to instantiate- it then does a batch memcopy afaik and sets that array to point to that block - it really is very fast
what is the diference beetween WithNativeDisableContainerSafetyRestriction(myvar) and WithNativeDisableParallelForRestriction(myvar)
i understand disableparallel but i dont know what is new on WithNativeDisableContainerSafetyRestriction(myvar)
you pass an empty array to instantiate with the capacity of the number of entities you want to instantiate- it then does a batch memcopy afaik and sets that array to point to that block - it really is very fast
@amber flicker That's only on EntityManager though, isn't it?
My issue is that I have a list of mixed prefab entities to be instantiated in one frame. [EnityA, EnityA, EnityB, EnityC, EnityA, ...]
Does it make sense to have a bursted/parallel job to group these, then a WithStructuralChanges job to use the batched entitymanager methods to instantiate the respective arrays and then another job to set the respective component data?
Can someone explain me why if the only systems accessing the buffer, are readonly, it is marked as changed with the withChangeFilter? Am I missing something, or what is wrong with this?
@foggy tree So WithChangeFilter applies to the whole chunk
not just that 1 entity
so that entity is probably fine, buffer isnt changing
but another entity in that chunk is having its buffer modified
@foggy tree GetBufferFromEntity(ReadOnly) not affect version bumping for chunk, it's only for safety checks. Accessing indexer for BufferFromEntity works different in comparison with ComponentDataFromEntity. It bumping change version even if you just access buffer, as under hood it uses (BufferHeader*)m_EntityComponentStore->GetComponentDataWithTypeRW which in turn uses ChunkDataUtility.GetComponentDataWithTypeRW which in turn bump change version chunk->SetChangeVersion. in other words - just accessing buffer from BufferFromEntity bumps chunk version always. ComponentDataFromEntity works different as it bumps chunk version only in setter. And BufferFromEntity itself haven't setter at all.
There is just 1 entity :/ @ocean tundra
@storm ravine so what options do I have to read a buffer randomly without triggering withchangefilter?
Oh dam I didnt know that
@foggy tree with BufferFromEntity - no way
that must be a bug/oversight?
This is not bug, this is how it implemented currently and will be improved
Well, I wasn’t expecting this behavior. I did multiple systems thinking this wouldn’t happen 😦
@storm ravine thanks. I’m glad I discovered this and found your help before relying too much on this
@ocean tundra also thank you
If you don't want change your logic and continue to use BufferFromEntity, as simple dirty workaround you can have simple ICD with bool\byte field and use ComponentDataFromEntity setter when you want trigger change on chunk with that buffer type entity and use WithChangeFilter on that type instead of buffer.
Yes, that’s exactly what I’m going to do for now. Thanks a lot
Also, what purpose of your logic with change filter on buffer in your case (just in abstract description)? Explain your case, as maybe it require different logic.
Is just an inventory, and the UI just re draw the buffer if something is modified.
But as you said, with a component for knowing for any changes can work, also I can put more data telling me “how “ it changed
Also need chage filter on buffer to calculate weight and volume of the content
Yep in that case ICD workaround will be fine
Also keep in mind when you destroying entities\removing components it wouldn't bump ChangeVersion on chunks
I wonder if ChunkUtility.GetComponentDataWithTypeRO would work in getting a buffer from BufferFromEntity without changing the version 🤔
Also keep in mind when you destroying entities\removing components it wouldn't bump ChangeVersion on chunks
@storm ravine I'll do it, thanks
I wonder if
ChunkUtility.GetComponentDataWithTypeROwould work in getting a buffer fromBufferFromEntitywithout changing the version 🤔
@coarse turtle problem here not in GetComponentDataWithTypeRO \GetComponentDataWithTypeRW itself as difference is onlychunk->SetChangeVersionbetween them. Problem is howDynamicBuffers implemented in chunk layout currently. ByBufferFromEntityyou gettingBufferHeader*pointer and it's not direct data access in chunk and only used for constructingDynamicBufferinitial memory offset which as result gives you data like native array (in simple words) which is exact data,ComponentDataFromEntityin opposite give you straight reference to exact memory where final data accessed and you can handle it directly in getter setter by just simple reading writing from\to this memory. And after constructing DynamicBufferin current implementationyou can't guarantee that you access it only for reading (this is what their comment mean in this case// TODO(dep): We don't really have a way to mark the native array as read only.) and this is why it RW by default and as result bumping chunk version. But again it's just current implementation and TODO allude changes in that area.
o cool - yea that would make sense
And WithChangeFilter still usable when you don't need access it by BufferFromEntity but by in in ForEach, operating through different ECB commands. Especially after adding AppendToBuffer for ECB. Or when you create new buffers, or wrapping BufferFromEntity indexer access in some conditions etc.
hey guys, is it possible to call C++ code (a native dll) from inside a job?
Using things like DllImport?
Usecase is, I'm using ENet which is a native dll. but looking at the code, alot of it is structs and pointers but with a class based wrapper around it
Was wondering if i could bring it all into the JobSystem for MORE speed!!!
hmm doesnt unity's transport layer use native c bindings
if it does you can probably do the same for your own C++ code 🤔
Unity Transport is what i 'should' use but it feels so clunkly atm
iirc they had native bindings that you would include into the project/build
I'm pretty sure you can call your own C++ code from job systems
if that was the case for transport layer
yea i think transport does have native bindings of some sort
yea - might as well try to include native calls into a job system 👀
i'd be interested to see if it works 😅
its all still idea phase for that bit
im not sure if i need the performance of moving it to job system yet
its already in background threads
i need to put better profiling around all these bits so i can tell where the performance issue's are
you could try using VTune to profile the built game
that looks intense
i was thinking more about getting automated tests working then profile those
probably using the built in profiler
yea that's reasonable
wow unity gets REALLY unstable if your not disposing native collections
It does
thats what i get for being lazy i guess
what?? unity isnt in node??
what ? unity isn't running in node?
then why do I see a nodejs server running in the background whenever I open unity....

Tf
personally i think they should have used nuget, but as their packages are all source code i guess it makes sense
when will unity make us batch install packages? 
it's a pain in the ass to update your packages 1 after the other...
yea its a pain
but also i much prefer to update 1 at a time
if i update a bunch and my game dies, which 1 did it?
I wonder what would a burst vs c++ benchmark would look like
would almost expect burst to be faster on some stuff 
there's been a forum thread with benchmarks for it, burst can be faster, if C++ isn't compiling as well.
is there a way to query for entities, within a collider?
kinda
you can use a collision job to get a callback on a collison
or you can use the physics world and do a *cast of some sort
finally i think you can use the physics workd and access the collisions there somehow
Is there anyway to log a JobHandle?
I'm 99% sure im setting up the handle correctly but as theres a few different worlds involved and i have to copy things around i think its not set right
dam this struct vs class, ref thing does my head in
A job handle is a magical work order - you get it when you tell someone (the DOTS systems and jobs) to do something, and you can use it to check if they're done.
You can also give a bunch of job handles to someone else to tell you when all of them are done, and you can pass them around so that people know when they should begin their work, if they need others to finish first.
it's pretty much the same, but more fit for purpose for high-performance games
tho 1 question, is it ok to keep doing jobhandle.CombineDependencies
Well, minus async/await. Definitely tasks, though.
yup seems more light weight
What do you mean "keep doing" combinedeps?
Combine deps, and then use the result to combine with something else?
i have system A that sets a jobhandle to jobhandle CombineDependencies(old handle, new handle)
Then system B CombineDependencies with that into its dependancy, then schedules its job, then sets that origional dependancy to another combine
Combining deps should be pretty much dirt cheap
oh and system a has that merged with its dependancy
Here system B should probably use AddInputDependency or what it is with system A
i thought about that, but AddInputDependency is something you need to code yourself and 2 they are in different worlds
Ah
so a system should not have access to a system in another world
Wait, how do you make them cooperate over different worlds anyway? And why?
Temporary worlds?
no perm ones
so server client worlds
server builds up a list of messages and 'pushes' those messages to the client
Because otherwise that seems like bad pattern.Different worlds should probably not have deps on each other, unless something like the physics world
in this setup both worlds exist on the same instance as the player is hosting and playing
Ideally you would still want to have them communicate as usual over TCP/IP
yea they will
Just using localhost insted of WAN or internet
but no point doing that when self hosting/single player
as theres a cost to serialize the data too
But you need that cost on the server for multiplayer anyway?
for dedicated hosting this wont be a issue as a client world wont exist
im aiming to not have dedicated hosting
so players host their own games
like old rts games
so a host is likly a player too
(also i relise that was a bad example as rts games were mainly lockstep)
Well, if you have one player who runs both host and client, and the serialization needs to happen anyway (for other players)...
Why make the local player communicate differently from everyone else? The deserialization cost should be miniscule compared to everything else.
having two methods of communication means two sets of potential bugs
also most rts games are mainly played singleplayer
Even with no connection to the wider net, as long as the computer has the hardware for internet (which in modern times means any motherboard - wireless support not needed), you'll be fine.
localhost (127.0.0.1) is a special IP that short circuits the normal routing, but going to the local internet controller, and immediately returning, no inet required.
If they have a router, they can use the local WLAN IP to connect to themselves as well as other people on the local are network (LAN).
And if that router is connected to the internet, you can connect outside the LAN.
Program <-> PC network hardware <-> local router <-> the internet™️
If you're making a networked game and you're not familiar with how the internet is built, architecture-wise, I advise you to look up the basics of the internet and routing.
it still feels wrong to have a network connection for single player
Many games do it, it's not wrong
It's more correct than making a special case for local client ^.^
maybe
but i still want to get this working
as a quick memcopy seems way better then a whole serialization network flow
plus im pretty sure i got it 😛 just need to confirm those job handles wont explode
also i have a usecase where i want lots of client worlds
Still only serialize once, so more clients just make my argument stronger 🙂
Well, making it work is more important than making it "correct", so do that first, and if/when you later find that having two methods of communication means extra maintenance and bugs you could look into using just network.
Is there a way to use isharedcomponentdata like archeotypecomponent on ijobchunk ?
or this is going to crash
cause i am getting error when i tried to getNativeArray
i just want to get isharedcomponentvalue on chunk
thats all
so maybe getnativearray is fool i think cause all have samevalue on chunk
Where are you trying to do this?
Because jobs have all sorts of restrictions on managed code such as nativearrays
[BurstCompile]
struct VertexSampleJob : IJobChunk
{
[ReadOnly] public ArchetypeChunkComponentType<ProjectionVertex> vertex2;
[ReadOnly] public ArchetypeChunkComponentType<ProjectedOccluder> archetypeChunkComponentType_occluder2;
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
{
var vertex_aux_array = chunk.GetNativeArray(vertex2);
if (chunk.Count > 0)
{
var vertex_aux_ = vertex_aux_array [0];
}
}
};
i am getting error while try get nativearray
cause syntax is not right
Projection Vertex and Occluder are sharedcomponents
so i guess there may be other way to get them that i didnt see
solved , docs were right xd
Anyone know what this is about? Trying to build the game.
It worked with the buildconfigs before, but this time I had to download com.unity.platforms.windows, and it gives me this.
Whyy.... are you making nativearrays, filling them, and then disposing them, all inside the Entities.ForEach?
How about declaring and initializing, as well as disposing them outside the ForEach?
Then you can use dispose on complete?
So my first impression was "wow, block of code. Consider splitting up"
And now that I somewhat think I understand it... Yes, still think that.
Ideally I think it should make the arrays of stuff to spawn, and then spawn either using entitymanager or a separate ECB job, but with that inner loop you suddenly have unknown size...
well in reality (for now). It's only running the foreach once since it just returns my 1 and only spawner entity.
Maybe use NativeList? Pretty sure NativeArray also automatically resizes on add.
The unknown size here stings, though. You effectively have a 2d collection. No idea how well native collections handle that, but NativeArray<NativeArray<RelevantComponentData>> could work. Or just straight up ECBing it.
SpawnerData spawnData here is a collection (DynamicBuffer?) with individual values for each thing it spawns?
The entire system (non-ECS meaning) seems like it might benefit from a architectural re-thinking. The way you do things here should maybe theoretically work, but I can't find any ways do to it that doesn't do bad patterns, bad practice, or is bad for performance...
What are you trying to do ?
if you're just spawning a certain amount of things, you could do:
- Get spawner info
- Spawn the things in batch
- Possibly randomize the things' ICD values that should be randomized
where #3 could be done completely separately. So you could spawn all of the things with literally the same ICD values, and some other system (or job) would the randomize the specific values that should be randomized.
less control at design-time, I suppose, but ehh. Fudge it till it looks and feels good.
okay I give up on my first attempt
lemme show code in here since somehow I'm only able to connect to discord...
is there a way to execute a job after ecb complete creating entities ?
so what I'm trying to do is speed this system up.
looking at my profiler.
if I became too ambitious with this system.
it's a huge main thread block.
What I was trying before was batch spawn and batch set the data of my bullets.
is there a way to execute a job after ecb complete creating entities ?
@undone torrent
i.e. job1 ..... AddJobHandleForProducer(job1) ..... job1.complete .... job2 ..... job2.complete
job2 is executing before new entities are created, i mean ecb didnt finish the sync point
@deft stump there's a unity dots demo somewhere that spawns bullets - wonder if that might be worth tracking down. You can likely make this faster by having a job that just calculates the number of bullets to spawn. That said, how do the 'SpawnerData' components come to exist? Could you instantiate at that point?
@deft stump yeah its probably not good to instantiate every bullet individually. Is there an overload for batch creation/instantiate in ECB you can use? or you could split it up into a creation system with a tag attached in the prefabs to signify and 'uninitialized' version - which lives somewhere sync-point friendly and just uses EntityManager to batch create. Then another system that can set the data with ECB for every entity with a customprefab tag + uninitialized tag, and remove the uninitialized tag once components are set (should just be an archetype change and so fast). If you have really large numbers you could even use an Entityquery after processing all, to batch remove the uninitialized tag.
Internet is back

Now then...
@amber flicker What do you mean come to exist?
@mint iron I'm actually doing that... hold on lemme show it to you...
Okay... giant code block, I know
I also had to put it in the initialize group.
what I meant was how/when are you creating those spawnerdata's?
Can I put materials/textures into Asset Bundle? Currently I have all assets inside Resources folder but it's more than 4GB and Unity throws exception
@amber flicker aaah.
so inside that ICD is a reference to a blob. So I make the blob during conversion, then take the referrence of the blob and assign it to the icd.
Ok I see - so e.g. 'how many bullets of what type' kind of config? The code you posted looks to me like it'd be a lot faster - does it work? have you compared?
it works. i haven't tested the 1K bullets per 0.5 seconds
I'm a bit confused though.. if the spawnerdata is created at conversion time, couldn't all these entities too? Or is there some additional event or something?
what you mean all these assets?
like the bulletprefab?
it is being converted.
here's the components of my spawner entity
what are those components on?
it's on my spawner entity.
are these bullets spawned on some event presumably? Like a key press?
I see
with burst enabled and safety checks off? that's stupidly long
safety checks off, jobs debugger off, leak detection off
burst on? think that job should say bursted if it is
debug log's or something? is that a bunch of gc there too?
what from?
hmm.. bit hard to remote debug... all I can say is that looks wrong if you're dealing with pure dots stuff. Do you have any particlesystems or mono stuff?
nope
and here's the ECB version

like wow
I want to know if EntityTransactionManager might help
but I dunno how to use the API properly
you need to work out what's going wrong first - take a look in the hierarchy view and find the stuff with highest gc
the profiler's hierarchy view
are you doing 5k x 1000 bullets?
how about the non ecb version that you pasted the code to earlier?
what's in Instantiate.Awake?
that looks odd to me... don't know if anyone else here can shed some light. I would check that a build attached to editor still looks the same.
maybe because I'm really pushing the instantiate to the limit
what does the bullet prefab have on it?
burst on of course
but you're not using it 😄
its an interesting setup you've got i havent seen that approach before with CopyFromComponentDataArray
but this is why i said two systems, the second stage that sets the data can go in normal ForEach burst/parallal if you want
wait isn't systembase burstcompile by default? or is that only lambdas? I thought em.instantiate with batch was burst compatible
its only in the lamdas, foreach or Jobs.WithCode
ah
but now that you mention it, he can probably put his for loop in a Job.WithCode
@deft stump try adding [BurstCompile] above your system
or did they release new entities with entire systems bursted? maybe im on old info
I don't know why the non-bursted one would have so much gc anyway...
so [BurstCompile] my EMversion.
might want to look at the source for CopyFromComponentDataArray it probably has a waited job for each one.
Oh it didn't crash. hahaha. but its lagging so hard.
restarting the editor!
and yeah use persistent NativeList system fields and resize instead of new allocated arrays
isn't it faster to just allocate the arrays specifically?
no
whaaat. okay okay... Imma profile the burstcompile one first. then do a branch to replace all the arrays into a list.
ToComponentDataArray also has a job inside each one and allocates new arrays
gotta get rid of all that stuff imo
the point about the nativearray being responsible for the gc may be true but I don't think it would take this pattern? Unless there are many spawners. I could be wrong though
it's just 1 spawner, just to be clear
or so you think... jks 😄
ECS magick, your spawner has now multiplied, good luck garbage collecting
maybe this is applicable to what you're trying to do https://github.com/jeffvella/UnityEcsEvents.Example/blob/master/EventsExample/Assets/Game.Scripts/Systems/SpawnAttackerSystem.cs (ignore the events and prefab stuff but just the system/tag setup)
how big's your project? I could take a look if you share it. Also - what Unity version, entities version etc?
well there's lots of music assets in the project. but they're not being used.
they're just sitting in the project folder.
hell there's literally only 1 scene!
unity ver: 2020.1.0b12
entities ver: latest
hybrid ver: latest
burst ver: latest
jobs ver: latest
unity phyics: latest
hold on. lemme push it to github. I have to get rid of lfs and all that stuff too

I made an MainAssembly.asmdef file in my Assets folder and added Unity.Entities as ref, but I'm getting errors that IConvertGameObjectToEntity and GameObjectConversionSystem can't be found.
all the other Entities stuff works
I'm on 2020.1 with the latest Entities package. Any ideas?
think you might need to add Unity.Entities.Hybrid perhaps? that's from memory but check the namespaces if not sure
What's the easiest way to figure out what's in what namespace
I use find in VisualStudio's ~~project ~~ solution explorer - don't know if that's the easiest
gotcha thanks
When using asmDefs you need to add references to the assemblies you use - for DOTS this means each of the packages.
In general I just add Entities, Jobs, Burst, and Collections to any AsmDef using DOTS. If using physics or renderer, add the relevant ones. And of course link to any of your own assemblies you use.
yea... though from memory I think the Unity.Entities.Hybrid is a bit of an odd one out as most top level asmdefs tend to include their children
For those following along, I think we tracked down mfragger's issue (though waiting for confirmation) - Bullet prefab has a Sprite Renderer
just a quick question, is there anything up with debugging dots?
my VS and unity keep crashing on a tiny projekt with 1 system when trying to debug it
setting a breakpoint inside some entities.forech loop seems to be ultra broken
@lime summit haven't bothered much myself but this vid might be useful? https://www.youtube.com/watch?v=nou6AIHKJz0
Im gonna try it out in ECB version first
"havn't bothered myself" ?! you are not using the debugger?
2020.1.0b6 always crashes when i start debugging and the newer versions don't even start for me so all my debugging consists of Debug.Log like back in the days in which i didn't know what a debugger is.
i just do print line debugging 👀
@amber flicker i would assume hybrid being separate is for tiny right?
Yea that’s what I assume too
print line debugging is like going back to a motorized beer crate, when being used to drive a damn maserati
sure, it gets you to the goal, but heck, my time is not that worthless
(close though)
It’s only recently become possible to use the debugger with bursted stuff and in general I’ve had a very crashy time using VS debug with Unity. Most of the time these days I just use .log. It’s personal pref but crashy combined with hopping around jobs on threads makes stepping pretty unpleasant imo. Maybe one day I’ll learn to use the vs thread debugger stuff properly but I don’t believe I’m bottlenecked by that of all things 😁 - the speed of my brain is my main issue
i have no understanding what you guys are doing when you are not using the debugger
yes, i am a noob and oversse obvious things
but the debugger is on the same level than udnerstanding what a type is
its super essential
print line debugging is no comparrison to being able to check the stack trace
or seing what is called when etc
Print line does give you the stack trace...
yes, but you cannot step through the stack trace and chek the locals while executin is halted
you have to recompile and start playing over and over and adapt the outpu
in comparrison to simply clicking through the paused code at the exact right moment in time
you are doing the same stuff just 100x slower
I’ve done it both ways. Imo debug log is just as fast in 90% case. Anyway.. pretty sure this is up there with tabs and spaces so... I’ll leave it there.
if your debugging things which are not written by yourself without the debugger, then its like comparing tabs with whitening pixels by hand
For simple stuff, print line works fine, but if you have a more complex "I need to find out why I get result Y when I expect X for what should be inputs ABC", being able to step through your code is greatly helpful.
And as simon says, debugging code you have no written. I would even extend that to code you haven't worked on recently.
A semi-complex class you haven't touched in a month? What did that do again?
There are habits and styles of code that makes print line debugging easier or harder, though - large chunks of code with more than the most basic complexity quickly become very hard to reason about using just print lines.
Simon says:
use the debugger! (but not with the current Unity/dots version as its broken af)
I don’t disagree strongly. I will just add that this kind of thing often comes along with a programmer elitism I dislike - and I don’t think people should feel like they’re an inferior programmer over this kind of thing.
I think everyone working on a language that supports it, with an IDE that supports it, should know how to use a debugger and step through code.
But like print lines, it's just a tool - and while it can be extremely useful in some cases, it can also be way overkill, or straight up the wrong tool for the task at hand.
I have maybe a 30% success rate getting breakpoints to hit, and not stall, and not crash when I try to inspect something, so Debug.Log is kind of the only option
I literally have to maneuver my mouse around certain things soas not to accidentally inspect-on-mouseover, its nuts
the entire editor freezes(and is non responsive) when hitting a breakpoint with rider debugging so debug.log has been my goto as well.
hi, i got this error
ArgumentException: A component with type:SceneSection has not been added to the entity.
im using HLOD at hybrid renderer. how can i handle it?
on the topic of debugging... "aline" by the same guy who made astarpathfindingproject allows for gizmos in burst and ecs
i just picked it up and had a quick mess around, works quite well so far? got an arrow drawing for every entity with a translation and rotation https://gfycat.com/snappybadbooby
arrows are kinda hard to see because im palletizing my colors(also gif) so it should look more legible than that in a normal project
i have the a* pathfinding project which that says uses it
i saw that, could probably dig into the code and use the methods from it but i thought personally worth giving the full thing a shot
are they both compatable in the same project? im using a* for my pathfinding
i would assume they are but I havent tried it
i kinda wish he would make a pure ecs version of astarpp. i own a copy but Im using unity's builtin just because its slightly faster to enter play mode with
so the latest betas are all burst and job system under the hood
getting some crazy speed ups
and things like his local avoidance have been rewriten too
but its still not super easy to interface with from ecs
as things like paths are classes
its kind of sprawling and huge, just from looking into things it feels like it could be better organized but this is also my selfish desires for pure ecs pathfinding 🙂
yea there is ALOT of code there
i probably only use like 20% of it
1 maybe 2 graph types
and i need to rewrite the graph scanning bits so it tests in the unity.physics world and not the default stuff
and i never use any of the movement scripts, i just manually get a path and do my own thing with it
I used aipath but did have to make fairly extensive modifications. sometimes I wonder if i should just bite the bullet and take a real good stab at learning unreal(or less so unreal but learning c++)
https://github.com/capnramses/pro_programming_tools_c_cpp might be a good overview of c/cpp if you're interested @safe lintel
@wary anchor yo i was looking if anyone had a shot into making poisson surface reconstruction in unity and saw you question a year ago, did you manage to get it working?
Good grief, I can't even remember what I asked!
its about building a mesh from a set of 3d points
ahh, I may have done but I can't remember because I ended up ditching that and raymarching my scene instead, so now I have 0 verts 😄
Sorry
💪 GL
How do I instantiate an entity as a child of another entity? Is that even safely possible (given all the other things, like LinkedEntityGroups, etc...?)
I've tried adding child and parent components so far, to no avail.
you should add child to parent's child and LinkedEntityGroup buffer
and add the parent to child's Parent and LocalToParent components
idk, i just use ecb 😄
ah I think they're all buffers, right?
well other than the components that go on the child
Child and LinketEntityGroup are buffers, Parent and LocalToParent are components
Ok I can write those relatively safely.
Guys, if I group all my systems with structural changes within a system group, and update it just before EndSimulationEntityCommandBufferSystem, am I effectivelly avoiding extra sync points and so having just one at the end of the SimulationGroup?
but the group doesn't affect in any way?
there are a few systems that I require to perform actions at that moment, because it is faster than sheduling to a ECB
as long as nothing in the group is scheduling jobs it should be fine, if you schedule a job and then do something that forces a sync point that will be bad
what are you trying to do tho?
usually being able to do a bunch of work in the job will win out even with the ECB being a bit slower
one system is a spawner, but it spawns multiple entities, so I use a nativeArray
for everything else I try as much as posible to use ECB
yea thats a tough one, as with low number of entities ECB is probably better, but spawning tons the batch apis are best
there needs to be a batch ECB
what is that? (sorry If I dont understand all terms used in this context, I'm new to both ECS and unity ECS haha)
ECB = entity command buffer
batch apis i was talking about the entity manager apis that use native lists/arrays
and was saying that unity should make a batch version of ECB
oh yeah, I think the same, actually I wrote the system thinking it does exists, but then I realize it doesn't haha
But is ok this way
there are not a lot of systems with structural changes, so I dont think it is a problem
and was saying that unity should make a batch version of ECB
that's why I horrendously tried to convert my spawner system from ecb to em.
just to use the batching system
if it becomes more of a issue you could look at exclusive entity transaction (or something like that)
allows 1 job to do structural changes
but doesn't that "lock" the EM into one thread?
yea i belive so
so for my case, I can't do multi-threaded spawning.
but having 1 job doing all your spawning is still good
better then blocking the main thread
eh. true.
i think the spawn scale would have to be huge to make it worth it
probably like 10k + entities
kek... I might need it
😛
crap... I dont have nitro anymore :notlikethis:
i feel its one of those things to look at when your profiling and trying to get all the speed
is it just me, or I can't seem to find platforms ios on my package manager
Not in the package manger, but google finds it https://docs.unity3d.com/Packages/com.unity.platforms.ios@0.5/manual/index.html
soooooooooooooo
EM version spawn time of 1000 bullets in 0.5 seconds.
and properly using rendermesh...
is now 2.46ms!
:dab:
thanks @coarse turtle
this is actually massive improvement
just not using sprite renderer and using render mesh.
even when ECB is slow.
And I might gain more perf from using EM batching,
it's massive difference
There is a EM batching ? 👀
there is. I posted the code before on my implementation
sadly there's no ECB batching
😔
Damn, I tried placing my Entities closer/further away from the camera hoping that would fix my draw order problem, but it seems like the Hybrid Renderer is still drawing certain entities ontop of others despite the distance to the camera
That sounds rather strange. Are you using orthogonal view? Special shaders?
Well that's trippy
that big line of holes there should have roof tiles, for example
but they are being drawn underneath tiles that are further away from the camera
Any particular reason why things are build 3D with orthogonal view?
Just trying to convince it to do the ordering you want?
as opposed to just working in Unity 2D?
These are 2D graphics on flat planes that face the camera at a geometric angle, most people would refer to it as isometric graphics
In the gif they don't seem to be on a flat plane. I am familiar with isometric 🙂
each "tile" is its own flat plane
But the gif is very confusing to look at, probably because of that ordering
yes, it only looks good at a very specific angle
or it would, if the graphic draw order was happening correctly
With orthogonal camera the distance to camera doesn't matter, so they could be on the same plane, but eh.
Sidenote: Are you using "plane" shapes for the tiles? That's a lot of extra polygons compared to "quad"
no, they're quads
here's the same building at the magic angle
my gif is just trying to show that my geometry is closer to the camera, but the draw order doesn't seem to care
here's another
that's really trippy
it's like that sidewalk art that looks cool, but only at a very specific angle
anyway, I don't know if this is a bug with the hybrid renderer or what
my unlit shader is transparent
I think I hit the limit of ecb destroying 10,000 stuff.
Could those particular tiles have a priority or something which overrides the normal distance priority?
what kind of priority? I am aware of the "Sorting Priority" that exists on HDRP shaders and "Render Priority" that exists on Mesh Renderers
but I've never seen any evidence that the Hybrid Render pays attention to either of those
in either case, I haven't changed those values
I am not familiar with those kinds of things, but looks like an override to me. What if you remake the offending tiles from scratch?
what do you mean by an override?
It overrides draw order. Why, and on what basis, I have no clue. But it does not do what you'd expect from the default behavior. Thus, override.
i restarted the editor and now it's different tiles where it's happening
yes
almost makes me feel like something is going on during entity conversion that messes with the draw order
i'm using GameObjects and sub-scenes to do the entity conversion
yeah if I hit re-import on the sub-scene it produces different results
the flashes are when I re-import the sub-scene
wat :o
I think we need someone who really understands this to find out WTF.
Though you can probably bug-report it - if not directly a bug it's unwanted behavior
yeah I may make a specific forum post about it.
it's almost like the order the entities are being created matters or something
I don't have direct control of that when I let subscenes do it for me
and if I "Edit" my subscene (which shows game-objects in scene view), the entity draw order goes really crazy in my Game View
thanks for talking with me about it
here's what it looks like when it's "just GameObjects" and not entities, so yeah definitely think it's something in the Conversion process maybe
i think I'll isolate just this building and make an example project out of it
I also noticed that when I deleted my other subscenes that were converting 2 million GameObjects into Entities it stopped being inconsistent and now consistently draws the same tiles out of order no matter how many times I re-import
So now it's at least consistent in it's bad behavior!
But also, holy crap, maybe consider merging some of those to not 2 million GOs/entities?
only certain parts are drawing incorrect
no deal, I'm using ECS so I can keep every tile separate from one another. 😉
and so they can be moved individually at runtime if I want
That's... I'm not sure if that's the proper use case for this, but I mean... if it works...?
each sub-scene has 10,000 GameObjects
I am pretty sure mega-city was something like 6 million gameobjects
when a sub-scene converts it to entities, the GameObjects no longer exist in memory
ah it was 4.5M mesh renderers for MegaCity
That's a crazily optimized sample (by people who deeply understand and even built the system), though
well, yes, I'm relying on however Sub-Scene gameobject conversion works
the 2 million entities run really well even when I render them all simultaneously
it's just the draw order that's a problem
i should try manually making my entities again sometime and see if that makes a difference
i do like the idea of the sub-scene workflow, though
question... how do I know if a component is a shared component in the entity debugger?
@unborn totem might be worth checking that the renderbounds etc are all different on the converted entities- it looks like all pieces may have the same pivot point from the model for example
@amber flicker you're right. it's my sprite renderer that's making it lag so much
and gc'ing it to no end as well
now then... how do I assign a material in a job
well, I changed my material to Write to the Depth buffer and turned on Alpha Clipping and it seemed to fix almost all of my problems
I swear I tried that before
Unable to access the managed method `object.Equals(object)` from type `Unity.Rendering.RenderMesh
❓
???????
still doesn't look like it's fixed all of them, though
okay so now I'm trying to solve this...
that random bullet flickers in that spot
I'm guessing because the entity is spawned there first before I set it to the correct spawn point.
Yes - either make sure the spawn system finishes setting pos/rot before the transform system or you can manually set the ltw (for the first frame) (I prefer the former)
welp I put it in the beginSimCommandBuffer.
and kek spawning 1000 bullets per 0.5 seconds takes 0.001ms
I don’t know if all of it is on the main thread - I suspect it’s taking a bit longer (you can click on the job to see total time) but that sounds more like it!
I WILL SHOW YOU TRUE BULLET HELL!
Hahah... that first taste...
but doesn't that "lock" the EM into one thread?
@deft stump this is why EET used in separate world which wouldn't lock your main world EM and didn't stuck logic and only synch when you MoveEntities from which is very fast. This is how built-in subscenes streaming works.
About ECB. EM batched operations of course fastest thing as I described it many times (And ECB has it partially for adding\removing components, destroying entities (EQ version of batched operations), but not for Concurrent version). But don't forget that ECB chain playback now fully goes through bursted codepath, and it gives huge performance improvement, even with sequential commands processing.
Yesterday, I spawned a few entities from a converted prefabs with point lights on them. (for a muzzle flash on a bunch of cannons)
Normally the lights don't work (Hybrid Renderer V2) ... but I had them in for my authoring workflow anyhow (and for when I figure them out)
But then they did work! And it looked great!
I wanted to verify that I didn't spawn a gameobject instead or something... and then the lights stopped working again.
Now I am back at square one and can't get point lights on entities to work. -.-
Anything specific I need to do to a Light Component (monobehaviour) to convert it to an ECS component that acts as a light?
Can you even do that yet?
Convert and inject would do the trick, but of course then you'd still have the gameobjects
Yeah it's kinda weird. The objects were also removed so they definitely were tied to the entity TTL component I use.
I had a convert to entity system on it, maybe I had it set to inject... but somehow I doubt it.
do you have any disabled components in your gameobject ? that sometimes stops monobehaviour (and Unity components) converted properly
Has anybody run into this error while serializing/deserializing the world:
InvalidOperationException: The BlobAssetReference is not valid. Likely it has already been unloaded or released.
IndexOutOfRangeException: Index 1065297994 is out of range of '2' Length.
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
using (var writer = new StreamBinaryWriter(_savedWorldFilename))
{
SerializeUtility.SerializeWorld(entityManager, writer, out unityMappingTable);
}
}
public void DeserializeWorld()
{
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(World.DefaultGameObjectInjectionWorld.EntityManager.UniversalQuery);
if (unityMappingTable != null)
{
World localWorld = new World("local world");
var transaction = localWorld.EntityManager.BeginExclusiveEntityTransaction();
using (var reader = new StreamBinaryReader(_savedWorldFilename))
{
SerializeUtility.DeserializeWorld(transaction, reader, unityMappingTable);
}
localWorld.EntityManager.EndExclusiveEntityTransaction();
World.DefaultGameObjectInjectionWorld.EntityManager.MoveEntitiesFrom(localWorld.EntityManager);
}
}```
Hopefully it's okay to ask here. I tried on the forums but a mod took it down.
Okay soooo...
I have an new problem...
same problem as the guy above. The BlobAssetRef has been released.
wait... I got past that now...
wait wtf
there's 4 of them!

Oh I got it to work now
what was the issue?
I used convserionsystem.CreateAdditionalEntity instead of conversionsystem.GetPrimaryEntity
I think I need to remap the entities after deserializing?
a mod took it down? what was their reasoning?
Not sure. It had the little glasses icon that said mod review and then it disappeared. I don't have any messages or alerts about it.
anyway did you manually dispose any of the blobassets before you tried to serialize your world?
I am not directly using any blobassets in my script. Stack trace looks like it's coming from the collision world Unity.Physics/Collision/World/Broadphase.cs:749
I have also tried disabling the SimulationSystemGroup during serialization but I still get the same error
MoveEntitiesFromInternalAll(EntityManager srcEntities, NativeArray<EntityRemapUtility.EntityRemapInfo> entityRemapping);``` same problem as well. This is making me think the problem started before trying to move to World.DefaultGameObjectInjectionWorld.EntityManager
oh, i seem to recall disabling physics when I was experimenting with this
yeah quick check i had this in my save test system
private static void TogglePhysicsSystemForSaving(bool enabled)
{
var x = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildPhysicsWorld>();
x.Enabled = enabled;
}
might be related
It was a good thing to try, but not it.
{
World.DefaultGameObjectInjectionWorld.EntityManager.CompleteAllJobs();
TogglePhysicsSystemForSaving(false);
if (unityMappingTable != null)
{
World localWorld = new World("local world");
var transaction = localWorld.EntityManager.BeginExclusiveEntityTransaction();
using (var reader = new StreamBinaryReader(_savedWorldFilename))
{
SerializeUtility.DeserializeWorld(transaction, reader, unityMappingTable);
}
localWorld.EntityManager.EndExclusiveEntityTransaction();
CleanUp();
World.DefaultGameObjectInjectionWorld.EntityManager.CopyAndReplaceEntitiesFrom(localWorld.EntityManager);
}
TogglePhysicsSystemForSaving(true);
}
public static void CleanUp()
{
var ents = World.DefaultGameObjectInjectionWorld.EntityManager.GetAllEntities();
foreach (Entity e in ents)
{
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(e);
}
} ```
I just don't see where I'm affecting BlobAssets in my code. 🤔





