#archived-dots
1 messages ยท Page 74 of 1
Do you have a container passed into a previous job and within it the [DeallocateOnJobCompletion] attribute is on the container?
No
At least, i dont think so.
The script is here, @stuck saffron
Try disposing the entitiesarray after scheduling the job
Maybe not. Skimmed too quickly and entitiesarray isn't the one its complaining about buuuuut
any ideas why a convert of a prtefab seems to be stripping off the mesh renderer?
is it something made with probuilder? had some issues there
its a unity default sphere
i assume you have the hybridrenderer package installed?
yep
its just been tested with a mesh identical to the one already being spawned and visible successfully, still not visibl
if its just a blank sphere and converttoentity it should work, if you are doing something in the conversion process like swapping components it may be missing something that the render system needs
i would check the entity in the debugger and see if it has everything that a working entity has
Thats how i know its stripping off the renderers
This one's proxy is real simple too
public class ParticleProxy : MonoBehaviour, IConvertGameObjectToEntity
{
public ParticleData GetData()
{
ParticleData data = new ParticleData();
data.lifeTime = 5;
return data;
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = GetData();
dstManager.AddComponentData(entity, data);
}
}
Also, can anyone answer - is there any particular reason that var is used so much in ecs? is it gonna cause problems if i define my types more clearly?
yep, in fact, its kinda acting like its ignoring the prefab entirely, in spite of my references all being linked up.
so if you were to drag the prefab into a blank scene on its own, it doesnt get stripped?
that works fine, its getting passed the prefab through from the spawner
like the example spawner did
public class ParticleSpawnerSystem : JobComponentSystem
{
EndSimulationEntityCommandBufferSystem entityCommBuffer;
protected override void OnCreateManager()
{
entityCommBuffer = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
struct ParticleSpawnJob : IJobForEachWithEntity<ParticleSpawnerData, LocalToWorld>
{
public EntityCommandBuffer CommandBuffer;
public void Execute(Entity entity, int index, [ReadOnly] ref ParticleSpawnerData spawner, [ReadOnly] ref LocalToWorld location)
{
for (int i = 0; i < spawner.particlesPerSecond; i++)
{
Entity instance = CommandBuffer.Instantiate(spawner.prefabObject);
CommandBuffer.AddComponent(instance, new LocalToWorld { Value = location.Value });
CommandBuffer.AddComponent(instance, new ParticleData { lifeTime = spawner.particlesLifetime });
}
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var job = new ParticleSpawnJob
{
CommandBuffer = entityCommBuffer.CreateCommandBuffer()
}.ScheduleSingle(this, inputDeps);
entityCommBuffer.AddJobHandleForProducer(job);
return job;
}
}
shouldnt it already have localtoworld and particledata?
Yes
wait... maybe its the spawners proxy
public class ParticleSpawnerProxy : MonoBehaviour, IDeclareReferencedPrefabs, IConvertGameObjectToEntity
{
public GameObject particlePrefab;
public float particlesPerSecond;
public float particlesLifetime;
public bool stickToParent;
public void DeclareReferencedPrefabs(List<GameObject> gameObjects)
{
gameObjects.Add(particlePrefab);
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var spawnerData = new ParticleSpawnerData
{
prefabObject = conversionSystem.GetPrimaryEntity(particlePrefab),
particlesPerSecond = particlesPerSecond,
particlesLifetime = particlesLifetime,
stickToParent = stickToParent
};
dstManager.AddComponentData(entity, spawnerData);
}
}
im surprised that doesnt give an error if the spawner.prefabObject is the same prefab as it should already have the ParticleData and a LocalToWorld
yeeah i thought it was wierd too... but take away the add component, and they have nothing...
the system is simply copied from my ship spawner.... which the only difference is that the ship spawner destroys itself.
If that made a difference, i should still get one particle on the first frame at least, i guess
for (int i = 0; i < spawner.Ecount; i++)
{
for (int i2 = 0; i2 < spawner.EcountRows; i2++)
{
var instance = CommandBuffer.Instantiate(spawner.prefabObject);
var pos = math.transform(location.Value, new float3(i, 0, i2));
CommandBuffer.SetComponent(instance, new Translation { Value = pos });
float x = 0; //rnd.Next(0, 10) - 5;
float y = 0; //rnd.Next(0, 10) - 5;
float z = 0; //rnd.Next(0, 10) - 5;
AISeedTracker.Ais += 1;
System.Random rnd = new System.Random(AISeedTracker.Ais);
int seed = rnd.Next(0, 2147483645);
CommandBuffer.SetComponent(instance, new MoverData { velocity = new float3(x, y, z), maxSpeed = 20 });
CommandBuffer.SetComponent(instance, new UniverseShipAIData { seed = seed });
}
}
CommandBuffer.DestroyEntity(entity);
this is the other spawner... almost identical.
is this a prefab in a prefab for the ParticleSpawnerProxy?
๐
I cant understand it, two identical systems, but one works and the other doesnt...
its not the nesting?
nesting?
What do you mean @safe lintel ?
Im completely stuck.
ive even tested spawning the particle with the usual ship spawner.
works fine, and, i can spawn the ship with the particle spawner, but i cant spawn the particles and the ships both at once. Well, if i do, it works, but the entities have no mesh.
ah thats super strange you can do either one or the other in each others system but not the way you intended
i thought it was a nesting issue with the prefab references but im out of ideas ๐ฆ
@golden heron is the working test on the same project? i was trying to figure out why my stuff wasn't loading, turned out i didn't import the hybrid renderer package
it was a similar issue too, if you don't have hybrid imported, no conversion added a mesh renderer
same project
during testing both systems still existed.
all i did was swap the prefabs around
all i want to do, atm, is be able to spawn from more than one system, and, to be able to keep spawning...
it makes no sense ๐ฆ
the system is in fact nested in the prefab, but even when i ran them side by side it still failed
hrm, so 2 systems spawning the same prefab? i haven't tried that yet
no
two seperate systems, duplicated from the same code, now provided with independent appropriate data and files, including seperate prefabs, now failing to work alongside each other.
the particle system ends up ripping off the meshes, or, its beginning to look like if i run them together its creating an empty entity rather than actually converting the one i give it, which, the other system is using fine.
so.. progress
i got them spawning seperately.
I do, however, now need to figure out how to overcome what seems to be the issue when i have the spawner attached to my ship, and attempt to move its entity around, using standard parenting. It appears, according to the internets, that this method...
public void DeclareReferencedPrefabs(List<GameObject> gameObjects)
{
gameObjects.Add(particlePrefab);
}
frm the proxy script isnt being called, due to the nesting.
ahh as i thought
Is there some way to call this manually on child objects? Or, to place the prefab on the parent entity, maybe, and have it be called there?
beets hed agenst wall
ive just put them on the main prefab, i think it might be possible if you were to dig into the convert script to mess around with traversing the hierarchy but thats too much for a possibility for myself
Its starting to seem it might just be easier to make a gameobject particle system just follow the damn ship hehe but that defeats the point of this.
I kinda hope these things get sorted out in the (near)future, the roadmap for this is still super vague/non existent
yeah i had problems nesting prefab refs when trying to come up with a destruction system, kinda gave up on it for the moment due to that peculiarity
i stopped enjoying that when i stopped going to nightclubs hehe
Well, i was intending a method of having the hiearchy consisting of a group of objects, each with its own heath.
Dont know how that'll end up now, but, to be honest, i could do that in oldschool monobehaviours, its the universe ships i need ecs for
goes to cry quietly in a corner hehe
Prefab variants aren't the time saver they're promising to be in real world projects, at least mine.
End up micro managing and making mistakes
its not so much a variant problem, more of a nesting ecs problem
Yeah, an object is nested in a hiearchy, during its conversion... damn... I just had a damnably daft idea...
You can call methods? those overrides replace methods? Only thing missing is an event trigger, basically>
?
Can you call the method manually in the convert function?
Or, at least move its code there?
if you figure out a way, do share ๐
Well, its quite simple...
The code in the function not being called, can it be moved into the convert part? That seems to work, i get all my ints and floats properly
Ill try when i finish my cigarette.
It needs the input list reference :(
I am gonna look at finding that list
I'm using the new Unity Physics package with ECS but for some reason the entities I'm creating (with EntityManager.CreateEntity) are invisible despite adding or setting the RenderMesh to it (with a material and mesh). I can even Debug.Log(EntityManager.GetSharedComponentData<RenderMesh>(entity).mesh.name) and it outputs the mesh name correctly
They're appearing in the Entity Debugger
do you have a localtoworld along with translation and rotation(not sure if those two are needed but might as well add em if not already there)
Did you add the hybrid renderer package?
Anyone know where I could find examples/point me in the direction of the ideal way to deal with pairs of entities that needs to check some data vs each other?
I feel like I always end up in these situations where I have like one Entity, keeping track of a second entity, and then need data from both to do something, like Collider from A, and damage from B.
One way I guess would be to add the data needed to a component on the second entity and calculate everything from that component and entity...
And since Collider is hybrid Object in this case, the easiest way would actually be to add a WriteDamageBackData to the second Entity with reference to the first Entity to write the info back to a component on Entity A, and then do the calculation... some messy stuff ._.
you can link entities, but i am also at a loss as to a good way to figure out this stuff.
it would be nice if there was a way to just have the linked entityB saved as a ref in entityA, and then be able to say something like GetComponentsFor(entityB) or something
as is, i've done it, but seems like it's pulling a lot of data for 1 thing... my example would be a timer. i wanted it possible to link multiple action entities to the same timers, in case i wanted everything to run in the same time-frame. so a moveTo entity links to a timer entity. to get the actual timer component, i send timers = GetComponentDataFromEntity<Timer>(true); through to the job, and use timers[moveTo.timerEntity] to get the actual value for that timer. seems strange to get ALL timers then find one entity, but it works.
that said.. i just got my guy moving! progresssssssss!
GetComponentDataFromEntity's just a pointer though right? So you don't 'get' all the timers - the issue is more that if a chunk has just filled the l1 cache, going off and getting timeres[moveTo.timerEntity] causes a cache miss mid-chunk-iteration- at least that's my understanding - would like to be corrected if wrong!
we'll just say that's over my head at this point, but if there's a better way to do it, let me know! i'm just learning this stuff.
That's the way I do things and I think for now it's the best way (that I know of anyway!)
There is one trick I do though which from benchmarking I think mildly helps with large numbers.... which is let's say you had 5 timers for one entity but only one was active at a time, have a 'current timer' component that sits on the entity and is populated (copied from one of your other entities), when it becomes active... then when you iterate over that entity the data is linearly there
@mystic mountain Try decoupling the entities by using a manager that both register to.
@amber flicker added an active tag to things to state the actions and timers currently running. now not only do i have movement, but chain-able actions... which is what i was looking to do. thanks!
hmmm, this appeared: https://bintray.com/unity/unity-staging/com.unity.visualscripting/0.6.0-preview.2
I don't get it, why they keep updating the old version, afaik this isn't DOTS version either
I can't see any way to create new assets with this to check it for sure, it only has blank editor window now
but it doesn't have Entities as dependencies so it's probably not a DOTS thing
yeah i feel like that was an old thing that's been coming for a while. DOTS visual scripting would be great tho
i feel like it might have been one of those.. purchased and implemented in core things?
I still don't get why they keep updating the old thing if it's never going to be released
I guess they could still update the framework if it's resusable
yeah, but if it's something that's been in the pipeline for a while, seems a shame to drop it when it can be of some use
hopefully. i'm looking forward to seen the editor for DOTS
maybe its just the visual editor gui part and the actual nodes are in another package
did you try the dots animation package 0lento?
only installed it to see the menu entries
never tried it
I don't really plan to do much rendering on DOTS at this stage
would love to but it's just too raw for production right now
maybe in few years :p
yeah its kinda a rocky road, was hoping you had figured out the clip/rig conversion
I have another project that could benefit from megacity style streaming
but it's not active project right now
new DOTS datapipeline is using this old vs editor still
huh
is there a way to send an array of entities from an entityquery to a job? i specifically want a list of entities with componentA but without componentB
EntityQueryDesc has All, Any, and None. You can then use m_QueryGroup.ToEntityArray(Allocator.TmpJob) inside OnUpdate() and pass it into the job
// m_QueryGroup is of EntityQuery class
m_QueryGroup = GetEntityQuery(new EntityQueryDesc
{
// Entity MUST have these components
All = new ComponentType[] { ComponentType.ReadWrite<ComponentTypeGoesHere>() },
// Entity CAN have these components
Any = new ComponentType[] { ComponentType.ReadWrite<ComponentTypeGoesHere>() },
// Entity CAN'T have these components
None = new ComponentType[] { ComponentType.ReadWrite<ComponentTypeGoesHere>() }
});
You can specify if the components are ReadOnly, ReadWrite
You don't have to use the Any or None
ah i'm running to the issue of setting them read only.
Also, you can do m_QueryGroup.ToEntityArray(Allocator.TmpJob, out JobHandle jobHandle) which you can pass the jobhandle as a dependency to the job. Or call .Complete() on it to make sure it finishes before scheduling the job
Hopefully that helps and I didn't just completely miss what you were asking
@safe lintel adding LocalToWorldProxy didn't fix it
@stuck saffron i keep getting "NativeArray Job Iterator must be marked [ReadOnly]" error when i send the entity native array through. i marked it with the [ReadOnly] tag, what else do i need to do?
basically everywhere i could think of trying to get rid of the error.
i can't make the entityquery readonly can i? i have the elements of the query set using ComponentType.Readonly<Component>()
then the nativearray<entity> is marked readonly as well inside the job
Can you post a code snippet?
embarassing ๐ but ok
Haha you can PM if you prefer
@gusty comet can you screenshot what the entity looks like in the debugger?
whats the difference from using "ref component" and "component" in the entities.foreach?
and is there a way to title entities?
because structs, all of your IComponentData are value types but using ref allows them to be used like a reference, so any changes you make in ForEach will in a sense stick
and by title entities you mean in the debugger or something else?
EntityManager.SetName("name");
doesnt work in builds though so you might need the #if UNITY_EDITOR #endifthing
ah thanks
@safe lintel I figured it out by looking in the debugger at an entity instantiated with a prefab, added RenderBounds, WorldRenderBounds, PerInstanceCullingTag, and LocalToWorld but I'm going to start removing them one by one to figure out what's necessary and what isn't
coolio
@safe lintel well for reasons I don't understand yet, removing WorldRenderBounds, RenderBounds, & PerInstanceCullingTag, but keeping LocalToWorld and rearranging it so Translation and Rotation were above RenderMesh did it ๐คท
using 2019.2.0a13 with all up-to-date packages btw
oh I see, RenderBounds and WorldRenderBounds are getting auto-added now ๐ค
Anyone interested in helping me test my new maths library?
its an addon the unity.mathematics package, with lots of its missing maths replaced with new Methods! Includes, for example, a new FromToRotation, and all methods are summarised for vstudio autocomplete descriptions
@me if interested!
Hey guys,
just another question. How you accessing data from a different entity or do you have a concept to avoid that? I would to link entities together. Let's say I want to spawn a movement point entity and this should have set it's owner entity. And in a system which is processes the movement point data I need position data from the movement owner entity.
I read about ComponentDataFromEntity<T> which will give you access to a component from another entity. But I also read this is slow.
While I found a post from Joachim Ante, where we suggested to add components to the entities which should receive the event. But will that not ruin the chunk utilization even more?
ArgumentException: AIMonitorData contains a field of System.Collections.Generic.Queue`1[Unity.Entities.Entity], which is neither primitive nor blittable.
my understanding is ComponentDataFromEntity is just a table lookup with the entity as the id
Oh noes
so I would use that and profile performance if things werent going as expected
any solution for how to use a queue in this case?
i mean before I knew to use componentdatafromentity I was plugging an entire array in and iterating until I found the entity as a match so it has to be better than that ๐
havent used queues sorry
but that sounds like one of the fields is incompatible for its useage?
yeah
but...
short of rebuilding arrays of thousands of objects every frame im not sure its gonna be possible...
After the change from UnityEngine.Quaternion to Mathematics.quaternion I am kinda lost.
Can someone hint me towards how to move an entity based on its rotation and translation? Or based on camera direction.
You can do something like newPos = translation.Value + (deltaTime * speed) + math.forward(rotation.Value) or pass the camera rotation into the job instead of using rotation.Value. And then assign it to the translation
in the job
Hey guys.... my brain hurts i try to do AABB collision detection within a IJobParallelFor
public struct AABBCollisionJob : IJobParallelFor
{
[ReadOnly] public NativeArray<IdleZombie.Components.AABB> Colliders;
[ReadOnly] public NativeArray<int> objectindex;
[ReadOnly] public NativeArray<Entity> allEntites;
public void Execute(int i)
{
for (int j = 0; j < Colliders.Length; j++)
{
if (j != i && IZPhysics.Intersect(Colliders[i], Colliders[j]))
{
// DELETE ENTITY ?!? }
}
}
As you see i want to remove the entity on collission. I cant remove it in the job as it seems, because you can't add a EntityManager in the job. How do i send a signal outside to remove it? Is there any way?
You can pass in an entity command buffer
So something like public EntityCommandBuffer.Concurrent commandBuffer; in your job
Ahhh I see... I'll check it out tomorrow. For now is sleeping time. Thanks @stuck saffron
@potent cape Yep, @stuck saffron is right, you'll want to pass the command buffer. I have a version here for despawning entities*: https://github.com/warlokkz/ship/blob/master/Assets/Scripts/Cursor/CursorDespawnSystem.cs
@potent cape
- I think you will need to use disable parallel for restriction (to allow accessing all indexes)
- You only need to loop over j = i + 1 (do not check same pair twice)
- command buffer
yes @dry nymph ?
i edited above...
ah ok ๐
- ummm i don't really understand what you mean? like not using the ParallelFor and just For?
- yeah... i realized that after posting yesterday too ๐
- thanks again ๐
1 - [NativeDisableParallelForRestriction] attribute on the Colliders array
@ember moth i wrote some extra maths functions i could do with testing, covers your use case by adding in a fromto using direction vectors, and you can use the lookrotation of quaternions with it.
Let me know if you'd lile to test, if anyone would like to - it handles a lot of basic maths stuff unity usually does but in float3, float2, and unity.mathematics.quaternion especially for ecs.
And, any suggestions for additional functions to add would be greatly appreciated - i want to make maths for ecs great again! hehe Also, it inlines properly too, so nice and efficient.
I also intend to make it very programmer friendly, when you pop up the vstudio autocomplete, it'll give full details, inclusive of the method's use, if i can help it.
//This is line 27 and 28,
AIMonitorData monitorData = EntityManager.GetComponentData<AIMonitorData>(monitor);
monitorData.entities = new NativeQueue<Entity>(Allocator.Persistent);
//-----------------First file, ComponentData
public struct AIMonitorData : IComponentData
{
public NativeQueue<Entity> entities;
}
//-----------------New File, for proxy
[RequiresEntityConversion]
public class AIMonitorProxy : MonoBehaviour, IConvertGameObjectToEntity
{
NativeQueue<Entity> entities = new NativeQueue<Entity>(Allocator.Persistent);
private AIMonitorData GetData()
{
AIMonitorData data = new AIMonitorData();
data.entities = entities;
return data;
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = GetData();
dstManager.AddComponentData(entity, data);
}
}
Any ideas why im getting an allocation error (which is what i assume is happening) on the entities NativeQueue ? The line (27) is attempting to access the queue, in the system, i have solved the longer term effect of the error, in such that it only appears once, and on the systems creation, it fixes the allocation, but it still leaves me with an ugly red error...
It looks like it isn't yet supported for a NativeQueue to be a property of IComponentData
not sure if tyou will ever be able to put native stuff in pure components
Hey, how can I add classic MeshRenderer component to an entity?
@dusk relic that doesn't make much sense - what you can do is add a RenderMesh component if you import the hybrid render package
Yeah, that being said one user on unity forums discovered that MeshRenderer is far faster than RenderMesh if the mesh is different on each instance
yea I think I know the post you're referring to - you have to be mindful that each RenderMesh is a shared component and will break chunks up accordingly - you may be better off with gameobjects with many different meshes
Hmm yeah, the thing is that creating GameObjects and doing calculations on them is awfully slow
However I know there is a way to add MeshRenderer, I just don't knopw how to
ok so you can probably add it as a component object
so AddComponentObject(theMeshRenderComponent)
oh great thank you
I've not tried it - not sure how it would get it's position etc... if you're after pure speed you may prefer to send buffers to gpu somewhat directly
I had a look on that one, but then I would not be able to have colliders right?
I don't see why not?
no but you can just have gameobjects + colliders or entities + ecs physics colliders and then build an array of the resulting matrixes with the meshes you want .. no?
Oh yeah, that sounds pretty nice I didn't come to think of that, thanks again
No problem - good luck ๐
Thanks, I will need it
hmm, has anyone tried to use a blob before in ecs? I'm trying to find an example since I'd like try and convert some sharedcomponentdatas to a blob asset instead
afaik theres not any official documentation on creating blob assets
yea - I was hoping there was some obscure example I could find so I can get started exploring it ๐ค
hey Timboc do you have any links to the RenderMesh performance thing regarding many different meshes?
that is a gut punch as I really wanted to make destruction a feature with ecs ๐ฆ
render mesh perf with different meshes is really "does SRP batching work with this?"
and do you really need different meshes or that amount of accuracy? I mean it's always going to be a problem doing destruction for any software
(I'm also tackling destruction)
dont need destruction at all, but it does add an extra element of fun
same, I'm doing the old all or nothing approach at the moment with some "hidden bits that were always there that smash off"
i can afford the draw calls having basic destruction on env there all the time, but for small objects i just swap them with broken version and send bits flying
the further i get the more I think I shouldve stayed in monobehaviour land
i recommend dots for actual production in constrained titles that really need it like rts or 2d
for general games i think we really do need the full dots editor and another year on top
until then... we can still benefit from it
it can accelerate our rendering of environments for sure, for example culling. drawing, all these should be fast enough that you can run your game in mono land but handle the rendering of lots of bits in ecs land
for this title i'm just going to see if Unity can accelerate a largely monobehaviour based game by rendering the level itself more efficiently, ie unity's own internal optimisations
maybe audio too? i dunno
I'm definately not going full in on it
i still want to go full tilt, audio and animation are really the two big keys that are holding me back and assuming the stars align, preview packages will be released sometime this year
but
i thought i could have my cake and eat it with destruction, it makes sense why there would be a slowdown
the destruction thing should be possible - afaik unity have a ring buffer for meshes etc
should be super high perf to calculate the destruction then generate the meshes, but I don't know how far along unity is with their api for mesh manipulation with ecs
its the intention you can do this though
it's not much different to streaming in 200k things on main thread under 0.2ms
not sure what a ring buffer is, but I was just using that nvidia blast plugin someone ported to unity
meshes premade in editor
but i had a hell of a slowdown with point lights
not sure at the end of the day if it was hdrp, my use case or ecs
give or take 1k unique meshes, only like 6 or 7 point lights were slowing things down
what did ECS frame time look like? it should show it on the debugger
did you turn off safety checks?
it was under the renderpipeline part of the debugger which was the slowdown
this is just using hybridrenderer?
yeah hybridrenderer and hdrp
huh... hmmm thats 100% supported :/
dare I ask how many objects? :D
1k shit i'm reading up sorry
i think like 1k unique meshes and more from multiple instances
6-7 point lights with HDRP (which is deferred by default) is nothing
for 1k meshes
(with mono)
I push way more at 60fps 4k res
with monobehaviour
on 4 year old hw
so this is good news though, it means you're probably just blocked somewhere
I was about to say, it sounds to me like this might not be a graphical issue, but rather CPU. Have you profiled, thelebaron? If you have premade models that you spawn in on destruction using ECS, you should be able to wreck a lot of stuff before you wreck your FPS, I believe. Though, in my experience lighting related lag (if it's that) can often be fixed by toning down what casts and receives shadows.
i do believe it was a shadow issue with the emissive radius setting
disabling shadows for those chunks isnt really ideal though but i guess more investigating is waranted
@amber flicker @safe lintel i dont think thats really true, about the nativecontainers not being compatible - it appears that the only limitation is that the initial struct construction cannot have its value set in a proxy properly, but the initialisation of the nativecontainer in a system works(with the container being present on the componentdata)
Does it really lose visual fidelity that much from turning of shadows on those?
Is this casting and/or receiving shadows?
Unless you're going for crazy photorealism, something like destruction chunks, which are there for 'juice' and probably won't be on screen for very long and is not something the player would normally focus on, are exactly the kind of things where you can easily 'cheat' and do the easy way and get away with it, visually speaking.
Well I wasn't doing any swapping of unbroken to broken, the chunks just form the entirety of the model and get enabled by physics when they take damage
Ah, yeah that sounds... suboptimal
When you make a system, can you put private and public variables into it like a normal class? Will that then persist through frames?
sure - useful for creating native collections and sharing them between systems
You can, but AFAIK it's not considered good practice for pure ECS.
The usual rule of thumb applies though: If it makes your code better (easier to make/read/maintain/whatever is important to you) and there is no reason not to, then go ahead.
Ok, what would you suggest for a method to gain access to a persistent nativequeue? I need it to be fully persistent, it needs to stay until the system stops running.
i need to iterate it in my system, pull out some entities and process them without losing the position in the queue
just public NativeQueue<> blah; initialized OnCreate, disposed in OnDestroy or whatever
ok, in the system itself?
Sounds like this is definitely a case where the rule of thumb applies and you can just put it directly in the system instead of slavishly follow pure ECS
Yeah, this is a central part - the queue defines what will get processed this frame, so that i can extend the delays between updates.
I quite commonly use the pattern System1 - public NativeQueue blah, then in System2 entityManager.GetExistingSystem<System>()` in OnCreate, then in the job of System2 pass through system1.blah
I dont follow the need for two systems?
well... I assumed that was the part you were struggling with? otherwise yes, just simply declare in the system like you would any c#
my problem i suppose is being self taught, one of the things i never read up on was how overrides work, and so i didnt realise i could put the variables into the outer scope properly, otherwise i likely never would have tried using the component data.
If you realize that's a weak point of yours, I suggest looking up some videos or other information sources about that specifically, they might point out some things you didn't know.
If anyone does need to put a container in component data, i think i know how you could... If you made a dummy component, like a tag, you could replace the dummy with the real one in the system at the same point you initialise its array. Judging by how i only got an error during the first frame, that should work i think.
I only just realised that was a missing bit of info as i said it, i should certainly read up on it
public class SomeSystem : ComponentSystem
{
private object _someVariable;
protected override void OnCreate(){
_someVariable = new Object(); //As normal
}
//remember to dispose any native containers OnDestroy, though
}
I was thinking that, is the nativecontainer properly disposed by exiting the game?
Preetty sure exiting the game free sup all the memory it used, yeah, but it's good practice to dispose of unmanaged resource you make, where you make them.
for that matter, systems can get destroyed even while the game runs and you don't specificalyl tell it to
yeah, i tend to apply the most appropriate of the allocation types as well, but to be honest being able to forget seems impossible, the compiler is really good at throwing red errors at you if you fail to deallocate hehe
Ooh, can i define somehow that i want a system to never be restarted then? Its crucial that the list stays in order and persistent...?
Yeah, they've made a big deal about making things work by default and tell you when you do Bad Stuffโข
That part at least, is done fairly well. I wish theyd put some more info in the code summaries tho hehe
most of those wierd big long named classes and components from ecs say nothing in the summaries
You could just make the variable static? That persists even if the instance is destroyed. Pretty sure people who have strong opinions about that kinda stuff would rip their hair out if they had to interact with your code anyway, but the point of styles is to help the developer develop, so if they become an obstacle, they are no longer useful.
Yeah, i do like being able to reconsider the styles if needed, where appropriate. What i am trying to do does seem like something which should be supported tho,
I just simply want to put all the entities into a queue, those that define my universe's background activity, and let them update their thousands of entities at a rate of like 50 per frame by using the fifo behaviour.
(would recommend against static only because you may have issues in-editor - I did at one point)
If i remember correctly, i tried statics, and the errors came saying they arent supported at all, even when accessing an external class static. I think they are non-thread-safe by nature.
Well, that is true, but I figured this was running on the main thread anyway.
AFAIK the 'pure ECS' way to do this would be to create an entity to hold the data
That being said, all my processing systems are jobs, but this one is not, it runs on main thread with as minimal activity, runs first, and defines who gets processed.
Thats what i was trying to do, thats why i wanted to put the container in a component data
Yeah, that's why I figured it'd run main thread and be able to use static. I do think there are ways to avoid ECS killing your system, too, though I don't know the mechanics good enough to say how.
An entity is never disposed of unless intentionally directed to be destroyed tho, right? So using an entity which has no other components does seem sensible, Ill try adding the tag instead, then changing the component in on create in the system, see if that works when i get home.
It seems, from how the errors acted, that the struct is capable of holding the nativecontainer, it just cant include the allocation part, so it exists if created by a conversion for one frame as an unallocated variable so the system gets upset. I figure i can overcome that with the tag... ill message here to let you know if you like?
I'm not sure what you mean, and I don't particularly need to know your results. Though, if you want to share, here is probably the better place, so more people can see them.
Hey, someone have the old MeshInstanceRenderer code?
It's not in the package anymore, or I just couldn't find it
they changed some names of stuff
its probably in there under a different name
Here is an interesting question...
If you have a one - use system, ie, its gonna change one entity once, then never act again - whats the best way to deal with this? if i make the system and then i have it simply stop working when the tag it uses no longer exists, it is still gonna be making an entity query every frame, which is really not necesary... Can i kill the system tho?
Like have it properly stop running?
Alternately, i could condense the logic into another system's on create?
does giving the entity query some OR requirements affect the speed of the query when you exceed 500,000 entities?
@dusk relic you need to install Hybrid Renderer now and it's renamed to RenderMesh => it still exists
I suggest to do a quick search for https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ReleaseNotes.md if you feel something is missing
the upgrade guides are pretty informative and you usually find what has changed
they literally renamed MeshInstanceRenderer to RenderMesh
systems and implementations evolve a lot on DOTS
it's been like that from the beginning
Yes, which is why Iโm asking for the old code.
The new one is too complicated for my neess
needs
they've actually made it simpler to use now
but I guess it depends if "simpler" means you can use your own code still
old setup had more boilerplate
injects and stuff
How is it simpler?
However, Iโm just trying to figure out how to get the mesh data to a system, since entities canโt hold mesh component
Or shoul i make a shared component which has a mesh field
data should be in components, not in systems
you know this demo? https://github.com/tertle/MeshDemo/
systems operate on data
I have updated that to latest entities locally, just havent pushed a fork for it
You are tertle?
I just meant that I've updated that mesh demo project myself to run on latest entities, upgraded the few things that needed to change
Ah alright.
I was also wondering if it would be wise to use an external renderer, since unityโs renderer canโt accept unmanaged data
i mean Mesh class
what I tried to communicate earlier was that components in ECS hold your data and systems hold your code/functions
therefore mesh data belongs to components
Yeah, each entity has a mesh and I want to render it
However I donโt think RenderMesh would be good, tertle had a benchmark which showed that traditional MeshRenderers were faster than MeshInstanceRenderer if the mesh was different on each entity
that makes sense
I dunno if that's even all that different if you draw instanced meshes for each unique mesh even without custom renderer
you get the benefits from the instancing and it probably always has some initial overhead
but if you don't need duplicates, you don't get those gains
I dunno what's their grand plan on ECS rendering, they renamed the MeshInstanceRenderer to RenderMesh despite it's still working the same way, so it suggests they either don't want to separate the instanced vs noninstanced meshes or that they just handle that on the same component in the future etc
@dusk relic That was only with a low number of meshes. When you have a lot, and especially when you can instance them the hybrid renderer is WAY faster
I've done tests with a few hundred thousands meshes just fine
@flat talon that was the whole point, if you got unique meshes, you don't get instancing gains
like, if you got level that mainly got few instances per mesh, you just pay for the initial overhead
I can't immediately think any such level tho ๐
I do know that the hybrid renderer is a temporary solution until they have a "pure ecs" renderer, but that is probably a year away or so
yeah, it's a stepping stone
(Im just guessing at the time)
I'd guess the full renderer would be last thing they'd do
something we'll see around 2022
I'm hoping we'll get some nice tools once Tiny C# gets released ๐ lots of stuff in there
we can use hybrid already and there are way more important things missing on other systems right now
like.. that DOTS editor ๐
yep! I hope we'll see the first version of that once they release Tiny C# ๐
I really really want that editor myself, more than anything
I hope we will be pleasantly surprised with the tiny editor actually working with all ECS world components
I was hoping they'd push out Tiny with the 2019.2 beta, perhaps they are waiting for RTM on that
I'd be disappointed if they still keep it separate as they said a long time they want to put these closer together
But I'm creating procedural meshes, each entity will have a different mesh
well the workflow for it looks great ๐ component types as assets, the component groups and all that
yeah, I really really want that especially, I don't like the conversion oddities at all
I believe the current workflow for meshes has a lot of memory copies, so it wont be super fast
it's like making DOTS feel like proper Unity again
current setup feels like a big hack
they'll probably do a new mesh API as well, slowly over the next 2-3 years they're pretty much DOTS-ify the whole engine
yeah totally
Will be nice to see ECS entities in the scene hierarchy ๐
Eh.. I'm probably just going to try and write my own engine then
Anyone fancy offering any suggestions id appreciate it!
(My entire setup hinges on me solving this problem, please help!)
Oh, and the poll is clearly very important to vote on hehe
@golden heron Place your queue as a field on your system?
heya, i replied on teh forum ๐
(might as well reply there as then itll be possible for people to see any useful answers ๐ )
Has AngryBots2 ECS from the GDC 2019 presentation been somewhere released? Could only find Mikes SpaceShooter
Lol I just noticed that this isn't the ECS version, forget that link. And it was released before the GDC 2019 presentation as well
neat didnt know that was released
Nyscersul nested prefab conversion should be in the next entities release(whenever that is)
Nice thanks
If i have a reference to an entity in a queue, is it gonna be storing a copy of the entity's data?
This is a standard queue, not a NativeQueue
Im getting this...
ArgumentException: All entities created using EntityCommandBuffer.CreateEntity must be realized via playback(). One of the entities is still deferred (Index: -94).
when i store my entity references direct from the spawning system...
Mmm Im unsure if you can use the ECB entity indices post playback
As it is just storing an int in relation to your queue of commands
And storing an entity doesnt store antly component data fyi
Storing an entity stores an entity struct that has 2 fields, an index and a version number
Also, for your queue question; you can just store a NativeQueue allocated as persistent on system start and dispose on system end. You can then, in jobs or on update use this queue. Just make sure to complete any jobs scheduled PRIOR to disposing. Ie hold a local varaible of the job handle you are using the queue in and complete before disposing
@golden heron ^
Thankyou for the detailed answer...
This is how I use persistent queues now
I tried to use a nativequeue and it seemed to result in the constant deallocation error, in spite of disposing on destroy, it seemed to really dislike its persistence extending beyond a few frames
I havent had any problem with it? ๐ค
i wasnt doing the complete tho
i dont suppose you have some code i could see how youve laid it out? Maybe copy one of your systems, delete everything except the struct/ethod definition headers and the lines pertaining to allocations of and deallocation of the nativeQueue?
Im on my phone atm
I've been trying to get this working for a week hehe
ok, in that case, can i ask your opinion on an alternate idea...
Basically: OnCreate() set local nativequeue
Update use local queue
Destroy job.complete(); dispose queue
Easy ๐
I was thinking of basically iterating over the system's entity array directly, its in a main thread component system. This should be fine?
(Thanks ๐ )
ill explain in just a sec, brb (sorry)
If you are wanting all the things you just spawned, use a tag and then iterate using a foreach job
Like, spawn them in with a tag, then after looping, remove those tags
ok, that sounds cool
i was gonna say basically, i havent tried yet, but i was reading that its possible to explore the arrays of data that the ecs system uses to store stuff directly, and that you can then directly access the array of all the entities.
Well keep in mind. You get an entity. Now what?
You dont have the data. You still need to get that
Using a foreachjob would at least have that data
And not mem thrashing
You can use the entity manager to request component data of a certain type from an entity.
You can. But it wouldnt scale well
You only need the entity reference to get everything, if you are in a component system anyways
you mean scale well as in it would be slow
?
Meaning that you are putting a lot of work on main thread
As well as not gaining the performance of the memory layout still
Ah, no, hang on a sec... i havent explained exactly why im trying to do this
That would be nice
sorry hehe
its basically a simulation of a universe, where 95% of the systems contain no players, and, as such, can be updated at a much less frequent rate, whilst entities inside player occupied systems would update every frame. The entities in the systems without players are unrendered, and never seen, so, even 5 seconds between updates is acceptable, assuming that the move is both interpolated, and steps are taken not to overshoot the destination.
So, this component system needs to pick and add a tag to a small number of the thousands of ai ships which would be moving around, trading, mining, to produce the games economy.
So, the component systems job is to tag its chosen ships for processing, in as quick and simple a way as possible.
JobForeach is still your ideal companion here me thinks
everything else, movement, turning, ai choices, thats all done in jobs in the chunk system
a small job where each job is a single entity getting its tag added? or a single job which iterates them all and does it all at once?
I usually for somethinglike this: have a foreachjob select what I want and add them to a queue, the pass that queue after the selection job is done and handle them as needed
Selection job usually is a ForEachJob for data filtering and the manipulation job is just a normal IJob
The reason
I can select what datatypes I am filtering for then also use that data to filter it further
Ie: TaskData{ =idle} add to my queue
I want them all to do something
listens carewfully
The point that you are isolating down to a local scooe usually something has gone wrong in a system design
By that I mean , I want to handle these objects constantly
Or in this case GIVE ME ALL ENTITIES
That is not a good plan if you are opting to not use the reason ECS is good
The more you can do in jobs the better
No matter how silly it may seem
Filtering, selecting entites you can do a number of ways
EntityQueries, Looping over entities matching tags in a job, etc
Well, i was thinking partly that the nature of my systems might be more stable if i am able to force the system to do this part (the choosing what to process) on the main thread, whilst it has other jobs which do not affect the same entities are running, like some of the systems ill end up with relating to player's system's maybe.
Like, i could run the jobs for the particle systems im planning, then the component system without having set the dependencies ?
If you halt main thread you halt the game.
The job scheduling will handle the overlaps fine
Ie I have a system for moving my ships forward 10
would that mean the main thread pushes on, or will it wait for each system to do ALL the systems work before the next system starts?
Then another system moving my ships right 2
Schedule these both it will know about the data overlap
If marked readonly it will pair them up best it can
If I am only reading data then all jobs read only of the data could in theory be ran in the same time interval and it will do it for you
But it would do all of this on separate threads
So the system starting is like .1 ms?
Or lower
As the tine it takes is how ever long the scheduler takes
so, it doesnt wait for each system's jobs to finish before starting the next system, but, it does check each job's data dependencies will allow the apropriate access at the time the job starts, before it allows it to complete?
Should be
I havent run into data overlap issues yet
Nor timing issues
And I had a simulation of 200k cubes rotating and orbiting a central point
Only possible with jobs
so if i wrote five systems, each system working on different entities and different data, then ran it, and was able to see the order the jobs completed, you'd find some jobs from system 1 ran after system 2, despite being sent to the stack before, but, if the data and entities are all the same, and dependencies are such that say system 1 is read-write, system 2 is readonly and system 3 is readwrite, i imagine they wouldnt overlap, theyd all run system 1, then 2 then 3?
oops, edits...
you can see the order the jobs complete in the profiler under Timeline can't you?
If. They are sequential in nature and you need them to work in an order. Put them in the same system
i didnt know that... ill explore that suggestion, thanks, vertx
Otherwise the order will be determined runtime iirc
I've not done much ECS, but you can definitely see jobs executing in the Timeline view normally, so I assume it's the same ๐คท
All systems written ALMOST should be independent of other systems
Ie I turn one off others woukdnt die
Also, i havent seen this mentioned, but its kind of suggested - we can assume that the system orders all jobs to complete before the end of a frame?
No
so jobs can last beyond the end of a frame?
To some extent. They SHOULDNT atm last too long. But Id recommend if you have a long job, call complete if using a persistent native container before scheduling a new job
Ive had a job run for 3 frames as it needed to
Ok, so generally its unlikely, but just in case be wary of large blocks of processing in the same job, i guess
So in the csse of jobs thst are handling data it is ok to schedule another job
so did that job need to be using something like yield? or was it just locking up a secondary processor on a worker thread?
The point I am making here is the natve queue idea would break if you were to be say unloading from your prev job
And your nee job started loading to it
exactly what happens is this...
it dequeues,
it adds to another seperate container...
it immediately requeues, in the same scope, function, method, even the same if conditional hehe
...why requeue it?
this queue represents the list of ships being processed.
take it out of the bottom, process, (mnove/turn/think) then pop it back in the top and do the rest.
its intended to make the system robustly able to scale its delays depending on the number of ships
I could be wrong but that isnt really Data driven ? As you have a list of these ships already? The entities component data themselves . Requeuing them sounds opposite of scaleable. But what ever works
(By the way, thanks for your patience, and help @solar ridge )
i need to keep some kind of way of knowing which one of the ships is next to be processed data driven would have me accessing the entire array of entitys per frame
Which is actually fine to do
i'd need to check values of timers
Totally fine
thats what i was doing first, then i was told that was bad...
Again you are in thread n land
hmmm... gimme a sec
Because in your queue system. A new ship is added. They get added to a weird part in the queue
Not necessarily the last ship
doesnt that break the fifo rules?
What I am saying is: ship 1 goes not is at the end of the queue
I add ship 5 I now have 2 3 4 1 5
Which may be important based on what is going on
But your scaling means that you jow have this massive queue of all ships
For what purpose?
As you should not really use any time in main theead to grab data
im trying to find a copy of my original system a sec
Main thread should be for passing info to jobs and little work as possible
Unavoidable with somethings
this is an older version of the system
actually... you know ill just rewrite it, and past that...
that system is broke hehe
(have a look if you like tho)
Err. TimerData each frame add using IForEachJob
Another job readonly to check for time desired
I dont see why chunks would be necessary here
its just the format i wrote everything else in
ref?
dats.Value += deltaTime
Then another job for checking if your times are usable
Keep in mind the ForEachEntity variant
If you need the entity
Inneed sleep now. I wish you luck
ok, thanks for help! Sleep well!
World.Active.GetExistingSystem<AISchedulerSystem>().totalShips = 1;
is this safe to use inside a job?
(ignore the value, its an example line)
is that in your job execute or when you initialise the job?
in the execute
its referencing a dependent system's data
system a finished before system b, system a is setting up the data for b
@safe lintel
i dont think you are supposed to be accessing other systems directly inside jobs
There must be some sensible way to have the systems pass data independently of the entities?
Im trying to have a system count the entities and then work out some timer stuff...
maybe do more if it works. Just seems impossible any time i want system a to be able to pass data to system b, it becomes a ballsache.
I think im gonna return to the timer checking and just use tags instead of value changing. At least i know i can make that work and not spend the best part of a week without progress - thanks to everyone who has tried to help tho, sorry if i have been dumb! hehe
you can pass data around from another system but at time of the job scheduling rather than right inside the job
is it possible to send events from ecs to monobehaviours without polling? e.g. when an entity changed so monobehaviour UI needs to update, without having to check hascomponent every frame
polling is faster than you think, but if you want a simple event listener, do the polling in a component system and pop off the event from that
sub using the entity as a id in a public dictionary or something
Thanks @safe lintel
@low tangle was that to me? Im trying to use the tags setup to limit the number of entities processed per frame, basically.
that was @hollow sorrel sorry
if your having trouble making a system, you probably just need to rework how you think about the problem
oh for your question you really want to use the components/entites as the data between systems
its kinda like having all the data out in the open for you to look at later
but if you really need to keep data inside a system but get it from another, really just use public fields and in the other systems grab that system using GetOrCreateSystem<>()
then keep track of it
its kinda like a manual version of the older [inject] api
@hollow sorrel entitys implement gethashcode so I've used that int as a key in a hybrid gameobject system
So you have been accessing the entities directly, june?
does it matter wether you use the Entity as key vs an int and doing gethashcode
dictionary uses gethashcode underneath too right
Also, with regards to your comment, my requirement is the other way around, to be able to put data into another system before it runs.
what kind of data
As an example, say the second system was receiving a count of the entities from the first system. Its more complex what i actually need, but say i wanted to have each job increment a counter in the second system.
i say, each job, i mean each entity processed by the previous system.
@hollow sorrel yeah its the same thing, I just store that int into a component, so instead of keeping a ref, I keep a key (I just needed a unique number to start with)
so system 1 needs x
system 2 produces it?
System 1 takes in all entities, counts them, does some checks of some values, then sends the data to system 2, which uses that data as constraints to define what entities it processes, and how.
and you cant store all that entity data into a component for the second system to pickup and use as its constraints?
Part of the data involves a "queue". I have explored both using timers to result in a clunky chunked setup which had each chunk only process 1 entity, that with the longest timer, and also explored trying an actual queue, and a nativequeue, im about to return to the original timer idea and try running some basic stats through to minimise cycles of processing, things like how many entities, whats the longest timer, and so on. The ultime aim is to have a background system of entitys, representing the objects in locations [edit]without players to be able to update less frequently, only say 30-50 per frame most of the time.
Ive got all fhe interpolation and stuff going fine.
Its just trying to find an effective method of queueing the entities in a persistent way.
oops - edits
in my systems I have to run a peak of around 1m entities all being processed and queued
to pull that off I worked with chunk itteration and a Buffer<Entity> for the actual queue
ended up simple enough in the end, basically just had to make sure the dumb way it would run would stop instead of overflowing
ok, can you directly access the array structure that the entities are held in by the system?
yep
How so? Where would i start? Some derivation of World.Active?
inside of a jobchunk
I probably used the wrong word
let me pastebin it
i dont mean the system as in an ecs system, i mean the entire system
does it need to leave ecs and be accessed from mb?
personally I'd still just use a entity with a buffer of entitys on it acting as a easy to get to queue
no, its all work done within the constraints of ecs systems, just want to know if i can access every entity in an array that exists naturally in the system, ie. without copying out
well yes you can go randomly get something from any entity there is
either entitymanager on the main thread or explicit component data type in a job
Ok, cool, so in a job which is scheduled via entity queries, onupdate is called once per matching entity/chunk? So its not a reliable place in those style jobs for stuff you want to run once per frame across everything?
they most certainty will one once per everything
thats what the jobs running on a query do
Hehe i think ima stop asking questions and start some code - thanks :)
Thanks :)
(I probably will ;) )
If a system receives, say, 200 entities matching its query in a system providing one job per entity, and so, 200 jobs, would the onupdate part be reliable in incrementing a counter - assuming the only change in activity affected by the counter was in the same update?
Also...
The onupdate needs to return a job handle, but, is there anything stopping me from setting up two different job structs by different names in the same system which then have different effects?
Ie, if counter < max, send first job, else, send second job
first job does activity, second job does wait timers and such
nope you can chain and should chain jobs
whatever makes it easier to make your logic work
var jobaHandle = new joba{
data fields
}.schedule(this, inputdeps)
var jobbhandle = new jobb{
}.schedule(this, jobaHandle)
return jobbhandle
cool thanks
is there any way to see the data going into the job at the point of creating it? ie, identifying which entity is the subject of the job?
if(shipsActed > 50)
{
var jobA = new AISchedulerJob()
{
DeltaTime = Time.deltaTime
};
return jobA.Schedule(this, inputDependencies);
}
else
{
bool wait = false;
var job = new AISchedulerJob()
{
DeltaTime = Time.deltaTime
};
return job.Schedule(this, inputDependencies);
}
I have this, but i want to check the component data to see what its timer is to know which job it needs to go into
for the shipsActed value?
no, its independent timer
if you have a stored reference to the entity just grab the data though the entity manager
also you dont need the () if your field initalizing a object with {}
but i dont have that reference? how can i get it here? the ai scheduler that drives the selection of the entity in the first place, the component, contains its own entity reference, so if i could just see the data that goes into the job
they are two different ways of constructing a object
I get you ill remove the ()
oh I see, so your trying to look at a component then branch based on a value in it, to run another job?
yes
why cant you have both bits of logic in the same job
intention is to be if timer = top 10% then process, otherwise if remaining ships to process is equal to the remaining ships, itll just process all the remainder
i was trying to minimise the jobs... if i can branch it, my "wait" job becomes...
you shouldn't need to minimise jobs
struct AISchedulerWaitJob : IJobForEach<AISchedulerData>
{
public float DeltaTime;
public void Execute(ref AISchedulerData AI)
{
AI.timer += DeltaTime;
}
}```
you just need to look at overall job time if you are meeting your frametime budget or not
okay so you have tons of float based timers that increase
so, forget about the branch if i need to see the data? put the branch in one job
then you need to run afterwards and look at the timers
to decide what you should do
likely you will be able to 'do it all' while looking at all of the timers
Yeah, the timers serve a dual purpose - later systems also use them to correctly interpolate the movement for an arbitrary delay
ok, so its basically back to my first design... :/
Thanks for the help tho ๐
well its really hard for me to understand what you are trying to acheve
Apologies, if it helps...
systems are byproducts of what you want to achieve using the data you have (or will create)
I tend to write out the logic and events in a document, figure out the simplest flow for what I want to happen. then start deriving component types from how things need to look for me to run simple querys on it
Its a space game, a universe, where only the systems containing players are rendered, and in view, everything else moves around in the background, and so can be updated infrequently to save processing, even as slow as once every five seconds per entity, as long as steps are taken not to overshoot the destination.
why are you trying to save processing? did you actually run into performance problems?
Because my final aim is to run multiple concurrent physics simulations depicting the multiple systems containing players, its for a server of an mmo game
how do you plan on running the physics sim, custom or the new ecs physics?
custom. Its gonna be handcoded minimal newtonian physics
good choice
well I'd say your going to need to very very cleanly make the component data state be as opaque as possible
because you either have to go full ecs, or have it mirror the actual physics sim world
i want over a thousand solar systems, each requiring "maintenance" on planetary orbits, ships to be moved, and attacks to be worked out. eventually, there could be 20,000 or more background objects to move, easily, if i achieve what i want
hence why this is important
well thats actually not even really a problem for ecs scale at all
like I said before, I process over 1m entities for a single system @1000 player target for my game
itis when you are also running the communications requirements for alll the connected players of an mmo ๐
at roughly 8ms on the server
I already push much more data I promise you
I also dont have the fastest pc to get the project started with
one of the best things about ecs is jobs on servers, that automatic balancing and multithreading does wonders for server cpus which have tons of cores, but not as fast per each
my dev machine only has 4c, but our servers we typically use have 8+ meaning it runs x2 faster by default
or x2 the cpu time to use as well
that extra budget is insane as well when it comes to raw pushing more and more systems and entities
1,001,109 entities, this is one of the benchmarks I run
what does your system queue look like? kinda curious how many systems manage that many entities
well I can't exactly show most of this stuff because of competitors (were a few weeks from releasing right now)
ok np
it does really good, but a lot of time at the scale ecs is letting me run at
most stuff just doesnt scale up to this number of things
like I'll pull a pdf of a technique and it works well at a couple of thousand, but scale up 10 - 1000x and it just dies
seems to take a few days to work out the single ecs way that pulls off the right performance
the system in question here I've tried to redo about 3 times now, and even with newer ideas its still isn't any faster
even with a full new way of logic / thinking of it
also main thread foreach's are dirt slow past 1000 entities in a query
I have a bunch of masks being used
and for some reason, they are interfering with masks outside the hierarchy
like
parent
child with mask
child with mask
child
parent
child with mask (doesn't work because of above masks)
child
shouldn't they only be affecting children?
and I do have a valid reason for using masks within masks, so that isn't changing
Thanks june.... interesting...
@low tangle do you have a ready simulation you could benchmark a small change with? I refer to your screen snippet, 159.34ms?
Try seeing if it makes any difference using a normal for loop. To the huge number sof entities i mean.
My system is taking shape slowly, atm, not able to test yet tho as need to rebuild dependent systems too
whats funny is that 160ms in one main thread system is only processing 1k entities
vrs the jobs running on the 1m
that system was just a skeleton I was getting started on testing some logic, its getting removed later. but I'm a bit busy on some vr fullbody logic right now
Ah ok, no worries :)
I'd be interested if you fancied sharing a quick description of your project?
VR sandbox with gmod and vrchat influence. but all at a larger scale per server (100 players official target but were aiming for 1k on beefy servers)
Nice, so a rpg/building kinda game?
trying to build a full collection of all the vr gameplay stuff you expect (guns, weapons, ai ragdoll physics) and cram it into a large sdk kit people can build with
Oh, isee, thats cool
that way people can make gamemodes that are full games and players can share super easily
while not having to make the entire vr kit for their game
Would you have any offhand suggestions for good reusable methods i could add to my mathematics package? it currently has a few options, like fromto returning a quaternion from two vectors, for example.
for the most part, I've found all the method's I've needed in there
I built it to emulate some of the missing functions from unity.mathematics, it uses the ecs types
sometimes in the weirdest spots though
like I'd expect it to be a extension but its just a static method now
I did a ray tracer in it the day before in a few hours and it was 100% mathmatics
didn't find other than a single method that wasn't in there
yeah, it seems easier to offer functionality that way, when you want to offer it without bogging down the objects you are acting on, i think.
yeah its cleaner and closer to gpu programing
mine is all statics
which is super nice
thats what theybsaid, based on hsls (or whatever the order should be hehe)
Hlsl? i dunno hehe
So, do you know, offhand, what i would put in if i wanted my component system to directly access the entity arrays? I tried to find it but got stuck. Its a componentsystem, main thread. I wanna try a few things accessing the heirarchy direct, if possible.
Specifically not cppying out the data tho, i wanna see if i can avoid the memory allocations there
@quick stream are masks IComponentData?
might be better answered in the #๐ฒโui-ux , only have basic ui experience personally
I tried there but nobody responded after a long time
figured this might be a better fit, idk
Its WORKING!!!
Is there anyway to store an entity with components as an asset for later use?
Like a scriptable object
hey so i have come up against an issue. i cant figure out how to have an array inside a component that is then passed into a job. i don't understand why this isn't possible.
@latent walrus what do you need to store this entity for?
To add to the above: Do you need to store values as well, or just the list of components?
Faldor, are you trying to use SomeType[] arrays or NativeArray<SomeType>?
Because the first shouldn't be possible for technical reasons, while the second is very much something you should be able to do.
well you can't use a native array in a component because it ends up being uninitialized. (Unless it is possible to initialise the native array in the proxy definition). You can't use a normal array unless you make a fixed array which is considered unsafe.
@tawdry tree What would the solution for be for using <T>[] then? Converting in an array loop?
You'd need to initialize it from a system, probably as you add the component. I haven't done it myself so I don't know exactly how it's done, but it should very much be possible.
okay, its just a pain, i was just going to set an array of actions for a bunch of entities to perform from the inspector.
it seems like it should not be that hard to simply set an array in the inspector, and then use it in a system.
With array of actions, do you mean Action[] or array of some custom type?
@solar hill not sure I understand your problem
- DynamicBuffer ?
- Scriptable Object that is read by a system (if you want to edit something in the editor?)
In this case it is just an array of vectors and an array of times for how long to move in that direction
+1 for scriptable objects, as long as you don't particularly need them to change (that much) at runtime
So you're doing something like an animation, kinda?
but if you want to read it in a job, you have to pass it to a dynamic buffer (or blob, might work with references - i never used this)
That could work. this is really just a little test project to test the use of arrays in components.
i mean it just seems so convoluted. I find it hard to believe that just having an array on a component was not considered a common desire.
Quick google search tells me sharedcomponents should be able to hold normal arrays
but that is what a dynamic buffer is
Remember that arrays are kinda complicated in terms of memory, hence why you aren't allowed to the the built-in language type (as they want to make it really hard to F that up but still have the perf of managing it yourself)
they cant, that's what I'm allready using. i cant seems to get them to work.
sharedcomponents are mainly used for filtering or if you truly have something that's shared and never / seldom changes - like the render system
they can but you cannot access the values in a job
well it is shared, that's actually what i was using it for, many entities performing the same actions
Have your tried these dynamic buffers? I haven't touched them so can't really say anything about them, but from what sngdan says it should be an option?
they are not settable form the inspector which is very annoying
Wouldnt using the entity as a prefab work?
how would that help?
Ie the way HelloECS spawns in the sample
I have to run now, but I think you might want to specify your case and put it in the forum (and explain exactly what you want to do i.e. edit values of array in editor, access in job, per entity or shared across many entities, etc.)
Storing them for later like a scriptable object...
I think sngdan is right, explaining the desired effect would help a lot
As we all use things differently
it does not sound difficult to solve but your use case needs to be as specific as possible to get a good answer
okay cool, thanks for you help, i will make a foum post
i think the ecs example 08 spawn and remove has exacly what i am lookng for in their rotation speed proxy. i think i can have my data as an array and i can convert from that array into a native array in the proxy script. thus allowing me to give the array an initializer.
When in doubt, look at the samples. Albeit some of them are... not the best
Particularly one of them with a queue
ive noticed some unusual stuff... i kind of had a moment of "huh... is that how your supposed to do it, sure isn't how i would have"
Some of them are proving a concept not proving performance
still it can easily give people the wrong idea
The major thing it is demonstrating is that there is not one way to solve the problem
It is highly dependent on your needs
So they show multiple ways
Some more performant continuously where as others may be better in specific scenarios
(Thanks for reactions guys :) )
if you are still searching...
@potent cape Thank you. ๐
i just was looking for the same one and remembered you looked for it too
Anyone able to help me with a localtoworld matrix? Mostly just making sure i understand what its values are
It represents a position and three vectors, defining the facing direction, is that right?
Shouldn't a local to world matrix be a transformation matrix that transforms from local coordinates to world coordinates? ie localtoWorld*localPosition = worldPosition
curious if anyone here might have other insights on this (maybe some unity folks?)
hmm, might try asking that in the thread joachim started for scene conversion, i havent ever seen non monobehaviour classes referenced as part of the hybrid workflow so i have no idea if this is something that is slated for later or not planned at all
So does that mean i need to change the vectors held in the localToWorld to affect orientation, and the translation to change position? Or is the position you mean the property of the localToWorld? i think it had that as a property
I assumed that part of the matrix was actually part of the numbers in the matrix? My question mainly tho, is what do the numbers in the matrix mean? I am trying to use one, but need some definitions of what it is
I thought i understood but guess not
My bad, it seems the unity.transforms package manual covers this :D
What are peoples thoughts on using ECS for production?
(I know that it is in preview and that means officially it is not supported for production)
imo its pretty solid for pure number crunching, it still lacks a lot for features though
fantastic already
using it in prod myself
reactive systems are still pretty not ergonomic, but the trade off for system separation from data makes it worth it. At the moment I can keep the entire logic of my game inside of my head because of how simple each system is
its super nice for reasoning about things
Does somebody had also problems running the hybrid renderer with LWRP and SRP leads to rainbow flickering visuals?
@crystal zephyr If you're using the Convert to Entity it might be that it creates one renderer there as well. Try disabling the one you have on your GameObject in that case.
@mystic mountain I using Convert To Entity. But in this case I have a prefab referenced in a spawner. This prefab gets converted to the entity and I use EntityManager. Instantiate. And the ConvertToEntity is set in this case to Destroy GameObject. So I have nothing to deactivate ๐ฆ
to the bugreportmobile
i'd second @low tangle take. using it in production already, though some things are certainly still pretty awkward
i'm tending to keep a lot of things in regular ComponentSystems and hybrid until the tooling improves
and not a lot of the subscene / convert to entity stuff. @frosty holly i maybe be wrong but i think they feel too early along and it will just be pain being that bleeding edge. but the hybrid stuff works for now and you can get things prepped and as the tooling improves it should be pretty straightforward upgrading
That seems to be the overwhelming consensus - you can very much start using jobs and systems for most projects, but we're still a good bit away from most projects being possible to do in pure ECS. It seems to me like there is a few project types that can utilize pure ECS for at least part of their logic, though.
Yay! correctly delayed ai movements, with basic momentum simulated movements on the non-skipping ships too :D (fps isnt great as pc is slow)
well, that was unexpected ๐
heh ```Undo/Redo, unstable - will likely crash
Copy/Paste between graphs, unstable - will likely crash```
I could do without undo for a while but copy/paste is pretty bad
but yeah, it's early
kinda wierd if the editor build is a custom build? why not roll it into the beta
what do you mean?
the beta is only 1 version later than a14 anyway.
@safe lintel ah, you mean the link on the thread
yeah
ah
would expect b1 to work with that
unless there's some dependency with ugui that's not handled yet with that package
"We share this build to be as transparent as possible with our process and get your early feedback. This is an opportunity for you to see how DOTS and Visual Scripting are evolving and participate in the discussion."
I want this for everything Unity does
while I want that too, the issue with this is that so many vocal and ignorant users don't understand what alpha is
they call out the whole engine being trash that breaks in every direction
and many are straight up mad at Unity for daring to do even previews
wanting only final things (yet they could just as well wait for those final things)
in modern age, you just can't make everyone happy
I doubt that's new
they could do some "register for alpha/beta"
I suspect it's been like that forever
if you have to file a form, even if it's automated process, it would leave some entitled individuals out
Just, we have better channels for loud ignorance now
as many of such can't be bothered on filling forms ๐
getting alpha level access for all users hasn't been norm in past
usually it's been only available for select people
It also makes them literally legally agree to the fact that
THIS PRODUCT IS IN ALPHA/BETA/EARLY ACCES/WHATEVER AND WILL LIKELY CHANGE/BREAK/HAVE BUGS/WHATEVER AS ITS BEING WORKED ON
Won't silence all the voices, but gives a very easy to to shut them up if they get too obnoxious
The form would be a great idea
probably doesnt help that many companies use alpha/beta testing as just a marketing ploy for their products
Same issue as with early access games - They definitely have their place, and a lot of games would not have existed in their current form without including a large amount of users as early as they did, but there have also been some bad apples.
https://forum.unity.com/threads/dots-visual-scripting-first-experimental-drop.677476/ Looks like they've dropped in an early preview of a node based editor for their DOTS workflow
@coarse turtle we were just discussing it ๐
Haha, maybe I missed out on the discussion here
is there a EntityManager version of ComponentDataFromEntity?
ok nevermind GetComponentData, was confused cos rider was not highlighting it the same as other stuff
I feel like the very type of people who complain loudly about Alpha/Beta features not being done are the same people who would complain loudly back when Unity really didn't open up and features just appeared out of nowhere, and were rife with issues due to not being vetted by a larger pool of users than a handful of select companies
The main thing needed from Unity is a clear and somehow accurate estimation on features release dates. With that info, you know you if you have time to do it yourself or wait a bit for Unity to do it and in that process, prevent a lot of frustration of doing something they already did
(I'm not saying estimation is easy because it's not)
Hey all! What is the best type of system to use when it handles only one entity, like PlayerInputSystem?
Is it worth it to use as a job, or do I simply run a ForEach?
There is a SetSingleton API
ah,
what kind of job to use when going over the Singleton Entity?
It is not explicity a singleton, but as it represents the player I guess it is ever only going to be one
I think IJobForEach<PlayerInputComponent> in a JobSystem would work fine
Ok. I just remember someone saying that using jobs create a tiny overhead, so it was not recommended to use with small systems. I just wanna be sure
Mmm. they are probably right. The input shouldn't need to be in a job explicitly. You're probably okay with just a regular ComponentSystem instead.
Yeah, putting it in a job is probably overkill for what it is doing. Sorry for any confusion
What is this SetSingleton?
the scheduling for a job is a super tiny overhead
if its fully ecs then a jobforeach should be a no brainer
but if its not, a regular entitys foreach for speed of implmentation is what I go for
Im trying to learn pure ecs
So should I go for JobForEach?
it throws a exception in the editor if you spawn more than one (helpful for debugging broken logic)
jobforeach's are super nice and should be your default if you can make it work for the logic you want
SetSingleton is just some api sugar for only allowing a single type of an Entity to exist. It allows for a an easy EntityQuery via entityQuery.GetSingletonEntity()
yep
theres no buffer accessor for it
but there is a componentdata accessor
and you can always entity->buffer like any
So if I want the player to be unique, setting it to a singleton is more efficient?
And another thing, I tried to use a empty component as player tag, and got this:
ArgumentException: ArchetypeChunk.GetNativeArray<PlayerTag> cannot be called on zero-sized IComponentData
I need to use [RequireComponentTag(typeof(Hungry))]?
I'm not sure how the last part ties into the other part of your statement
I created an empty component as a tag for the player, but when I tried to schedule a job that required it, I received the error. So I searched and discovered that I need that attribute on the job
But now Im facing another problem, when I hit play my object vanishes
It has the ConveertToEntity monobehaviour and if I go to the entity debbuger, it appears there
ah i see.
But not on the Scene or Game windows
What setting do you have on the ConvertToEntity? is it convert and destroy?
also if you're planning on doing an ECS conversion, you should not expect the GameObject to stay inside of the hierarchy when running
do you have the hybrid-renderer package installed?
I forgot the hybrid package ๐คฆ
I CAN MOVE THE PLAYER
Im so happy right now
Thank you guys for your tips
That would be all for today, but you will see more of me ๐
Congrats
is it not possible to inspect NativeString? just jumping onto 2019 and latest ecs for something quick and could've sworn i did this before ๐ค
empty components should not be in the ref component name part of a foreach and for a jobforeach they should not be in the generic type slots, instead as a requiretagcomponent attribute before the job @safe gate
has anyone worked on applying rotational inertia in ecs?
specifically, id like to be able to apply the lerping quaternion as an acceleration and then have the ship continue turning if the controller stops turning.
Doing so independently in three dimensions wouldnt be a problem, if i had a function to break the quat into eulers
Please @me if you respond :)
you should have a second component that is a component that decays to zero
then modfiy and create the main rotation and copy it over when applying input
and always have the main actually applied rotation decay constantly in a different system (can even throw a bool in there and update it for turning the decay off without removing the component) or use a tag [Decay] and remove / add it to do the conditional decay
@golden heron
Thanks @low tangle what method would you use to apply the decay? I was using a drag multiplication with a cutoff at tiny speeds for the movement, i was trying the same but wasnt able to work out the right approach
spherical lerp * delta time * angular rate you want to decay at
make sure its lerp thats clamped so you dont go past
lerp to zero basically
at a rate you want to decay at :)
bonus points if the 'mass' of the ship is related
I do want it to be
Well... Its gonna be quite a complex scenario...
The result will make it quite realistically possible to calculate both the variance in turn rate on each of the three local axes, and the centre of gravity.
In a nutshell, i've mentioned its an mmo, but the final design will be using ship components put together into a customised design made by the player. If you place objects that extend outwards greatly in one dimension, the rate that dimension turns around its axis will be reduced, unless of course the object which is extending is very light, like a sensor array. I want to model the appropriate differences between the ships like that, and should be able to do so easily, with ecs, mostly because my gameplay wont involve gravity as a force. So its basic newtonian motions across the board.
That being said, would it just be easier to use the rotationEulerXYZ component ?
sure you can do it that way
also a module could have basically rca thrusters and help with movement on that axis
rca ? sorry im not good with abbreviations hehe
also look into solving the turning forces on a per ship basis so you can save the effort of calculating the ships stats all the time
sorry rcs* I put down a audio jack type
https://en.wikipedia.org/wiki/Reaction_control_system
Oh, the entire ship is gonna be "fixed" at load time, amalgamating all the dat into one set of centralised data.
Yep
also I'd highly suggest not calling it a mmo, but totally aim for that level of size
think very carefully about how you will do your network scaling
I wanna make the final result go through first the stat amalgamation, then merging the meshes.
servers are expensive as well so keep in mind both bandwidth and cpu time on server as those are the two most expensive peices
So the designs are in fact one piece in the games view, for ease.
yes thats exactly the right way to plan it
Yeah, im planning for initially to run it from home... but im sure once its going it wont be hard to have it fund its own requirements.
always start with the simplest implementation first before laying on merging and what not. ecs is very very good for keeping it separate and easily tying in new logic and data without touching the other systems. Its a big strength and in action super satisfying
I also have already had some networking set up - a simple 3 ships in an empty system test, using my own networking layer :D
(That was easy compared to ecs :P )
its easy at first :)
hard part is scaling it up and keeping it from spaghettifiying
(The vid is my red ships driven by intervals - these represent background ships - and green is the insystem ships, hence updated every frame and more in detail)
It naturally scales too... It knows how many frames to skip, for example, from the second frame onwards, in spite of that sometimes being quite a few - at 5000 ships it skips approximately 100 frames per move.
But, uses lerps and no overshooting :)
Have you tried the rotationeuler component? Does it completely replace the normal rotation, or just offer an extra layer over quats?
dont think I've used that one, all my rotations and positions are inside of my own custom component data due to needing full control and not wasting time computing a transform localtoworld
So you dont have the normal rotation either?
just a custom one yeah
I sometimes use the transform system for some smaller systems
but my main ones all drive custom ones so my pipeline is clear
How does the custom one work?
componentdata struct with a quaterion and a float3 in it
8 diffrent other types modify it and utilize data from it
about 12 systems touch it
And you have turned off the transform system that manages localtoworld completely?
transform system only runs when you use those components, I'm not so they dont
ok, cool... So your custom one, how does it replace the standard rotation completely? Surely it needs one of the original components to apply the rotations and stuff too? Or, is that sent direct to the mesh renderer?