#archived-dots
1 messages · Page 189 of 1
one option is to not make them exclusive
if the rest of your systems behave as expected, it shouldn't happen right? Relying on exclusivity to sort out the issue comes with its own problems.
yeah guess you are right
I think its more of a design thing
so I would like to prevent the game designer from adding multiple attacks
I'm an "anti state machine" person and I recognise I don't have much company 😅 - I find them useful conceptually and almost always problematic in practice.
I think it's reasonable to prevent a designer from adding multiple - but I'd say you can easily do that through editor tooling. A dropdown for example.
guess I should handle it through authoring components which add either one of these
it's easy to e.g. have all your authoring components extend from a class that checks the gameobject only has one of them in OnValidate... not sure I'd pick that particular approach but that's how easy it could be.
I have a hard time not thinking in states. I mean even scenes or menus are "states"
Thought more about one authoring compenent to rule them all (with an enum)
That works too. I have never ever seen (or written) a state machine in the wild that didn't end up having a mixed state or hidden state of some sort. Even menus in any more complicated than a game-jam sense. Anyway.. don't want to start a tab v spaces thing here 😬
I have definitely have an opinion on tabs v spaces 😉 On state machines, not so much. I rather use them because I dont know of any better solutions for some cases. Would be eager to learn how to handle it differently though but I dont want to steal more of your time 😄
Thx for your help again
My approach is 1) simplify -> iterate -> simplify - do you really need different data? 2) Make a matrix of exclusive & mutual states - try to turn this into a hierarchy and choose the best method for that data - e.g. usually Tag, bool or enum.
When you start it's easy to go straight to Melee Attack, Ranged Attack & Magic Attack but after iteration I it might look a little more like a single ICD with e.g. float attackRange;, Entity effectPrefab; int AnimationIndex;
Iteration is actually a pretty good point. I guess I tend to overthink the architecture and plan ahead quite a lot. Now that I started to actually implement some stuff there is a lot of "bad" ecs code which is not extensible but on the other hand it is pretty quick to refactor it.
Yea with practice I think I'm getting a little better but I think it's really hard to get it right first time (or second or third for that matter).
would be curious what other regulars like Sark & Psuong think of all this though - always good to get other perspectives for balance.
in an IJobChunk is there a method to get the Entity struct that an IComponentData is associated with? Or would it be a better idea to just have an Entity field within the IComponentData that has it set (when the Entity is created and data assigned)
var entities = chunk.GetNativeArray(your_entity_type_handle);
for (int i = 0; i < chunk.Count; i++) {
var yourEntity = entities[i]
}
that's the idea behind getting an entity that's associated with an IComponentData in IJobChunk
ah thanks! yea I saw the GetNativeArray and was starting to try it, but what if I needed the actual Entity struct with index and version in it? (or does that suggest maybe I shouldn't be depending on the actual Entity struct)
I was using it as sort of an identifier (though I know the index changes potentially if entities are removed)
You pass EntityTypeHandle, same way you do with ComponentTypeHandle
hmm well if you access yourEntity you can access yourEntity.Index and yourEntity.Version also 🤔
Then access it like psuong's example. That is the entity associated with the component.
To your point, yeah I'd say that's pretty spot on. Write an implementation, ask myself does it fit my needs for my work - yeah? Move on. Revisit if the needs change later down the pipeline based on player feedback etc. I don't really think about the "future proofing entirely" aspect - since I think that depends, you can work towards a goal and go down a path, but needs and goals change over time
Psh, not me. I write everything perfect the first time. /sarcasm
😛
And regarding the state machine stuff, the idea behind the state machine is to associate a bunch of data and behaviour with a state, right?
Isn't that what ECS already does with components and systems
I wouldn't try to go against that unless I ran into performance issues
In short, SystemGroups as states ?
With a RequireSingletonForUpdate(chosenStateComponent) component to enable/disable system groups ? and you swith the chosen state at runtime ?
switch*
swap*
one more Q 😄 so with ComponentDataFromEntity<AINode> in an IJobChunk you use Entity to index into it, is there any way to iterate over all of them, or am I better off first copying to a temp NativeArray with ToComponentDataArrayAsync<AINode> and then writing the changes back in a second job?
iterate over all of the ComponentDataFromEntity? @fathom trout
Yeah, but you need to require a query not a singleton, or you could never have a second entity with the given state
Using ComponentDataFromEntity is pretty slow if you're doing it a lot. Better to use an acceleration structure if you can
@fathom trout is there a particular reason you're not using Entities.ForEach over IJobChunk? sounds like that'd be the easier version of what you're trying to do
Oh right, I was picturing like a Menu state. But you're right wouldnt work for AI agents for example.
Thanks for the insight
I see, yea in an IJobChunk for updating AI I was planning to loop the valid AI Nodes and then assign a node to the AI.
I am currently using Entities.ForEach but need to modify the Node also (when the AI selects it) and wasn't sure if the way I was doing it is correct, so started investigating IJobChunk
Is the AINode on the Entity?
basically with the Entities.Foreach afterward I was doing this... Entities.ForEach((Entity e, int entityInQueryIndex, ref AINodeUser nodeUser) => { //since we modified the user in the prior job using temp array //we need to set it here.. hopefully the index is correct! nodeUser.User = nodeUsers[entityInQueryIndex].User;
but no idea if that index will always be correct
yea I guess if you had a structural change before this job finished - the entityInQueryIndex might change
generally you wouldn't need temp arrays or buffers, you can just modify the component directly
dunno if you're doing something fancy to populate nodeUsers
A structural change would force any running jobs to complete immediately before it happens though
ah true
hmm it's because I do Entities.ForEach Brain but since the AINodes are not on Brains (they are separate entites) I thought I had to use ToComponentDataArrayAsync<AINode> prior to the ForEach to get the AINode data
but then if I want to modify the data in that array, its not going to be on the original Entity
& about the structural change, is that why I'd want to use an Entity CommandBuffer ? To defer any change until it is finished re-assigning any of the modified data?
sorry still not sure what kinda logic you have set up
so you populate a new list of nodeUsers which are new structs, not living on any entity at that moment?
and then sync that up with the entity versions of those with the nodeUser.User = part?
also yeah you'd want entity commandbuffers (ECB) to defer structural changes, but structural changes only means adding/removing components/entities, if you're only changing component values that doesn't count so wouldn't be necessary
var validNodes _nodeQuery.ToComponentDataArrayAsync<AIValidNode>
Entities.ForEach Entity e, ref Brain brain
//code for considering which valid node to pick
for( i to validNodes.Length )
//if picking a node
validNodes[i].User = e; //set entity as user of node```
something kind of like that, so I'm only setting the user value
The array and your foreach are guaranteed to match up only if they have identical queries
AFAIK
ahh, that might be what I hit, I started getting index out of range errors when it got a bit more complex
(thus I started investigating IJobChunk) 😄
I think what you want would be to do _nodeQuery.ToEntityArray AND _nodeQuery.ToComponentDataArray. Pass both into the job.
Then you can match the entity to the component without using CDFE
wouldn't CDFE be better here
ah
If you are very concerned with speed it's better to do acceleration structures
is doing 2 .ToArray on queries better than one CDFE tho
seems like that'd be twice the work
but could be wrong
I think copying two arrays once is better than doing one CDFE for every single entity in the query, I think
thanks for all the clarification, giving it a try now, acceleration structures, is that similar to how the boids example is setup with the cells etc
basically minimizing how much you iterate over
Of course you should profile to make sure, but that is my gut feeling
They're copies. So you can write to them, if you want to write back to the original components you have to use _query.CopyFromComponentDataArray
cuz if not i'm just imagining something like
var nodeType = GetComponentTypeHandle<AIValidNode>();
Entities.ForEach((Entity e, ref Brain brain) =>
{
//code for considering which valid node to pick
for (i to nodeType.Length )
//if picking a node
nodeType[i].User = e; //set entity as user of node
}).Schedule();
and then you'd be setting it right away
no need for temp arrays
Oh I goofed and thought he was writing to the entities in the foreach
That seems way better
Also didn't realize you could use ComponentTypeHandles like that in a Foreach. I guess that makes sense though
or maybe reverse it, loop over AIValidNodes and check Brains instead
i think i'm missing something cuz i don't think you can do nodeType.Length but yea
You could get the length from the query
Hmm, but can you get the type handle from the query?
I think if you're targeting a specific archetype you would have to do it my way. If you only care about that one type
Your way is better
yea it depends on how you're picking nodes inside the Entities.ForEach
CDFE is basically a lookup table into that component type
so it's not just specific entities, it's all entities (if they exist)
same usage as a dictionary basically i think
i'm a bit rusty with ECS now so prob not giving the best advice
nice to see more ppl are picking ecs up now tho
at Facebook.Unity.MethodCall`1[T].set_Parameters (Facebook.Unity.MethodArguments value) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.MultiList.CalcExpandCapacity (System.Int32 current, System.Int32& needed) [0x00000] in <00000000000000000000000000000000>:0
at Game.Systems.Conversion.PrefabRegistryEntryAuthoring.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.Convert (UnityEngine.Transform transform, System.Collections.Generic.List`1[T] convertibles) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entit<…>```
What the actual fuck is Facebook doing in my stacktrace... 😱
Anybody seen something like this before?
yeah
this is in the middle of my game
not doing anything login related
Game.Systems.Conversion.PrefabRegistryEntryAuthoring.Convert is this code:
public void Convert(Entity entity, EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) {
if (TryGetComponent<TrailRenderer>(out var trailRenderer)) {
gameObjectConversionSystem.AddHybridComponent(trailRenderer);
}
if (TryGetComponent<ParticleSystem>(out var particleSystem)) {
gameObjectConversionSystem.AddHybridComponent(particleSystem);
if (TryGetComponent<ParticleSystemRenderer>(out var particleSystemRenderer)) {
gameObjectConversionSystem.AddHybridComponent(particleSystemRenderer);
}
}
}
AddHybridComponent appears to use a MultiList internally
If I remember right AddHybridComponent only works on gameobjects. Could be wrong about that
There's not much documentation on it
It works fine on Android for some reason....
And it works fine the first time This conversion system is run
I kill the app and open it again and then it will blow up with this error
so weird
almost as if something gets corrupted
I only tried to use it once and I remember it just not working at all on components but working fine on a gameobject, maybe I was just confused
Is there something AddHybrid does that doesn't work with AddComponentObject instead?
is it possible if you manually destroyed the gameobject before destroing the entity its attached to through the companion system?
i think addhybrid just links the lifetime of the gameobject to that of the entity(and vice versa) @zenith wyvern if you did addcomponentobject it doesnt track what gets destroyed at all
i dont use it though, dont trust it since the samples still say its super experimental(though they say that about animation too :D)
Really? Meaning if you destroy an entity it will leave the hidden components added with AddComponentObject behind?
From the documentation when you use AddHybrid you are meant to just ignore the existence of the gameobject altogether
well lets say you AddComponentObject(transform) to an entity, if you destroy the entity the gameobject that transform is attached to still lives on, and vice versa
ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
at System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) [0x00000] in <00000000000000000000000000000000>:0
at System.Array.Resize[T] (T[]& array, System.Int32 newSize) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.Conversion.MultiList.CalcExpandCapac<…>
For some reason it's resizing and then realizing, oh no, there's different kinds of elements in the array?
I just tested it, it seems like any objects added via AddComponentObject are destroyed with the entity
Oh I think the Facebook.Unity.MethodCall`1[T].set_Parameters (Facebook.Unity.MethodArguments v might just be the uncaughtexceptionhandler looking hella weird at the top of the trace...
@zenith wyvern i would assume an otherwise unattached object but not necessarily a gameobject
I guess the results depend on if you're using "convertandinject". If you destroy the original gameobject after doing AddComponentObject, the entity still has the component on it (meaning your systems can still access the component)
But if you use "ConvertAndInject" it still syncs up the component to the original object
And if you THEN destroy the original gameobject, your entity still has the component.
So it seems it's still hiding a gameobejct in the background somewhere, just one that you're not meant to see or mess with
AFAIK HybridComponent does the same thing except it syncs up transforms automatically
dots netcode question : any bandwith experts out there that know when to use a ghostfield instead of rpcs to sync values ? example : a unit can have 3 items (byte itemSlot01 ,02,03). Items change only rarely (maybe once per minute on one unit, when user is dragging it onto the unit). Would an rpc whenever a user assigns an item beat the itemslots being ghostfields ? Or are ghostfields optimized that they don't even generate traffic as long as values don't change (i guess that's the real question) ?
(Imagine a game with 10 players, each having 10 units)
I answer myself 😄 https://forum.unity.com/threads/dots-multiplayer-discussion.694669/page-5 > if mode is set to static, ghosts that don't change wil not get sent apparently
Does anybody know how to convert referenced GameObjects to entities in GameObjectConversionSystems?
conversionSystem.GetPrimaryEntity you mean maybe ? or maybe you're looking for IDeclareReferencedPrefabs
yeah but IDeclareReferencedPrefabs only works with IConvertGameObjectToEntity I think?
I am using GameObjectConversionSystem as this seems to be the preferred way as every unity conversion is using it
this might help you : https://gamedevbrothers.com/programmatically-linking-entities-gameobjects-without-the-converttoentity-component/
Here is a way of programmatically injected the created GameObject into an Entity without using the ConvertToEntity component.
usefull helper functions they wrote
Just found that GameObjectConversionSystem also has a DeclareReferencedPrefab method. Now I just need to figure out how/where to use it
How would you go about having multiple random values? I've done this before but it doesn't allow for more than 1 random value per ForEach
Random random = new Random((uint)UnityEngine.Random.Range(int.MinValue, int.MaxValue));
Entities.ForEach((Entity entity, int entityInQueryIndex) => {
random.InitState((uint)(random.state + entityInQueryIndex));
as using the same Random variable multiple times just gives you the same number.
you can change the seed provided to Random
for example feeding it with Time.deltaTime
and new mathematics package has its random, I dont use the UnityEngine one anymore
Wait do you mean you want an array of randoms ? Or maybe use your already available entityInQueryIndex to retrieve next on random
What I want is 3 different random ints
3 for each entity, right ?
Pretty much
call nextInt() 3 times ?
I would but that would give the same number.
var deltaTime = Time.deltaTime;
Entities.ForEach((Entity entity, int entityInQueryIndex) => {
var random = new math.Random((uint)deltaTime);
Debug.log("Random: " + random.NextInt(yourMaxValue)));
}).Run();
Try something like that ? Not tested, I dont guarantee syntax or result :p
I would even try to init the seed only in onCreate, should still give different results
calling .NextInt() 3 times
Gives an error saying "seed must be non-zero"
dt is generally going to be less than 1, so that will always be zero. Try dt * 1000.
😛
But with random you're usually meant to pass in the seed once and re-use random from then on. Continually reseeding gives a pretty high chance you're going to repeat values early and often. Unfortunately using the same random over and over between jobs is not standardized and very annoying.
There are some solutions on the forums
Yeah with this I always get 0 from NextInt
var elapsed = Time.ElapsedTime;
uint seed = (uint)(elapsed * 1000);
Try that
Still not the right way to use it but it should give slightly better results
It does give better results but still the same number for both my NextInt calls.
You're seeding random before you pass it into the job right?
If you're seeding it in the foreach then yeah you're going to get identical results since it will just reseed it on every invocation
So I should do Random random = new Random((uint)Time.ElapsedTime * 1000); before the ForEach? Tried that but gives the "seed must be non-zero" error
Come on man. What do you think "elapsedtime" is on the first frame?
oh god-
Just add 1
it somewhat works but every entity has the same seed which is not something I want.
What do you mean every entity has the same seed? If you're calling "NextInt" once for each entity then they will all get a different value
you could use the entityInQueryIndex to generate a seed per entity
Since the seed is made outside of the ForEach every entity has the same seed.
just add your entityInQueryIndex to the seed so you will have a differnt one for each entity
That seems to work better
Does anybody use GameObjectConversionSystems or is anyone just using IConvertGameObjectToEntity? I am having a hard time figuring out how to resolve referenced prefabs 😬
Does it not work if you just call DelcareReferencedPrefabs(go); var prefab = GetPrimaryEntity(go);?
I've only used IConvertGameObject but that is how I imagine it working
DelcareReferencedPrefabs can only be called from the GameObjectDeclareReferencedObjectsGroup
which is why I added another system in that group calling DelcareReferencedPrefabs
but the resulting object which is instantiated later on is just an empty entity 😕
This is what it looks like atm:
class WeaponReferenceConversionSystem : GameObjectConversionSystem
{
protected override void OnUpdate()
{
Entities.ForEach((WeaponAuthoring weapon) =>
{
DeclareReferencedPrefab(weapon.Projectile);
});
}
}
class WeaponConversionSystem : GameObjectConversionSystem
{
protected override void OnUpdate()
{
Entities.ForEach((WeaponAuthoring weapon) =>
{
var entity = GetPrimaryEntity(weapon);
...
DstEntityManager.AddComponentData(entity, new ProjectileAttack()
{
Projectile = weapon.Projectile?CreateAdditionalEntity(weapon.Projectile):Entity.Null,
});
Yeah given what you just said that's what I figured it would have to look like. I was looking for an example in the packages, no luck. Did you verify that your prefab gets converted properly the usual way using either IConvertGameObject or GameObjectConversionUtility? Maybe it is working but there's some problem with your prefab
I did not use either of those but was reliing on GenerateAuthoringComponent before which worked. Not sure if there is sth special about that though
Actually looking at that code you declare the Projectile as the prefab then get the primary entity as the base weapon, is that right?
The projectile only has default components. The lower part is for converting the weapon which references the projectile prefab
I thought I would have to add all references per weapon with DeclareReferencedPrefab
but maybe CreateAdditionalEntity is the wrong way to access it later on 🤔
Having a hard time parsing what you're expecting from that code. When I have a referenced prefab I add the prefab gameobject via IDeclareReferencedPrefabs then during conversion to get the "Prefab Entity" i call GetPrimaryEntity on the same prefab gameobject. Then I can attach that prefab entity to my converting entity as needed
Not sure what the createadditionalentity bit is about up there
ah I think I see the problem
I thought of GetPrimaryEntity only for getting the entity which is currently being converted
using that instead of CreateAdditionalEntity should solve the problem I hope
Yeah that sounds right to me based on what I see from that code
great that works 👍
now I am just wondering if GameObjectConversionSystem or IConvertGameObjectToEntity is the recommended worflow
Unity seems to use the first one for all its own components. The latter one seems to be better documented though
I think a conversionsystem makes sense for when you're actually converting an existing non-entity-related normal ass unity component to entities. It saves you from having to mess around adding conversion scripts to stuff, you can just convert your existing gameobject into an entity and it "just works". IConvertGameObject makes more sense to me if you're just making an authoring script for something that is only going to be in the entity world
That's what it seems like to me anyways
@karmic basin I realized with the Reinterpret you suggested to use doesn't seem to work with FixedLists within my Neuron struct. Everything else in my struct works except those.
try to access it directly by index then ?
Thats also what I thought. But Unity uses systems also for ECS specific components like PhysicsShape etc.
Yeah but that requires me to also update the Buffer with my new Neuron struct
and that does not work in parallel
As we went through some days ago
I managed to get around this, It's not a problem anymore.
Great
omg... 1,5 years of DOTS development and now I find this Discord channel 😖
is there a way to enable/disable individual components?
I remember reading about it but I don't know if that was added yet or not
Not yet
btw hows unity dots doing
is anyone using it in production
or is it just like a feature that mayy (or not) be common and normalized in few long years from now
thats A LOT, wanna show results?
JUST READ THE INSTRUCTIONS is a surreal co-op first person shooter game where the only thing that matters is following the next set of instructions. Enemies will flood the scene, your weapons will break, more instructions will come, and then repeat.
Aspire to not die.
Steam page: https://store.steampowered.com/app/1461370/Just_Read_The_Instruc...
thats cool af lol
maybe i should render stars using dots
since theres 3000 of them
Thanks! 🙂
haha stupid me
@cunning depot nice! how did you do the UI?
when do you recommend dots over normal gameobjects?
Uhm just normal old Unity UI. Thats the only thing that no DOTS at all.
like do you need a certain amount of objects for dots to be worth it or something (and how many)
yeah dots for ui makes no sense ha
Yeah... if you have a few years experience with Unity I recommend it.
no im still under first year
That's going to be an uphill battle... but you know, if you put your mind to it
@gusty comet imo, dots is worth it when using normal game objects would make people not want to buy your game because of performance. if rendering 3000 stars makes your game slow, dots will fix that.
beginner DOTS progrtammer here. Im using the convert to entity feature on a simble cube. I have everything setupn and it works fine. Im trying to get the cube to rotate using a system:
using Unity.Entities;
using Unity.Transforms;
public class RotateSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((ref Rotation rotation) =>
{
rotation.Value.value.x += 0.1f;
});
}
}
Every frame my cube rotates, but also gets alot larger. Why?
sending gif of itm happening soon
Assuming that's the only code in your system I assume it's from trying to directly set a value on a quaternion. Also you shouldn't be using ComponentSystem anymore. You should model your code from/learn from the samples at https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/HelloCube
The very first sample shows how to do rotation
It doesn't use burst or jobs and it will be deprecated eventually
SystemBase is a superior replacement
does systemBase use Burst automatically?
yes
ok
time to see just how performant DOTS is
ok for what im currently testing dots is somehow slower than MonoBehaviours
using UnityEngine;
using UnityEngine.Serialization;
public class RotationScript : MonoBehaviour
{
[FormerlySerializedAs("radsSpeed")] [SerializeField]
private float rotationSpeed = 0;
void Update()
{
transform.Rotate(0,this.rotationSpeed,0);
}
}
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
public class RotateSystem : SystemBase
{
protected override void OnUpdate()
{
var deltaTime = Time.DeltaTime;
Entities.ForEach((ref Rotation rotation, in RotationSpeedData speed) =>
{
rotation.Value = math.mul(
math.normalize(rotation.Value),
quaternion.AxisAngle(math.up(), speed.RadsPerSec * deltaTime)
);
})
.ScheduleParallel();
}
}
this is a very basic example but i would thing that DOTS would outperform monoBehaviours
ok with a much bigger test DOTS outpeforms MonoBehaviours by far
Some potential factors 1) May not have burst enabled in jobs menu, 2) May have safety tests on (burst & jobs), even then you should test in a build, 3) method for measuring performance.
Spawn 10 000 cubes, see which one perform better
well for one, you're using schedParallel which adds some overhead because you need to startup a thread.
try using .Run() instead.
Is my understanding correct that ConvertGameObjectHierarchy caches converted Prefabs so I wont need to cache the resulting entity myself and can just call it again when instantiating the same prefab multiple times?
Because currently I am doing this:
private Entity GetEntityPrefab(GameObject prefab)
{
if (entityPrefabs.ContainsKey(prefab)) return entityPrefabs[prefab];
GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);
settings.ConversionFlags |= GameObjectConversionUtility.ConversionFlags.AssignName;
var entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, settings);
this.entityPrefabs.Add(prefab, entity);
return entity;
}```
Looking at the code it looks like it doesn't do any caching at all. https://github.com/needle-mirror/com.unity.entities/blob/master/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs
I would only use it for unit testing personally. For actual editor tooling and such you're probably better off using subscenes
And you should never ever call that at runtime, to be clear
It still seems like the way I use Random isn't working correctly. Not sure how or why.
But I really need it to convert my prefabs at runtime. E.g. for loading addressable assets. I am pretty sure it caches some stuff as it uses BlobAssetStores which are intended for storing Asset data. I am not sure about the overhead of repeatedly calling it on the same game objects though
If you can, wait until the dots team provides a solution - it's something they're working on.
Why would you need to convert at runtime? The idea behind conversion is to set it all up in the editor so at runtime you're only dealing with entity stuff. Right now that's a lot more annoying than it hopefully will be eventually but that's the idea. Just be careful about relying on it too much as it's probably going to break in the future
We still support more granular approaches like the ConvertToEntity MonoBehaviour and some function calls in GameObjectConversionUtility, but those should be avoided and are only kept around for dependencies we will remove in the near future. These approaches do not scale, are bound to be deprecated, and will not be addressed by this document.
It would be great if we could convert prefabs at buildtime but I guess thats not possbile. So converting at runtime is the only way when trying to instantiate anything at runtime isnt it?
Using "DeclareReferencedPrefabs" is how you're meant to do it right now I think. If you need an entity version of a prefab at runtime, you create a second component that holds that prefab and add it to your prefab holder during conversion
That is how I've been doing it at least, it seems like what they intend based on samples
I guess that would more ore less result in creating some kind of asset database subscene 😬
Making use of "GetSingleton" can make this a bit smoother since you can just group up a bunch of related prefabs on a single component and use GetSingleton<SomePrefabs>().MyBulletPrefab inside a system
yeah I have also used that kind of code in the past. but it feels more like a hack or workaround tbh
the thing is that the whole scene conversion thing does not really work for all kind of projects
for example I am planning to have a map editor that works in the editor and at runtime which is why I am also using entities at edit time
otherwise I would have to write 2 completely different map editors. One for editing gameObjects (which also gets really slow for bigger maps) and one for runtime
and I cannot just store the runtime created map data in a subscene so I have to create the map from another data source
which means load and instantiate at runtime 🙄
Yeah that's a bit tricky. With the conversion system I guess Unity would in fact expect you to make two verison of the editor, which kind of sucks
I had something similar, so I just wrote map editing information to a memory mapped file and loaded that on runtime
you can extend that and put in another step to create entities after loading in the memory mapped file
That sounds interesting. So you just store the memory containing the map entities in a file?
Kinda, - it's more information per entity since in my case all entities that would be generated had the same component types
I thought about that too. But I am using tilemaps and they can pretty easily be stored as 2d arrays which makes it easy to replace tilesets etc afterwards. Storeing the whole map as entites would make it a lot mor static
ok that sound kind of like what I am doing with the 2d array
but if you only store some information per entity you have to instantiate the entities at runtime right? Or do you create them in code?
i just instantiate them at runtime
better prefab & addressable workflow has been promised for quite a while now... doesn't help right now, just saying you might want to be careful how elaborate a solution you make if you can get away with waiting a bit
*of course a bit == DOTS soon(tm) == 😬
Yea that too, I don't even know if tht solution I wrote is still being used ¯_(ツ)_/¯
@pulsar jay fyi #archived-dots message
american dates..for a minute I thought that was from back in January 🤣
yeah thanks to reminding me of that discussion @amber flicker 😅
oops.. username blind apparently
yeah I mean you are right that it fits the topic and that I partly already forgot about that
but the original question of the current discussion was: does ConvertGameObjectHierarchy cache objects if called mutliple times? It uses a blobAssetStore so I would think so. But I am unsure if it only caches some Assets like meshes or the whole prefab
ah yeah, sorry I wouldn't know from the top of my head on what that does - I'd need to look into it when I have free time 🤔
I don't think it would cache it. At least I'm pretty sure it would do most of the work again - creating an entity and adding and setting components rather than instantiating from a setup entity.
Well I guess I have to dive into it and find it out myself. Just thought anybody might have done that already
Like Sark mentioned - mostly seen as something to avoid. ~~Though it should be easy just to instantiate the entity when it's called again if you keep a local variable.~~Sorry just looked at your code and looks like that's what you're doing I think.
yeah. it gets a little bit "trickier" with lists of stuff. I just wasnt sure if I was building a cache on top of a cache
Hey guys. What would be the cdfe equivalent for shared components ?
You can't use shared components in jobs so I don't think there is one. Since shared components have to be used on the main thread you would just use EntityManager
with entity command buffers, is there anyway to Instantiate a hybrid style entity prefab, or is it not possible by that point because of it being in ECB?
Would my best bet be reading back some entity component data and doing my GameObject.Instantiate there (with convert and inject) ?
Basically have a spawner and trigger system via ECS, but realized animation w/ mecanim will not work so I need to have it spawn characters but keep them "hybrid"
My experience is that if it's an prefab you instance, it does not work well when you instance a Entity containing hybrid stuff. They all seem to refer to a common set of hybrid instances instead of instancing their own. So I've avoided that.
Declaring enums as byte, does that do any difference? I Have a lot of enums that will never be over 256 values. Some of them are also keys in NativeHashMaps (the HashMap declared as <byte, data>). Will it do any difference?
Has anyone been able to set up dots unit testing?
I tried setting this up months ago and I'm still having issues with it. My Game namespace is never recognized by vscode and now Unity Editor does this thing where if I try to double-click a file to open it in VSCode it just crashes. I get a dialog saying 'OnGui.MouseDown' that never goes away until I task kill
It compiles and runs despite the fact that VScode doesn't know the reference
Vscode seems the 'game' reference, it has the game reference code in the same solution explorer, so I have no idea how this is happening
sorry if this shouldn't be in dots btw but I don't have this issue with pre-2020 versions not using dots
I just changed the editor and now it works, so whatever I guess.
If I'm creating a flow field as just straight entities, do you guys think using an enum would be a good way to denote multiple flowfields?
Multiple something calls for a Collection in my mind. Enum probably okay for finite size.
But I dont get what your use case is.
yeah I just want to limit the number of fields
I figure just using straight entities, for the flowfield data seems more straightforward, instead of putting them in buffers or whatever
Every one of these cylinders should have a random chance to replicate, but this doesn't seem very random at all. I'm not sure what I am doing wrong. https://gyazo.com/a6949474ff4cffafbd7528aeddeff0e5
All of them seem to use the same Random variable but they arent using the same one in the code. It must be something wrong with the seed no?
This is how my code looks ```csharp
double elapsedTime = Time.ElapsedTime;
Entities.ForEach((Entity entity, int entityInQueryIndex) => {
Random random = new Random((uint)(elapsedTime * 1000 + 1 + entityInQueryIndex));
I dont know if your doing it but if your using the burst safe random then you have set the random value back into it
Not sure what you mean by "setting the random value back into it"?
And yes, I am using Unity.Mathematics Random.
like in this tutorial https://reeseschultz.com/random-number-generation-with-unity-dots/
How to idiomatically generate random numbers in Burst-compilable jobs with Unity DOTS.
I tried using the exact code from that website but it never worked.
it worked for me 😕
I might have to try that again then.. I'm not sure..
I'm just going to go ahead and guess you're using scheduleparallel and each thread is starting with the same random seed.
"ISystemBase interface for making struct based systems that allow Burst compiling main thread update"
I
That is interesting
I wonder what a use case for it would be
- New scheduling API for
IJobEntityBatchwhich limits the resulting batches to an inputNativeArray<Entity>
This change is pretty neat, great for post filtering entities
"## [0.17.0] - 2020-11-13" did they just not update the date or are they really holding the releases back for that long?
Oh wow I didn't notice the date 🤔
https://gfycat.com/perfectvacantbedbug looks like buggy crap but it took forever to figure out how to manipulate the mesh(getting a bit closer to figuring out how to have physics drive the skinned mesh representation)
to follow that up, its the SkinMatrix buffer on the entity with a rendermesh that is under the root rigged entity. whats confusing is that that a skinnedmeshrenderer gameobject gets split into two entities(one parented under the root joint entity, other under the root rig entity) and also theres buffers everywhere. so many buffers, so little documentation!
now if only i understood why its a float3x4 instead of 4x4? 🤔 anyone with a better understanding of math got any guesses?
still no enable/disable components
my disappoint my immeasurable
and my day is ruined
* Deprecated `Frozen` component as it is no longer in use
``` then what the fuck are we supposed to use then --'
Could be related to https://github.com/Unity-Technologies/Graphics/pull/386
So an optimization trick
I'm also waiting for this, although I'm not sure that's gonna solve my problem but I'll welcome it if it does
is there an example how to use the burst inspector? I can't find out how to see the assembly output for my own ecs code
out of curiousity, what would be a usecase for disabled components ?
It will remove the need to add/remove components for things like events and state machines (just examples, there are much more use cases that benefit from that)
Basically we will be able to avoid structural changes whenever we want to without losing functionality
Basically what we are able to do already with monobehaviours (5 years using Unity and I can count on my fingers how many times I needed to use Destroy com a Component instead of just disabling it temporarily)
It's really a performance thing. I've got old colleagues who works in dots with a 25 pp team and about 10 programmers. They said that the scheduling of jobs account for more than 1ms, they have thousands of those. I know they already knew about this change and will be very pleased.
I need some help thinking in a DOTS way on this.
- I have a bunch of boxes stacked next to each other and on top of each other, think 3x3x9.
- Each box is an entity with a buffer representing contents.
- The contents have color data attached to them.
- The contents can change for a ton of reasons.
- The color of the box (RenderMesh) needs to be updated as they change.
Where does the logic for updating the color of the box go? Can it be threaded?
I don't think the changing of the color in the actual material can be threaded, but UnityEnginge.Color is a value type and obv. can be threaded. I would create a IComponentData that has all the necessary data to handle the whole transformation and do as much of it in burst as possible and set it to the Material in an NonBursted Foreach
Process it bursted in SimulationSystemGroup and apply to material in PresentationSystemGroup
I believe you can thread the change in color if you use URP or HDRP based material and have a component hook to one of it's colors
though I'm not sure anymore with this update
Yeah.. you're right. Forgot about IComponentData as MaterialProperties!
@cunning depot How exactly will it help with scheduling jobs?
Will what help with scheduling? Having everything in IComponentData?
I meant your ping. You pinged me an hour ago or so
Oh right, sorry. Confused... Well scheduling in bursted code will probably be a lot faster. I think that's about it.
I think Joacim Ante has mentioned that i few times in the forums
Hm interesting
I think GetSingleton in OnUpdate will be especially faster, since right now is basically a EntityQuery wrapped in help functions. It will still be a form of query, but queries are so fundamental to ECS and will probably be very optimized while bursted.
Is there a 2020 version of this?
https://forum.unity.com/threads/per-instance-material-params-support-in-entities-0-2.782207/
I need the colors to be dynamic
I think HDRPMaterialPropertyBaseColor is what your are looking for
@gusty comet All you need to do is have HDRP installed, add a "MaterialColor" component to your entity and create a HDRP shader for your entity with just one "Color" variable, has to be named color and connect that to "BaseColor". Then you can change that "MaterialColor" component whenever you want.
I've reached that point and am looking at scheduling the job now
I took a crack at this a few months ago but at that time unit testing did not work and my system is very unit test dependent, so I'm looking at it again and trying to pick up where I left off
Doesn't the HDRPMaterialPropertyBaseColor do exactly this with the Lit shader?
Not sure
I have not tried that, but HDRPMaterialPropertyEmissiveColor seems to work that way
I don't know what that is either so.
Do I have to do anything but inherit SystemBase to have OnUpdate called?
Nope
after enabling HDRP the cubes don't show up at all, rip. Is there something special I need to do to the material? Only non-entity objects render in the test.
Well the shaders used in HDRP is completely different from old Standard rendering. Have you used the HDRP Upgrade wizard to upgrade all materials? Have you tried them straight up in the scene? Sorry to say, but there is quite a few things that can be wrong if you are using DOTS and just upgraded to HDRP...
It's a very basic project. There's one material.
I've changed it to HDRP/unlit. It's blue.
I ran the wizard
installed hybrid renderer v2 and added the define to your project settings?
I have High Definition RP 10.2.2 and Hybrid Renderer 0.10.0-preview
and you added the define as per the hybrid renderer docs?
It sould probably work with V1 if I'm not misstaken. But Project Settings -> Player -> Proprocessor Defines: ENABLE_HYBRID_RENDERER_V2
https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.10/manual/index.html
I'm just going to warn you. DOTS with HDRP is not a walk in the park... Read the documentation (and maybe even the source code) as much as possible . It's preview for a reason.
I'm still having fun at least
Missing how to make this reference the IComponentType MaterialColor.Value
I've never worked with shaders or any of this, I literally just wanted a colored box but that's complicated with DOTS apparently
well "complicated" i'm snapping things together like I'm playing with legos at the moment
Oh I see, it's all in the documentation.
I really thing your sould look into HDRPMaterialPropertyBaseColor first
@cunning depot Don't post reaction gifs, please.
What's the component for material alpha?
I thought it was the MaterialColor W property
I guess I could just make my own
It's probably w. But have you configured the material to handle transparency?
That was it, I discovered that I had to manually drag the shader back onto the material to get it to adopt new properties
@karmic basin thanks, nice find
Okay, here's a practical problem. In that above picture I'm filling up a space with cubes. I want any cube to be able to determine, easily, which cube is adjacent to it in all 6 directions. The cubes are generated on tiles which have x,z and then they are on their own x,y,z grid. The adjacency should work across tiles.
I can change any part of that still, but that's just how it is currently.
What would be the easiest, most efficient way for these cubes to find their neighbors
you can find an entity index position on a 3d grid from its vector position in the world
then you can -1 and/or +1 in each direction to find neighbors
you need to know gridcell size and divide it to the position to get index
Is this in the docu for location?
badly explained, tell me if you need a more specific one
nah but you can find plenty tuts on spatial partitionning
I'm actually thinking of just serializing this. If I know the grid is 256x256 and there are 3x3x9 cubes in tile, then I know there are 5,308,416 cubes in the entire game and I can serialize an a,b,x,y,z to an int between 0 and 5,308,415.
and just have one really, really big array that's created when the map is set up.
I don't know how stupid that'd be though.
I could even use pointers for this.
Not unusual or uncommon. Plenty of octrees are serialized in Morton order.
more rigged mesh deformation progress silliness https://gfycat.com/respectfuluniformhog
Wow since when does shader graph support vertex and fragment output? Is this a new thing or an HDRP thing?
what does it mean when some of my entityManager.AddComponent / SetComponentData seems to "leak" across to other entities? (this is one I'm calling specifically from a MonoBehaviour in Update just for the player, while the majority of the others are not using monobehaviours)
is it the command buffer thing where a structural change occurs and thus the entity index / version my monobehaviour is referencing isn't correct for that frame ?
righto. the entity index and version changes when you do addcomponent. SetComponentData shouldn't change it.
also, it's generally agreed upon that mixing mono unity and ecs unity is big no no because there's lots of headaches associated with it.
makes sense, yea the player controller is all in mono unity, don't really want to port it (this is for 7day fps jam). I think I have a solution though, to keep the components in question all in ECS
ive not seen entity manager leaking, so kinda curious whats going on
I have a Fire component that is added to their weapon entity when they have a target aimed, then the weapon fires until a counter on Fire hits zero (Trigger pull time)
So for the player I'm doing entityManager.AddComponent<Fire>() but it occasionally causes the player's weapon to appear on one of the enemies feet and fire from there for 1 frame
cant say ive ever encountered that and Ive got quite a bit of mixed use cases with monobehaviours.
could be a bug though, if its small enough could just fire off a report
another Q, I'm noticing if I use dstManager.CreateEntity() within IConvertGameObjectToEntity.Convert(), it screws up the converted entity (things in wrong positions etc).
Would using GameObjectConversionSystem avoid that?
I was attempting to create separate PhysicsCollider entities and put them into a IBufferElementData during Convert()
actually maybe what i need is conversionSystem.CreateAdditionalEntity
...scratch that, seems to work fine after shifting the order of things around in Convert() 
Is it feasible to have dynamicbuffer which is a nativehashmap?
World.DefaultGameObjectInjectionWorld.EntityManager has no value during unit tests. How do I make an Entity Manager for testing?
Never tried but EntityManager purpose is to handle entities for the world, so I would begin by looking the source code of how the world gets it.
you don't create the entity manager, you create a world
look into the unit tests within the Unity.Entities package, theres lots of examples
is there a nativearrayutility-like class similar to the arrayUtility?
is the DynamicBuffer a reference to the actual DynamicBuffer or just a copy
For whatever reason for years I've had issues trying to get Unity to correctly rebuild with new references
I'm trying to get Untiy.Entities.Tests in, and I just cannot get it to work
good find on putting com.unity.entities to testable in the manifest.json
the problem is now that .net doesn't recognize it
the code compiles and runs fine, but I get squiggles on everything
Yea - I remember having that issue, so I just copied their TestFixture locally to my own testing dir
pfffffffffffff
this was an issue last time I tried working with ECS half a year ago
you'd think they'd have this sorted
I just want to do some very simple testing
@vagrant lotus DynamicBuffer uses a pointer to the actual data in chunk or elsewhere on heap. its allowed to be passed around like that because structural changes will cause its internal validity checks to fail and it will not let you use it anymore.
@mint iron thanks
quick question... how can i edit a entity during the play mode ? Just one little value ? ^^
The fields are greyed out and i cant insert new values in the "Entities" tab :/
Any ideas ?
they're generally not editable, unless you use a subscene
Damn... would be great :/ its much work to adjust values in code each time to see the outcome
Question about design philosophy.
In OOP, I have a class called a Jar. It contains chemicals. So the Jar contains a liter of water at room temperature. I then call Jar.AddChemical(Water, Temp.Boiling) and it knows, because the existing contents and the new contents have different temperatures, that there's work to do.
In ECS, I have EntityManager.GetBuffer<ChemicalComp>(cube); and I am adding another struct to this buffer.
How do I standardize this so I can make sure events fire no matter how chemicals are getting added?
not sure what you mean by events firing, but you'd have a system that either always looks at the data and figures out if it needs to do anything with it, or trigger execution by the presence of a component. For example, a foreach filtered to run on cubes with NeedsStuffDone component.
That's simply not possible. There will be tens of thousands of these. I can't scan them constantly.
I have, for instance, a Jar.HeatInhomogeneousTag that I can add as a component to handle the math.
But it'd be really nice to have a static method or something for dealing with this
Jar.StaticMethodForAddingChemicals(Entity, Chemical)
But that sounds OOPish and not what they'd want me to do
Are all chemicals <substance, temperature> pairs?
Theres literally no "clean" way to do this inside an ecs... You should just mark the entity as "ChemicalAdded" and having a loop running over them "Entities.ForEach((ref ChemicalAdded ca, ...) => { // Process and remove ChemicalAdded after processing is done }"
@gleaming plank ChemicalComp struct is Chemical, Matter, Temp
Oh and if the performance matters... you can simply use command buffers and multithreading, should be fine aslong as you dont acess engine stuff
So yes it's an IComponent and can be parallel threaded
That's the point
But idk, I just feel like there should be a more precise way of doing this, where adding something fires an even that allows for some hooks
Can systems even fire events?
@gusty comet There is... its called "Reactive System"
But its not implemented in unity yet... so you need to simulate it by yourself... or code one by yourself
I literally had the same problem and coded my own system... but it does not work with buffers :/
hm, okay. I'll move forward with plain systems and pin a note about reactive systems.
If there's a performance issue I'll look back on it
lol I feel like I missed a lot of exposition on whatever you're making. Could you clarify what thing was difficult for you to design the ECS way?
i think its just hard to get your head around, it feels like working around the problem when it should be so much easier if you're used to oop. took me ages.
just going to mention that one thing that makes reacting to events somewhat ill suited conceptually is the scheduling & parallel nature of systems - you almost never want something to react immediately as that puts you straight back on the main thread and possibly a sync point. So you often end up with events either at start or end of frame and then you lose that immediacy/iteration/recursion that events lend themselves to. Then it tends to look like either a) an entity created per event, b) tags, c) icd's with a counter/bool etc d)native stream stuff like the often sited events package on the forums. If you design around the whole game infrastructure around the concept of events, you may be best sticking to just main core imo.
hmm if anyone knows, which systems are responsible for bringing over the entities from a subscene into a world?
actually figured it out, it was everything under the SceneSystemGroup 😅
ya basically everything in that but also
if you're starting with a world with no systems:
- InitializationSystemGroup (the ones below update in this group)
- ConvertToEntitySystem
- EndInitializationEntityCommandBufferSystem
and your world needs to be set as DefaultGameObjectInjectionWorld as that's where the subscene gets loaded into when your regular unity scene gets loaded
How do I standardize this so I can make sure events fire no matter how chemicals are getting added?
@gusty comet
You can do WithChangedVersionFilter<ChemicalComp>() then your job will only run if there's a change to the chemical. You get a reactive system minus the structural changes
It gets tricky to prevent the job from running all the time though, you need to be very careful about read/write access
And you need to validate state since it runs on a whole chunk
Does anyone know why I am getting a "IndexOutOfRangeException: Index 1 is out of restricted IJobParallelFor range [0...0] in ReadWriteBuffer.
ReadWriteBuffers are restricted to only read & write the element at the job index. " error on this:
it happens inside of the raycast it appears (just discovered) on :
Unity.Physics.Broadphase+BvhLeafProcessor.RayLeaf[T] (Unity.Physics.RaycastInput input, System.Int32 rigidBodyIndex, T& collector) (at Library/PackageCache/com.unity.physics@0.5.1-preview.2/Unity.Physics/Collision/World/Broadphase.cs:590)
which is: RigidBody body = m_Bodies[rigidBodyIndex];
is anyone using raycast calls in parallelfor jobs or systems?
Can you show the rest of the job?
that's it. there's more but even when i take out the rest it happens. I replaced the collisionWorld reference with a CollisionWorldRO reference and it works now, not sure why. The ecs physics samples uses collision world inside parallelFor and it works
ColisionWorldRO being read only version, i guess that makes sense though
@zenith wyvern I can't find anything with that name anywhere. Is there a docu for it? It's called WithChangeFilter<T>
I can't speak on WithChangedVersionFilter<Component>(), but there are change filters. https://docs.unity3d.com/Packages/com.unity.entities@0.9/manual/ecs_entity_query.html#change-filters
They apply to archetype chunks and presume that data changed if any preceding system declared write access to them.
Hello, does anyone know how to optimize a 2D grid for random access while using the job system? I'm using a* pathfinding, which uses more and more random accesses the longer it searches. The grid for my purposes would be about 1000x1000 cells, each cell containing roughly 28 bytes. If the code is ever going to be cache friendly i obviously can't have data the size of ~27mb loaded every time i need to sample a grid cell. I'm thinking of chunking the grid into 16x16 cells and using Z-curve encoding for each chunk, however, i can't figure out how to create a NativeHashMap of NativeArrays, since array type data structures are banned to be inside one another in DOTS.
Like you said you can't have nested native containers, period. You can do nested arrays in blobs, or use NativeMultiHashMap or NativeStream
@thorny halo first trick you have to try is to decrease the complexity of the grid
doing cells is a great idea, as that gives you a 2-level acceleration structure of sorts
but generally dont bother so much with the z curve encoding or similar if you are already doing cells
if it really is a problem, try to turn it into a navigation mesh. Convert it first into a grid, and then on each grid, try to "mesh" it into rectangles that cover multiple tiles
it doesnt matter if the meshing isnt so accurate as long as its somewhat reasonable
but a 1000x1000 grid isnt even that much to begin with. Pretty sure the old Dungeons and Dragons games like Baldurs gate did A* on that size of a grid with no effort back in the 90s
have you actually benched it to be an issue?
I have, and yeah astar gets very VERY slow for a grid that size
~20ms in my testing, bursted with safety checks off for a naive implementation of astar
well fuck
For a worst case scenario with no walls pathing across the entire map
but are you sure that the slow thing isnt the priority queue?
on all the A* impls ive done that was the big bottleneck
btw, you should be doing flood-fill
In my testing it was about half priority queue half the rest of the algorithm
to give the separate zones an ID
that way you avoid the pathological case of "no path"
And I tested a lot of different queues
in that case we start getting into the tryhard level
first thing to do is to optimize the amount of nodes for it to be down. A grid is a good first step
every 16x16 tiles or whatever you join them into a grid node. The node has connection points to the other nodes next to it
when doing the A*, you first do the path on the grid nodes, and then you do the "normal" A*-ing on the nodes themselves
multiple levels of grid might be a thing if your path space is absolutely huge
Yeah I figured the easiest way to optimize beyond trying to do some low level cpu magic is simple hierarchical changes to the map to reduce the number of nodes processed. I will say it was VERY fast on <300x300 maps. Way faster than an identical non-burst version
converting the grid into a navmesh is also a popular thing
as it greatly reduces the number of nodes in the map
less nodes = faster everything
there is also another trick. Not using A*
jump-point-search
problem is that it requires the grid to be uniform-cost
In my case my game was constrained to a grid so astar was definitely my best option. But yeah if you're not actually making a grid based game then there are better alternatives
you still want to convert it into a navmesh
even if its still constrained to a grid
you just merge groups of tiles togther to search better through them
That makes sense. Just another form of hierarchical changes to the map. I personally wanted to avoid that to keep things as simple as possible
doing the 2-level grid is probably already more than good enough
meshing it is the next step after the 2-level grid
unfortunately for my use case, the grid will be baked at runtime quite frequently on a large scale so point search optimizations can't be implemented as it takes multiple seconds to finish. I've only kept to grids thus far to keep it simple, i might look into converting to navmeshes in the future tough. Here's an example to what magnitude I'll be dealing with terrain manipulation. https://www.youtube.com/watch?v=sH1b9wZ9xsk&ab_channel=Crysicle
GPU and CPU data state synchronized. SphereCasts/Raycasts can now interact with the heightmap.
Remaining to implement: reduction to the amount of tris/verts rendered. Most likely custom terrain LOD will be required. Unity's terrain methods are too slow.
Watching that all I can hear in my head is "Escape from the City"
I don't know why
I'm trying to use Unity.Physics' CastCollider method and I'm getting exceptions thrown.
This appears to be coming from Unity.Physics\Collision\Geometry\BoundingVolumeHeirarchy.cs
In the method
public unsafe BoundingVolumeHierarchy(NativeArray<Node> nodes, NativeArray<CollisionFilter> nodeFilters)
It's throwing an exception saying that GetUnsafeReadOnlyPtr isn't implemented for NativeArray 🤷🏻♂️
Has anyone else run into this?
I guess I'll have to cast a ray from the corners of my bounding box instead (assuming the CastRay function works)
"And, as I expected, it supports all the ColliderTypes apart from:
Mesh
Compound
Terrain"
🙄
https://forum.unity.com/threads/collisionworld-castcollider-notimplementedexception.851155/
Apparently this defect has been in there for over a year.
@frigid onyx yea unfortunate that compound colliders aren't implemented, i could see why that would be useful
non-convex mesh and terrain casting isn't supported by physx either tho
Terrain makes sense, because typically you'd cast something into a terrain.
I'll work around it, but it would be nice it if the documentation called this out rather than individual devs stumbling upon it at runtime. 🤷🏻♂️
ya i mean non-convex terrain
convex terrain and convex mesh should be supported
also i would think casting into a non-convex terrain/mesh should also work fine
seems that casting that as a shape into others is what's not supported
but if it isn't then yea that'd also suck
When I look in the Entities source, there is documentation, but when I use a package there it is not.
How guys to make it visible?
The feeling when you find your bug after 2 hours of "unexplainable" NaNs due to using normalize over normalizesafe 🤦♂️
Sorry we don't do off topic embeds.
When switching from Hybrid Renderer V1 to V2 fog and shadows look different, how can I fix this?
I also get an index out of range error from a GetSharedComponent call in Hybrid Renderer V2, it seems it's trying to get a component from an entity that no longer exists
so i'm trying to make a jobs based frustrum culling. been trying to get some samples so I can make my own implementation. but I can't wrap my head around it. because I'm limited with the job's system nativecontainers only accepting blittable types.
so what's a good approach to making this frustum culling a reality?
hmm what data do you have that's not blittable?
I haven't started coding yet. Just getting a feel for it.
but I think only one? the Renderer component of the affected objects.
ah and also I think the camera. I have no idea how to calculate if a certain vertex is in view or not with jobs
I would just make a bounding box that contains the entire mesh. Then you can fetch the planes of your camera and test against those inside a job.
Yeah you can use the planes of your view frustrum using the geometryutils class (it'll return to you an array but you can copy it to a nativearray or pin the array for a pointer to it)
nice nice nice... crap i was thinking to manually calculate the planes given that I know the fov, pos, and rotation. saves me the trouble
😄
Joachim: Yes, got delayed a bit because we had several iterations of shipstoppers since we are now validating all dots packages together...``` - validating all dots packages together 😲 🥳
👀
haha no I don't think so
haaaaaaa
could be wrong
welp... I'm gonna cry in the corner for a bit
We need the skinnedMeshRenderer more :p
Oh nice. That also explains why the change log for 0.17 is from November.
yeah enable disable doesnt appear to be in the patch notes
hello I'm back again. I'm trying to create a framework/feature for creating multiple instances of a subscene (rooms of a randomly generated maze of rooms).
-
I've created a ClientServerBootstrap to make mulitple worlds.
-
I've instatiated the subscene using LoadSceneAsync and I see the subscene in my secondary world as intended.
-
I want to use MoveEntitiesFrom but there are other entities in the secondary world created by the subscene system. When I try to delete those, something else deletes the entities I want to keep. My guess is that it's looking at the BlobAssetOwner component, but it's internal so I'm not sure how to remove it to see if that's the issue. Has someone done like this before? Or does anyone have an idea on how I can proceed?
Is there a better way to make muliple instances of a subscene?
public class ObstacleAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponent(entity, typeof(ObstacleTag));
}```
I don't suppose anyone can tell me what I'm doing wrong with the above code
the object gets converted to an entity but it doesn't add the component at all I don't understand 😕
yeah I think it is working right I just can't find them in the editor
in the entity debugger? do you have the right world selected?
plus if they were converted and in the right scene they would show up in my visual debugging system
yes be sure to check which world you're looking at - if you have the subscene open, they're in the subscene's world (and named). If closed I think they're in the default world (and unnamed).
I don't know it doesn't make any sense I can see the entities but they don't have the tags added to them
I think your code looks fine. Do you have a system that removes ObstacleTag?
dumb question but did you actually add said MonoBehaviour to your game object?
yep I think I've got some confusing with naming of things though
does it work if its new ObstacleTag() instead of typeof(ObstacleTag)?
you just get an error if you do that
^AddComponentData
i use this one myself. not sure if it matters: dstManager.AddComponent<RoomLibraryInitializationComponent>(entity);
all are valid and should work
ye
but yea, agree - prefer that over typeof()
timbloc do you know how to create multiple instances of a subscene?
yeah that's what I changed to @slim nebula
Not really - though Unity did release a generative dungeon example or something didn't they? Where every procedural tile was a subscene?
esp check out the known issues
does that sample work? thought it relied on unreleased parts but cant remember
also actually just tested using AddComponent(entity, typeof(mytag)) and it worked so not sure what was going on with your case calabi
I don't know its bemusing how I even come up with these errors 😕
yeah looks like that sample is using prefabs.... I guess I should just stick with that
aren't prefabs always loaded in memory tho?
can I create a bunch of subscenes each containing a single prefab?
fyi we're eagerly anticipating news on this front (prefabs/addressables/subscenes workflow improvements).. as-in, I believe a lot of the work is already done but not yet ready for release. Of course there are no timelines, just mentioning.
ok. that's good to know. then maybe I just do flat prefabs for now, and hopefully it's out by the time my shit is big enough to matter
I think subscene per prefab is.. fine? Though yea as I say, don't go and do a massive project based on that workflow as it's likely to change soon(tm).
yeah. I mean I'm just one dev. doubt I can make something big enough to be a problem in that time
thanks for the help timboc
I seem to have fixed the issue somehow by creating a new script and renaming things 
nope just more confused 😕
More reading, thanks 👌
how many components is too many
Whatever number makes it too hard for you to keep track of what you're doing
And I guess if you have enough components on an entity where it won't even fit inside a chunk...that's probably too many
As Sark said:
-It's too many if you can't keep track of em
-It's too many if they can't fit in a chunk*
-Not "too many", but remove any unused components (used in no queries, as data, tags, or otherwise)
* TBH it's too many way before that; If you have entities with a lot of data, consider whether perhaps the entity should be split into multiple entities. If you have very few of the archetype (<10, typically 1), consider if this data benefits from being on an entity at all, or whether it could be elsewhere.
I'd said the first one is the most important, but the second would be a big red warning flag that you miiight be using the wrong tool for whatever job you're trying to do.
okay. so does mathematics have an equivalent of TestPlanesAABB?
isn't that part of the entities package?
no should be the math extensions assembly
not sure if its documented, but should be there since I used it
I have a couple thousand entities which ecs works well for
but now I need a way to detect collision between each of them
does it make sense to implement an octree in ecs? the only examples I found were using dots native arrays without any ecs
physics collisions ? In case yes : you could use ICollisionEventsJob which provides you entity pairs that are currently colliding
Since unities new physics system already handles world optimization i guess that's one of the best solutions currently
not for physics collisions but simple object overlapping detection. unity physics is too slow for my needs
I need the collision detection without the physics simulation
like the physics elements are static?
im having a hard time imagining what you mean by "i need a collision detection without the physics simulation," since physics will usually simulate so you can detect collisions in the narrow phase of a physics engine
ah I reread what you wrote, @odd ridge if you only need to detect if objects are overlapping and I assume those elements are static, then yeah a spatial data structure is really all you need so you can reduce your search space.
I suppose unity physics doesn't expose that? I would have to write my own?
Unity physics does have a BoundingVolumeHierarchy that you can use. I'm not sure if it's public by default or if I have made it public myself
Hello! Anyone know how to get the scale of an entity after it has been converted from a gameobject with the script "convert and destroy"? Rotation and Translation are working but, Scale isn't... (Tried NonUniform scale as well)
CompositeScale is what you're looking for I think
gameobject
entity
@proper silo
So I've got a problem...
here's a snippet.
public void ForceUpdateCulling()
{
FCJHandle.Complete();
//Dipososing Other natives here ...
//...
//...
if (NativeResults.IsCreated)
{
for (int i = 0; i < NativeResults.Count(); i++)
{
//there's over 100 renderers!
Renderers[i].enabled = NativeResults[i];
}
NativeResults.Dispose();
}
}
now my problem is that copying back the result from the job to over 100 renderer.enabled is literally killing perf.
I'm wondering what's a good strat to solve this perf problem
Thanks, will look into it !
So I've got a problem...
here's a snippet.public void ForceUpdateCulling() { FCJHandle.Complete(); //Dipososing Other natives here ... //... //... if (NativeResults.IsCreated) { for (int i = 0; i < NativeResults.Count(); i++) { //there's over 100 renderers! Renderers[i].enabled = NativeResults[i]; } NativeResults.Dispose(); } }now my problem is that copying back the result from the job to over 100 renderer.enabled is literally killing perf.
I'm wondering what's a good strat to solve this perf problem
@deft stump
Are you running it inside burst? Also if you can reduce the things you're reading from/assigning to into a single value of the same type you can do a memcopy or memmove of the entire run of data at once.
Even if you just move the for loop into an ijob struct with the burst attribute and call it with .Run you would see a huge improvement. Assuming that is in fact your bottleneck
Ah no. this isn't running in ecs. it's just a regular jobs.
An ijob struct has nothing to do with ecs
But Renderer is managed type. isn't that not allowed in a job?
hmm I had thought that unity by default does frustrum culling already with the renderer components, the draw calls change depending on how the frustrum is angled
Ahh, yeah if it's a managed type you can't use it in a job unless you pin it
ik it's not done in Graphics.DrawMesh(...) APIs unless you use the newer Batching (forgot the exact API name) API or fill a buffer and cull it yourself
if you want to continue giving frustrum culling a try, you can try to fill an array with matrix4x4 from a job and pass that to Graphics.DrawMeshInstanced
or Graphics.DrawMeshInstancedIndirect
does UnityEngine.InputSystem work with dots/ecs?
var horizontalMovement = inputMaster.Player.HorizontalMovement.ReadValue<Vector2>();
input.RightLeft = horizontalMovement.x;
input.FrontBack = horizontalMovement.y;
input.UpDown = inputMaster.Player.VerticalMovement.ReadValue<float>();
input.YawRightLeft = inputMaster.Player.Yaw.ReadValue<float>();
input.PitchUpDown = inputMaster.Player.Pitch.ReadValue<float>();
input.RollRightLeft = inputMaster.Player.Roll.ReadValue<float>();
seems to always just return 0. not sure what I'm doing wrong
(input is my component, inputMaster is the generated c# code by unity)
am I doin it wrong?
(or is there a better place to ask this)
inputMaster.Player.HorizontalMovement.performed += ctx =>
{
Debug.LogError("horiz");
};```this doesn't seem to work either. not sure what I"m doin wrong
hmm trying this now: https://forum.unity.com/threads/how-to-use-the-new-inputsystem-with-dots-ecs.901811/ maybe ignore me sorry
I was missing inputMaster.Enable();

I'm not too versed in the UnityPhysics package, but an ICollisionEventsJob (or ITriggerEventsJob) is probably what you should use. It'll give you all pairs of colliding entities.
AFAIK the dynamic motion parts of the physics simulation only run on entities with the PhysicsVelocity component. If your entities only have the PhysicsCollider component, I think you're only paying for collision detection.
If you're searching for specific collisions, rather than an ICollisionEventsJob which iterates over all collisions, it might be more efficient to run queries on a CollisionWorld directly.
The API is pretty verbose, so I'd recommend going through the official samples.
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/UnityPhysicsSamples/Documentation/samples.md
Sample 2d2 implements an ICollisionEventsJob as part of the example.
Sample 3 is basically a walkthrough of every CollisionWorld query.
Why is adding a Scale component in a Monobehavior Convert method not working while any other component is?
I think making my own custom renderer is going to be faster in terms of perf than trying to make do with unity's renderer components
yeah that's fine, I think implementing with Graphics APIs would be decent, otherwise you can hook in an external renderer
I've done that and it works quite decently for DrawMeshInstancedIndirect
Oh I was able to circumvent it by using Array.Copy to a managedArray.
then use Parallel.For
then rely on the Update method to update it for me.
uuugh it's not performant but at least I'm getting results
okay so. Upon testing... it seems that my solution isn't anymore faster than rendering everything
how do i add a collider to my terrain in unity 2020 i am new to unity
i still fall through
@gusty comet well your character must not have a collider. the unity terrain comes with a collider
how do i get data from entity in a monobehaviour? i need to change an object's mb's properties depending on entity's data
You can access the entities package from monobehaviours
this means you can retrieve your world's EntityManager, or do your query, whatever...
any way to get a linked entity from a go?
A query. Or pass it to the gameobject from inside a system
to be exact i need get an entity's PhysicsVelocity and use its data to show speed to a user using unity ui
a query wouldn't get a specific entity though, would it?
The gameobject in this scenario would be the ui?
yep
When you're authoring your gameobject that's being tracked, you can add the ui as a reference in a managed component
And use a system to update the ui any time the physics velocity changes
how would i do that? i cant add gameobjects to components
You can. You can use a "Managed component", IE a component that is a class instead of a struct
Then it can hold managed data, and you have to use WithoutBurst and Run any time you access it
wait what?
In that example the "HealthUI" holds a reference to a text component
Not the least bit performant but good enough to bridge the gap until we have proper dots ui....if we ever do
well i also need it to control an fmod event soooo either way i have to use it lol
besides the main purpose of dots for me is physics raycast performance in dots unity/havok physics
imported hybridrenderer
restarted editor
checked using Unity.Rendering & Unity.Rendering.HybridV2
Visual Studio still does not recognize RenderMesh anywhere
How do I resolve this issue?
If you're using assemblies you need to make sure that's referencing the rendering assemblies. Otherwise try closing visual studio and deleting all the .vsproject files and the .vs folder in your project directory.
Does unity do entity conversion of the top level scene on compile? or in runtime? Are there future plans regarding this?
I guess I can just have a subscene as the only child of the root and put everything in it
are native hashmaps resizeable?
huh so what's the point of adding a capacity then?
Resizing isn't free. Just like non-native containers, you safe some CPU time by setting a sensible initial capacity
Also there's a limit to how much it can resize at once. Something to do with cache size
It won't let me use UpdateBefore/UpdateAfter on a custom ComponentSystemGroup, so how do I specify when my group gets placed relative to the default groups?
Has someone made any experience with SharedComponentData and IJobChunk ? I'm having 10 'battlefields' which each consist of 40 'fields' , i added each field a sharedComponent with battlefield index (int) to structure them into chunks, but I would need to compare some requests to that index to target the right battlefield (for movements for example). So i was wondering wether it's possible to (readonly) access shared component data for a chunk ?
Hey guys, real quick question. How can I easily do hybrid renderer for static objects and still have normal physics for them? Duplicate the object with just the colliders or what ?
Hello, I'm creating a Priority Queue data structure which I'll be using in a job later. Initially I thought I'd just need a hashmap and a heap, but now i realize that it's only enough for a single job thread as other threads would need their own priority queue. If i needed an x amount of threads to use a Priority Queue for each thread, is the only way to do that is to create a Priority Queue Array? Where the x heap arrays and x hashmaps would essentially be combined into a single heap array and a single hashmap?
E.G. Priority Queue [Heap][Hashmap] -> Priority Queue Array of size 4 [Heap0Heap1Heap2Heap3][Hashmap0Hashmap1Hashmap2Hashmap3].
@deft stump When trying to save a value in a hashmap the key will be converted into an index of the hashmap array, if the index is already occupied, it will move to the next index until it finds an open index. Because of this, hashmaps always have race conditions when multithreading and writing to them. Writing to a hashmap can only be done in a single thread in order to avoid overwriting data from 2 or more different threads/
then what's .ParallelWriter for?
@deft stump If I'm understanding correctly, on line 129 "NativeResultMap = ParallelNativeResultMap;" is not a data copy, NativeHashmap is just a struct on c# with an index pointing to c++ data. So It's copying the index, not the array data. So when you're doing "ParallelNativeResultMap.Dispose();" on the next line, you're deleting the only data you have. Therefore, NativeResultMap, which is now pointing to the deallocated data, is causing exceptions when trying to access it.
To fix, probably just make ParallelNativeResultMap with Allocator.Persistent, dispose of NativeResultMap , then assign ParallelNativeResultMap to NativeResultMap .
hrmmm
Okay since I can't do parallel writing. maybe I could shard it?
and then have x number of ijobs running
or maybe use NativeDisableContainerSafetyRestriction]?
Well if you want to do parallel writing on a NativeHashMap, use the AsParallelWriter() function
Still waiting for 0.17 😦
I jumped onto version 2020 because dots in 2019 is hardly usable imo but I'm definitely sticking to 2020 LTS this time. updating my project everytime unity releases a patch is such a pain
so... HAHAAHAHAHAHAHA
scheduling the frustum calculation per object. instead of making a giant list and scheduling it once is no go.
for 1003 objects, i'm getting 60ms just from this one monobehaviour that's scheduling a job being called 1003 times.
Yes, scheduling 1000 jobs in a loop will work very badly
Here's an example of writing to a native hash map in parallel
var nmh = new NativeHashMap<int, int>(32, Allocator.TempJob);
var writer = nmh.AsParallelWriter();
Entities.ForEach((int entityInQueryIndex, Entity e) =>
{
writer.TryAdd(entityInQueryIndex, entityInQueryIndex);
}).ScheduleParallel();
Job.WithCode(() =>
{
var arr = nmh.GetKeyValueArrays(Allocator.Temp);
for (int i = 0; i < arr.Length; ++i)
Debug.Log($"{arr.Keys[i]} : {arr.Values[i]}");
}).Schedule();
nmh.Dispose(Dependency);
@deft stump
Don't try to dispose the parallel writer. It's just a wrapper around the original container
Is there an easy way to get the delta time since the job last ran?
but to put it back to a managed object, I have to loop through the KeyValueArray. right?
I have no idea what your use case is. If you need to run through every element you can just use foreach on the container, I only use the KeyValueArray because you can't do foreach inside a job
Does anyone know if the ComponentSystem will be deprecated?
It'll still be around for the GameObjectConversionSystems that are in place (but yes use SystemBase instead for your gameplay logic)
I'm getting a dots-complaining error about my generic component
for the ComponentSystem there was an option to register them via assembly: attribute
[assembly: RegisterGenericComponentType(typeof(MyGeneric<ComponentName>))]
However it doesn't work here
ah sorry, I don't know much about generic components usage in DOTS :/
sounds like i'm going to recreate the whole game 😢
well my idea is this.
there's 2 scripts, 1 is a Singleton (for the sake of arguement), and 1 is a regular old monobehaviour attached to X number of objects.
the idea is:
register each monobehaviour in the singleton hashmap with instanceID as it's key, the bool wether i want it to render or not as it's value.
setup and schedule the job inside the singleton update method.
then after the job is done each monobehaviour gets the result from singleton hashmap.
that was the idea.
Is there some reason you need extra culling beyond the built-in frustum culling?
If you need occlusion culling for gameobjects they already have a system for that
just a side project and nothing really serious.
I just want to see it done and in the most performant way possible.
In most cases if you want the most performance you should be using ECS. Gameobjects are slow
And awkward to use with jobs in most cases
i thought your bottleneck was the renderer.enabled = true/false part
that changed
ah
Back with some design questions for my little dots project... soooo i want to implement some sort of combat system 🙂 Each entity has some sort of health, which is no big deal because thats easy to realize ( Health{ health, maxHealth } )... furthermore there should be certain types of damage and resistence. For example magic damage, physical damage, true damage and other forms... and phsyical resistence, magic resistence and other forms. How would you realize the damage and resistence in components ? Each type one component ( PhysicalResistence{ strength... }? One component for damage and one for resistence with enums/strings as a generic variant ( Resistence{ type..., strength... } ? Or another variant ? ^^ Whats a common approach for this ?
Im still struggling with the data oriented mindset, so im glad for any help here ^^
I don't know if there's a "common" approach. You're describing a pretty complicated system with a lot of different components that need to talk to eachother
I was thinking about it for my roguelike. You could have combat represented as an entity with references to the attacker/attackees. You can have TurnBegin/TurnEnd systems, then other systems that operate between them that affect the combat entity in different ways before it reached the TurnEndSystem where the actual damage gets applied
That's a lot of boilerplate but I feel like it does a decent job of separating concerns
Thanks for the insight ^^ ! The main focus of my question lies on the different variants for representing dynamic content ( Resistence and Damage types in my case ) 🙂 Any ideas on those ?
i'd prob do the latter, Resistence with enum type
bypass the indirection you have
But then you can't have multiple resistances
give the native hash map to all of the monobeaviours, access though the singleton likely, stuff it into a field
have each access grab from it
don't copy memory before you need it
have the ability to fetch it
yea i suppose it would be a dynamicbuffer of resistances then
would normally keep things as simple as possible and do seperate component for each type, but then you'd prob end up with a lot of duplication since damage/resistance is usually applied the same way
Yeah I was just thinking that, like one component and system or at least job per type is a lot of typing
^ So its always some sort of trading with flexibility ?
Like, the buffers are much more flexible in terms of "new" resistences e.g.
It also should be easy to add "new" types of resistences... so its probably better to keep the resistence flexible too
i think dynamicbuffer would still be pretty flexible
and if you have 4 (for example) different resistances in your game, you could specify your dynamicbuffer size as 4, and then specify an index in your enum per type so you can just do
buffer[DamageType.Physical] or whatever to get the one you want, so you don't have to do a bunch of searches
since i would assume the default value of a resistance would be 0, not null
so makes sense to preallocate that in the dynamicbuffer size i think
I actually prefer this way - I use bitflags to mark which types of combinations I want applied 👀
if all the resistances use like the same struct but different values, you can stash all the values into an array and can fetch the value based on the flag value:
Resistance A: 1 << 0 would be accessed like so: log2(1 << 0) = 0, so you can access the 0th index of an array and fetch those values to apply)
Yes a buffer for the resistance type makes it more complicated than it needs to be I think
You can represent "DamageType" as a single enum. Reuse it for attack type and resistance. Then you can have a single system that checks for the resistance component and just checks if the resistance enum has the same type as your damage, and modifies damage accordingly
Kind of out of the scope of dots for sure beyond that
Anyone know of an up to date Dots tutorial? all seem to be from a year ago
Only thing really kept up to date is the ECS manual and the github samples https://github.com/Unity-Technologies/EntityComponentSystemSamples
Have any of y'all had any problems with generic function pointers like FunctionPointer<Func<int, bool>> in bursted code? When I try it in burst-compiled code it works just fine, only running into errors with it in C# code.
A lot of the tutorials / sample content I'm looking at are outdated. Anyone got any recommendations for things to look at so I'm not exposed to depreciated ways of doing things?
EntityComponentSystemSamples is your best bet
Check the pinned messages for this channel: Entities & Physics Samples
Ah - yea I saw the pins but one of them pointed to the wiki which pointed to a few outdated tutorials
I'll check that one out tho
I'm completely lost been bashing my head at this for hours. I do this:
var sceneSystem = EntityManager.World.GetOrCreateSystem<SceneSystem>();
var subEntity = sceneSystem.LoadSceneAsync(scene.SceneGUID);
```then a few frames later sceneSystem.IsSceneLoaded begins returning true, but none of my subscene entities exist in the entity debugger. What am I missing?
what's the correct way to load a subscene? is this not it?
shouldn't this RequestSceneLoaded component be getting eaten by somthing in return for the scene actually loading?
i can't handle this I"m going nuts
is there source available for SceneSystem? I guess I have to look line by line and figure out how the serialization works?
Deprecated Deprecated ConvertToClientServerEntity, please use the sub-scene conversion workflow instead.
so if LoadSceneAsync is not the way to do this, what is?
I don't know how to load something only for client or only for server world if this is not it
is there some magic setting somewhere in options to enable subscene loading?
I'm trying to load a subscene with a single object with a single component. it just doesn't load. what am I missing?
I"ve looked at a million tutorials they all say the same thing. anyone?
has anyone here loaded a subscene before?
how dod you do it?
calling LoadSceneAsync 10,000 times per frame doesn't seem to help either
So your object doesn't appear in the entity debugger after loading it on the server?
The scene seems to be loaded since it has the PrespawnInitialized flag in your screenshot
I'm sure there are other indicators for that but I'm not that deep into the sceneloading logic
so here's my subscene
it's in my main scene
I"ve confirmed the guid passed to loadsceneasync matches the .meta file of the scene
then I have my system
public class FUCKYOUSystyem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((Entity entity) =>
{
});
bool working = false;
Entities.ForEach((Entity entity, ref FUCKYOUComponent fuck) =>
{
Debug.LogError("WORKING WORKING WORKING WORKING WORKING WORKING WORKING");
working = true;
});
if (!working)
{
Debug.LogError("FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL");
}
}
}```
my FUCKYOUComponent never shows up
no
I have to click reimport
is that all?!?!
/wrists
it might be working now.....
It should automatically reimport the scene if you do changes to it
But I do not really trust that to be honest
that's what I thought too... appears to be broken
Does it work now?
yikes
I can delete the component and it breaks it and fixes it without having to click reimport now
so I guess it just got into some bad state?
thanks for helping
aaaaaand it's broken again. the fuck did I do
sigh
disregard
yes!!!!!!! it loads my stuff now
so happy
now to delete hours worth of debugging code and profanities haha
my favorite part of unity editor is the play button gamble. Click it and wait for 10 seconds to see if it did anything. It might work it might not. it might be playing and if u click it again it'll queue up a stop. great feature
Its me again... the discussion about stuff like damage and resistence brought me to new questions :c Lets say our mobs have weaknesses and strengths against either "weapon-types", "damage-types", certain "environments / locations" and other modifiers... how could we realize this in an extendable way ? Lets say we dont wanna use an enum or hardcode that many modifiers in our combat system... how would such a structure look like in component based design ? 😮
I think there's mane ways to skin this cat with ECS genar
your components could inheret some generic modifier interface
and be applied generically to hoever you plan to store the modified data
but that's just one option
I can think of a few
@slim nebula That sounds interessting... what do you mean with that ? ^^ generic modifier interface ?
like IComponentData
just add your own interface and use multiple inheritence
then you can cast ur different components to that interface and process it generically
Ah ok like "FireModifier : IModifier, IComponentData { ... }" ? ^^ But then we would need to iterate over each new modifier-type to calculate the damage result, right ? Which means tons of Entities.ForEach loops ^^
Or can we iterate over all "sub" types on an component ?
you could use an isharedcomponentdata to group things maybe to reduce to 1 query
Thanks, thats a good idea !
so I've got some game objects to organize hierarchy in the editor, but I don't need these as entities. Is there some component I can add on them to skip converting them?
or some other mechanism?
Is ECS pretty much the go-to architecture for Roguelikes?
IJobParrellelFor is only avaliable with .Schedule() or .Run()
is it not possible to have .ScheduleParrellel()?
(without using IJobChunk)
context of the logic
forloop (relatively small int)
forloop (relatively large int)
so it would not be optimal to to use
Entities.Foreach({
Job.Run()
}.ScheduleParrellel()
You can't schedule a job from inside a job
I'm confused by the question, IJobParallelFor is separate from ECS, it has no knowledge of chunks or anything
yes
it is a voxel terrain generation thing
it takes in data and output meshes
the number of entity to iterate over is low
but the number on executes in the generation is high
the IJobParrallelFor was from a non-ECS project before
i was experimenting with redoing the whole project in ECS
Question regarding blobs: pre-ecs I would use scriptable objects instead of enums for a few reasons, but considering they are stored randomly in memory it would work against the concept of ecs. Blobs are immutable so it seems like they would be a good place to go in place of SOs, but they must be created each time, as they are stored in memory.. is that correct? and would the best workflow be to still store them as scriptable objects and then create blobs on startup?
store them as scriptable objects and then create blobs on startup
typically. this is what I do.
ok cool. that seems like it would work just wanted to make sure there isn't any reason it would be bad to do
since SO's, from my understanding, are also designed to be immutable as well. A block of data that you want to read from instead of writing to it.
do you change any of your blobs runtime?
nope
for example, some of my scriptable objects i used as variables that could create separation between systems, like health
i'm assuming a new blob could be created and the old one disposed
but might not even need to do that with the change in architecture
that's expensive to do, but yes, you can do that. dipose old and create new
yeah that's what I thought, so will probably avoid.
thanks for the info! Do you load them like this?
I'm not sure where to look
sorry.. with the Addressable system?
ah... no I haven't used addressables with ecs yet.
you just create a normal blob and grab data through a mono maybe?
that would be an easy start
from hearsay, I think there's going to an ecs addressables??? I'm not sure where I heard that.
yeah I slap it onto a mono and use the conversion system to transform it into a blob
my mistake
IJobParallelFor.Schedule() is the same as IJob.ScheduleParallel()
so there is no IJobParallelFor.ScheduleParallel()
and there is no need
@zenith wyvern thanks for help
@amber flicker isn't you who making a tween tool for DOTS ? can I have a status about it ? I'm interested 🙂
Thanks for remembering @tame sigil - still a month or two away from getting it to some beta testers but doing my best to get it to that stage asap 💪
nice 🙂 thanks for update
np - feel free to add me on twitter or dm me for my discord if you want to stay more up to date
Hello, I'm trying to use types in this namespace https://docs.unity3d.com/Packages/com.unity.collections@0.11/api/Unity.Collections.html
however I keep getting this namespace instead https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1.html
when using Unity.Collections. Rider traced it to UnityEngine.CoreModule.Unity.Collections. How would one resolve this conflict?
Nvm, I just needed to add it to package manifest dependencies 🤦♂️
theres a dots animation forum! 🥳
Are subscenes more efficient than the convert to entity script? Even if it's only one gameobject?
How did you realize damage in ecs ? Each of my entities owns a "Health" component... thought about a "Damage" component that stores incoming damage for the attacked entity, that would be easy extendable. We could have an shield system that iterates over the incoming damage to absorb it. The other way is having some sort of damage event which connects two entities, less flexible because our shield system couldnt iterate directly over the entities... instead it needs to iterate over damage events. What would you choose ?
I feel like the damage event (represented by it's own entity) makes it more flexible. By definition one thing damaging another involves exchanging data between two entities, so trying to force it all onto one of the two doesn't work.
If you later wanted to do something like give experience to the entity doing the damaging, then you need some way to refer to the damager anyways
@zenith wyvern Thanks ! Thats right ^^ Furthermore it decouples the logic a bit. So lets say we have an damage event and the hit entity has some sort of "ResistanceModifiers" that should reduce or maximize the incoming damage... so we would simply iterate over the damage event entity, check if the hit entity has this component to apply the modifiers ? What if the hit entity doesnt have such an component ? Thats the only part that feels strange, i hope you understand what im trying to describe. A natural ecs applys its logic to all entities containing some component... an event however, only connects two entities and therefore its a bit harder to implement logic to reduce/increase the damage... or am i missing something here ?
@stone osprey
CombatSystem =>
Generates "Combat" Entity. Combat Entity has data for damage and entity references to things involved in combat.
Also Generates "BeginCombat" *component* on attacking and defending entities. These gives the attacker/target a reference to the combat
so they can affect it before it gets resolved.
DamageBonusSystem =>
Entities
.ForEach((Entity e,
in DamageBonus bonus,
in BeginCombat begin)=>
{
var dmg = GetComponent<Damage>(begin.combatEntity);
SetComponent<Damage>(begin.combatEntity, dmg.Value + bonus.Value);
}).Schedule();
// Remove "BeginCombat" component
ResolveCombatSystem =>
Entities
.ForEach((Entity e,
in Combat combat,
in Damage damage) =>
{
var targetHealth = GetComponent<Health>(combat.target);
SetComponent<Health>(combat.target, health - damage);
}).Schedule();
// Destroy Combat Entity here
Rough draft of what I was thinking of
May or may not work
Just kind of the idea I had in my head
I have a blank HDRP project and I added the hybrid render. Immediately I get this weird semi-pixelated look everywhere that wasn't there before the hybrid render was in.
It may look slight in these pictures but when you're moving around the checkerboard noise effect is really noticeable (look at the edge of the light to see it best)
@zenith wyvern Thanks a lot for your time ! 🙂 That helped a lot ! ^^ So our combat system spawns in a combat event entity... then the damage bonus system comes in and increases its damage and the resolve system applys the damage to the target.
Exactly. It's a lot of indirection but that's what you have to deal with when you want entities to talk to eachother in complicated ways
And it seems like it should be pretty flexible
And the same principle for resistance. It queries for BeginCombat and Resistance and changes the combat damage based on the damage type as needed
I guess you might need BeginCombatAttacker and BeginCombatDefender actually
This is actually great, because in my previous draft i had something like "Damage{ amount }" on my target entity... this changed later to "Damage{ list<float> amount }" because one entity can receive damage from multiple other ones and then i changed it to "Damage{ list<damageDesc> damages}" because i also wanted to involve different damage types... but having an damage event that stores stuff like type makes it much more composition based. BUT the "Damage" component on the target entity stays as some sort of consumer right ? So the event only calculates the damage and passes it to the entity-damage component. And that component value gets applied to the health ?
ah nevermind... just saw in code that "Damage" is on the event and that the event system substracts it from the targets health ^^
The combat entity can just use a buffer of entities for targets rather than a single entity
Ah I guess that wouldn't work, you would need individual damage for each entity so they wouldn't affect the damage for unrelated targets
I guess for that system to work you would just need to generate one combat entity for every target, and just have the same attacker as the source in every case
Why generate an entity at all? Why not just run systems on the entities involved?
But thats totally fine ^^ its not like there thousand of entities attacking each other in my game
@gusty comet The entities need to be able to affect the data before it gets resolved, and the attacker and the defender want to affect the data in different ways. Having data that both entities are trying to affect live on either one of the entities sounds like a nightmare
Or maybe I'm just missing something there
I was just thinking if an entity has health then it is capable of being either an attacker or a defender so just code a system for checking if you're being damaged and a system for checking if you're damaging something
Also on my pixilated problem, this is now happening with blank HDRP no-dots projects even though I have an existing blank hdrp no-dots project where this is not a problem and they're on the same version....
@gusty comet The discussion was around an extendable damage system. Dealing the damage itself doesn't really seem to be the problem.
Right but I don't see how this wouldn't be extendable.
Could you elaborate more? How would you handle the attacker having a damage bonus and the defender having damage resistance?
If characters can have resistances, just run the for each on all entities that have health and resistance and then lower the entity's health by the damage inflicted * resistance modifier. It would be complicated with more variables but I would imagine the damage entity you're using will also get rather complicated
I guess I'm making the assumption that attackers and defenders have the same attributes
Hi, no idea if I've stumbled into the wrong house, but we're a bit stuck on an issue and have so far failed to find any info to help.
We have an existing app built in Cordova (I know) and are trying to implement some AR functionality. Eventually we have come to the point of trying to integrate a Unity instance into the code using a plugin.
We have successfully compile the Android version and have one error when compiling the iOS version which is apparently a missing library:
ld: library not found for -lUnityARKit
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm not even the dev, just desperately trying to find some pointers 😬
try asking in the #🤯┃augmented-reality channel
Thanks!
is there any way for me to change this from 4 to like... 30... just so it goes away while I'm working on other stuff?
you can't change allocator life time.
either change it tor allocator.permanent or respect the allocator lifetime.
it's unity preview packages doin it. I havn't allocated anything myself