#archived-dots
1 messages ยท Page 105 of 1
i already know how to do basic queries and systems, i already have a system that updates markets to reflect their current price(depending on supply and demand), its a simple and lovely system ๐
but i couldnt solve the problem i am having
but i just couldnt do double query
@opaque ledge
What do you mean by a "double query"?
i feel like i should do double query somehow
2 queries and unionize them? I assume that's what you mean
so what i tried to do is.. every market would hold comparrision information against other markets, so if market1 sells for 1, market2 buys for 5, market1 would hold value of 4(since its a positive transaction since trader is buying cheap and selling high) etc.. so i tried to get all the markets.. then i tried to get all the markets again, so i would compare market1 to market2 market3 and then market2 to market1, market3 etc., after this system is done traderoute chooser system would take a look at this info and find the highest value and send the trade ship.
so... i dont know how to do a query inside a job struct
and i dont even know if my way of thinking is correct
You can't run a job from another job. It's an inherent rule of the safety system. If you need information in a second job from a first one, you need to gather it in one job and pass it forward to the next.
yeah i actually tried that before i gave up, i wanted to get all those markets from job 1 and put into nativelist and send it to job 2 and actually do the calculation there
but it felt like i was doing it in a wrong way because it felt like it was complex
If you feel like one system or job is doing too much, you can try to break up your data into smaller pieces that each get processed by their own systems
And Unity will do a nice job of handling the implied dependencies between that data
so 1 query per job then ?
I mean you don't really have a choice but yes that makes sense to me
Maybe someone with more experience writing larger more complicated systems can provide some better insight
i think you are right ๐
i probably will be working on it tomorrow morning
its.. kinda ugly code but hey if it works it works ๐
@trail burrow the whole dirty bit thing is 1 bit per entire property
including things like structs
then the actual Delta system unreal has does its thing
thing is, unreal has a huge bottleneck on checking deltas, as it does so every update
typical unreal network update goes something like this
for each connection (player)
find objects relevant to that connection
filter by check rate
go through ALL objects, and their subobjects, and compare with the last snapshot
build deltas
prioritize
send
the go through all objects part is super slow
for reference, doing that in PUBG takes a few miliseconds per player
and we have 100 players at start of the match
the N^2 problem is real
pubg (and fortnite, but fortnite does it better) does some trickery for that. For example pubg will only update 10 other characters per character at each tick check
and the fun part, is that well designed ue4 codebase is much slower than bad codebase. A codebase with a God Class in Character (player) that has a huge fuckton of properties is significantly faster than a codebase with split concerns and stuff in components
@coarse turtle you probably know this already, but its not worth it to make a custom engine no matter how much you think you are doing from scratch in unity. its trival to throw together a engine with ecs, jobs, physics, rendering etc but its another to take that and write all the editor tools, all little interactions between the librarys to make things work, setting up a proper build pipeline, cross platform?
in the case with unity dots, you can always fall back onto anything from monobehaviour world to get around something that isn't done in dots yet. like animations and fast rendering
Yep
totally get it though. I'd just love for dots only version of unity with source code
I'd love to just finish up whats missing good enough for my game and rock on
instead of dealing with a million broken projects they are working on (HDRP and URP disgust me)
Well end of the day - the stuff we end up building on top of dots isn't much of a pain for us
thats true
its so pleasant to work with once you get it
ongui debug windows with data is priceless for debugging things in dots
you just query things in your ongui and loop though them displaying the data, it ends up being faster than you might think
like I get the conversion system is a bit janky for ppl here, but it fit our needs which was quite nice
I've used it in my new projects but I can't use it in my main due to project requirements
I just use a custom manual hybrid setup
ah - and we were debating on using imgui but since we really just work on this on our free time, one of my teammates didn't want to learn how to stylize in imgui - so it was better to stick with uGUI
I've got a debug UI I'm thinking about releasing here / fourms soon thats basically just a runtime clone of the entity debugger
has most data and it even works in il2cpp from testing
I think the biggest issue with the conversion pipeline is at first they seemed to be leaning towards working naturally with entities in the editor
Then they just completely shifted to conversion system instead which...doesn't seem like anyone wanted
theres some things I need to rework before release but it already is super helpful for tracking down the bugs where it only happens in a build
I really want to rework the UI layout of it first and cut down on the number of active elements, but thats all easy to do once I set aside time for it
considering what happens to skinned characters, hierarchical relationships with physics, i kinda get why a dots editor wasnt the right way to go for now
Yeah I guess it makes sense to keep everything completely separate for now while they're still changing the higher level stuff so much
Bummer that it causes so much more work for the users though.
btw @low tangle what is your game, wondering if there's a store front page to look at ๐
I'm hesitant to link it because I got review bombed hard by some tolls from another game
ah - sorry to hear - no worries
just sucks a few kids can ruin a game so hard
even with evidence from their discord planning it, valve still didnt care
prepping a big update that should help though
It's a bummer that steam is so easy for people to abuse. I like that epic store is giving creators more control over that stuff. Or will be
Right now they don't even allow reviews
honestly thats better lol
I agree
I mean the guys even went to every single social platform it was being posted on about, twitter, youtube etc and shilled the other game while talking trash
so its not exactly the primary selling platform reviews that can be the issue
Well you said you're working on a social VR game, then I can imagine where the review bomb may have come from and yeah...that community is something else.
Fair
in a JobComponentSystem, what's the difference between using the [ReadOnly] attribute abose a member variable versus using the readonly keyword in front of a member variable?
The [ReadOnly] attribute is only needed for job structs, not needed for the new ForEach constructs. As far as I know the keyword has no special meaning in ECS
@zenith wyvern how do I handle input in ECS?
You read it on the main thread and either respond to it immediately or translate it into ECS components to be read by systems.
@zenith wyvern I'm trying to create an array of keystates and pass this array to the job struct, but I get error "cannot be of reference type". how do you give an array to the job?
If I modify component data in a native array created by ToComponentDataArray
will the updated data be used by the entity?
or do I need to associate the updated data with the entity ?
You need to assign it back. But you can do ToEntityArray and I believe both arrays are aligned the way you expect
great!, thank you @zenith wyvern
If I put the IConvertGameObjectToEntity interface on my gameobject in a subscene do I need another method to call the Convert method? At the moment it never gets called during runtime
Maybe you also need ConvertToEntity?
I tried putting that on the gameobject and it 'Convert' it to an Entity but it still doesn't go through the Convert method in the class
Hm, it should do that. Are ConvertToEntity and IConvertGameObjectToEntity on the same gameobject?
Yes they are
Have you rebuilt the entity cache?
If you have it in the subscene it is not supposed to get called on runtime, isn't it? It will be converted when the subscene is created in the entity cache. On runtime the already converted stuff should get loaded of the entity cache.
Right, during runtime this isn't called as there are no more gameobjects...
Didn't the Rebuild Entity Cache button get removed since a few months? I've been unable to find
I don't use subscenes currently, don't know. They were so much pain i kicked them all...
Does anyone know hot to make CollisionWorld readonly in a Entity.ForEach? With entities 0.5 .WithReadOnly() doesn't work anymore because CollisionWorld doesn't have [NativeContainer] set.
Are subscenes or better its data now be able to be in an asset bundle and will it work on android to load them?
@silver dragon I think you use ReadOnly on PhysicsWorld?
I tried PhysicsWorld and CollisionWorld and both can't be used with .WithReadOnly in 0.5
When using the new Build Settings Scriptable object, (which is required to use subscenes) and I hit build, I get:
Build ClassicBuildSettings failed after 0ms.
Build step BuildStepApplyPlayerSettings is missing required component 'ClassicScriptingSettings'.
Does anyone know what that means?
Happens in the "Apply Player Settings" build step
Started a new forums thread about my physics issue. I feel i miss something important...
@silver dragon try post your code
This is a follow up to https://forum.unity.com/threads/invalidoperationexception-the-previously-scheduled-job.682744/. I decided to start a new thread...
Solved (see thread) ๐
i am not able to install Entity from package manager,its stuck in installing
how to fix it ?
using Unity 2019.3.0f5
Win 10 Pro
Anyone know why I get this error while trying to add to DynamicBuffer<LinkedEntityGroup>?
Use in normal componentSystem with
Entities.WithNone<SpaceshipFinishedSpawningTag>().ForEach((Entity entity, ref SpaceShipData spaceShipData, DynamicBuffer<LinkedEntityGroup> linkedEntityGroup) =>
Seems like it gets invalidated when you add or instantiate other entities, so "EntityManager.GetBuffer<LinkedEntityGroup>(entity).Add(visual);" worked fine at the spots I needed it.
Hello, still learning. I've written a system that prints a debug message to the console every frame. After adding the second code block, it only prints once and ceases. What am I doing wrong? Thanks
[UpdateInGroup(typeof(ServerSimulationSystemGroup))]
public class GridGeneratorSystem : ComponentSystem
{
protected override void OnUpdate()
{
UnityEngine.Debug.Log("alive");
}
}
Entities.ForEach((Entity ent, ref GridTile tile) =>
{
});
Perhaps remove UpdateInGroup attribute ?
now it runs twice
Tip: Adding 'csharp' or 'cs' just after the triple backticks,a dn then immediately adding a linebreak gives you code highlighting for C#
Where is the second block located? Does it wrap the debug message?
In that case, do you have any entities with GridTiles? Are you sure?
Have you tried using debug breakpoints? Have you checked the entity debugger to ensure you have them?
give me a few minutes and I'll let you know, thank you
GridTile didn't exist after all
@gusty comet A system only updates when the things its querying for exist
I got a weird issue with getting a singleton from a job system.
My job system:
NativeArray<Entity> markets1 = new NativeArray<Entity>(100, Allocator.TempJob);
var firstJob = new FirstJobStruct()
{
entities = markets1
}.Schedule(this, inputDependencies);
var localbuffer = GetBufferFromEntity<LocalMarketComparissionBuffer>()[GetSingletonEntity<KanwisSingleton>()];
var marketbuffermanager = GetBufferFromEntity<MarketDataBuffer>(true);
var secondJob = new SecondJobStruct()
{
buffer = localbuffer.AsNativeArray(),
entities = markets1,
marketDataBuffer = marketbuffermanager
}.Schedule(this, firstJob);
// Now that the job is set up, schedule it to be run.
return secondJob;
}
At first system is taking 0.2 ms but after 5-10 mins it becomes 1 ms and this is what debugger shows me:
http://prntscr.com/qrvwtq
So it... 'allocates' that entity and doesnt 'release' it i think
that KanwisSingleton spawns every frame on the debugger
This is the first time i am dealing with a singleton so i am not sure whats going on
follow up thread https://forum.unity.com/threads/an-issue-with-accessing-singleton-entity-within-job-component-system.814764/
@opaque ledge i think its an issue with the latest entities package
it happens with the physics system too, 0.4 doesnt have that issue so im personally not upgrading yet. this is assuming your entities package is 0.5
@opaque ledge How's the entity list, do you have multiple entities of that type or?
@mystic mountain yeah, i needed to get a list of markets(which implements faction tag component and market buffer component), which thats what first job does, at second job i do the same thing but this time i get market component from that entity list also, so basically i am comparing markets to each other and save that to LocalMarketComparissionBuffer component inside singleton entity
@safe lintel yeah i am 0.5
What I was refering to was in the entity debugger, if you could see that it is creating new entities of that singleton type
oh no, it doesnt create any entities
The "localbuffer.AsNativeArray()" has to be disposed, are you disposing it? *
If you're not, try enable Full Stack Traces for LeakDetection
it doesnt give me any error about it tho
with full stack traces enabled
i think, when you do AsNativeArray it disposes itself later on
AsNativeArray just lets you work with the DynamicBuffer as if it was a NativeArray. You wouldn't want to dispose it since you probably don't want to dispose the underlying buffer.
You can think of it as if you were casting the dynamic buffer to a nativearray
also as a side note, when you create a buffer element data, you should initialize every spot, otherwise when you do AsNativeArray, operation on that array wont be able to access that specific index, lets say i have 10 capacity on my buffer element data, 5 of them initialized, when you do AsNativeArray and want do set index 6 thru that array it wont allow you.
I thought it would work like native container allocation but it doesnt ๐
Anybody knows how Jobs actually handle that you can't use any fields from a Job before it's completed?
leaks show up as warnings instead of errors @opaque ledge
no warnings either ๐
@opaque ledge I see I have the same thing for a singleton I get in my InputSystem
Guess I'll go back to using EntityQueries x)
Weird, it seem queries has worse performance than Singletons.
yeah, looks like its a 0.5 version issue
should i create temp or tempjob native array in a job struct ๐ค
If it's not going to exist outside the job it should be Temp
And don't call dispose on it, it will be disposed automatically
oh ? does that happen when its in job struct or all Allocate.Temp disposed auto ?
It works anywhere. It will automatically be disposed when it leaves it's current scope
oh good, i didnt know that, thanks
singletons are just a query that asserts there only being one and returns the first componentdata from Query.ToComponentDataArray(temp)[0]
@mystic mountain
you can check the source for them in the entities package
Anyone knows how to get the jobindex in a ICollisionEventsJob to fill the needs for EntityCommandBuffer.Current
Hey all, I'm trying to create a helper class that will take an Entity and return it as a container with all the different elements that make up that Entity (components/DynamicBuffers). These helper methods would be called from within systems. What I'm trying to figure out is how I can obtain a DynamicBuffer from within this helper class. Outside of systems you're supposed to get the default world's EntityManager, and within a system you're supposed to use EntityCommandBuffers. Am I correct in assuming I need to get the default world's EntityManager within the helper, even though it's being called from within a system?
entitymanager is always where you get data from the world outside of a system in that world
Alright, thanks!
@gusty comet try just CommandBuffer without .ToConcurent()
it works, but i don't know is it ok to do this or not๐ค
@gusty comet both the trigger and collision events are not yet parallel jobs
.Concurrent only necessary if its an IJobFor or variation of it. as its just IJob then you use the non concurrent version of the entitycommandbuffer ๐
@safe lintel i did not know that! helps alot thanks
is there any difference between Capacity and Length properties of a native container ?
Capacity is how many elements it can store total. Length is how many elements it's storing.
@autumn sleet so with NativeSetThreadIndex above an int property, i can use the concurrent Commandbuffer, too?
@low tangle Hmm, it's werid that with singleton it was round 0.95ms and with manual query.ToComponentDataArray it was around 1.3-1.5ms
looks like it does a mem cpy from the root of the chunk
makes sense because it enforces a single componendata in the archtype iirc
I dont use singleton too often so I dont remember all the gotchas with it
its here if you want to take a look
ln 794
@mystic mountain
Hmm ok
that skips a copy and a native array alloc
Hmm, GenerateAuthoringComponent doesnt seem to work on IBufferElementDatas
that sucks ๐ฆ
@autumn sleet thats nice, thanks for the hint!
@gusty comet no problem
I have a JobComponentSystem that I want to have access to my GameManager object, so from inside OnCreate() of my job system, I call GameObject.Find("GameManager"), but it returns null because OnCreate() is called before my GameManager object is created, how do I make it that OnCreate() is called after rather than before the object is created?
i never tried that but have you check the Script Execution Order ? @odd ridge
if you make your script before default time, maybe that can help
that wont work
system creation is after bootstrap but still before scene load
I suggest either a init function so you can assign it then to the system, or simply do a null check in the systems update and find it then if it is null
OnUpdate()
if(mgr==null) {
mgr = Find("name");
return;
}
etc
Hmm, so GetSingleton from system causes system to run even tho my query returns 0, but i need the singleton so i can feed it to my job struct ๐ค
is there a trick for this or i should just accept it and take the performance hit ?
uh if you want an unsafe route - i haven't profiled this yet:
unsafe struct FetchSomeSingleton : IJobChunk {
[ReadOnly]
public ArchetypeChunkComponentType<U> SomeType;
[NativeDisableUnsafePtrRestriction]
public T* YourSingletonData;
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) {
var data = chunk.GetNativeArray<SomeType>();
*YourSingletonData = data[0];
}
}
ofc - you should replace T with a defined type.
@opaque ledge
thats a scary looking code ๐ ๐
So you would pass the pointer through jobs
Otherwise you could try using OnStartRunning()
to fetch said singleton
ofc checks are necessary - especially if you have 2 of them - or if your data changes in the singleton
Hmm possibly another way @opaque ledge is (needs profiling to see much of an impact this has)
// In a JobComponentSystem
var data = someEntityQuery.ToComponentDataArray<YourSingletonData>(out var singletonDeps);
var lastDeps = new SomeJobForEach {
SingletonArrayData = data
}.Schedule(this, JobHandle.CombineDeps(singletonDeps, inputDeps));
isnt ToComponentDataArray a job in itself so that would be a lot of overhead
Yea - i just don't know much of an impact it has since I never tested it
since I dont use much singleton data - I typically just use GetSingleton<T>() ยฏ_(ใ)_/ยฏ
yeah that seems the simplest way, theres always going to be a bit of overhead because you have to sometimes check if it exists
on a JCS Entites.ForEach, do I have to specify WithBurst?
If you want BurstCompilation yes
on a separate note I wonder how much impact CompleteDependency() has in GetSingleton<T> ๐ค
silly that they also include WithoutBurst then
well you cant debug with burst
Hmm - anyone have recommended readings on assembly and simd? I'd love to learn a bit more ๐
Edit - I might take a look at some processor manuals as a starter ๐ค
but if it's not burst unless you specify WithBurst, what's the difference?
with burst is faster
In JCS ForEach will run with burst unless you specify WithoutBurst
WithBurst let's you specify some specific options
@odd ridge I feel like there's no nice way to do this right now. In the SceneManager class there are callbacks for when a scene is done loading so you can find your game object there. Or you can Inject your GameObject and use GetSingleton in OnStartRunning
Either way kinda sucks. If you can get away with making your manager a scriptableobject it's a bit nicer
By Inject I mean use ConvertAndInject on ConvertToEntity
@zenith wyvern thanks
@zenith wyvern OnStartRunning() was exactly what I needed instead of OnCreate(), I just didn't find the documentation for JobComponentSystem
now I did by reverse looking what you told me
is there any docs about the new build system anywhere?
like, how does one do automated builds with it (how to run it from commandline)
it's kinda relevant now that you can't even build recent DOTS with the old build setup
as a side note, IL2CPP is broken on 2020.1 again with DOTS
just tried a new project done from scratch on 2019.3 with dots + hybrid + unity physics and it built just fine
same project upgraded to 2020.1 fails on it
mono builds still work
it's nothing new tho, IL2CPP keeps breaking all the time :/
you can call the build command from the asset
var buildSettings = Resources.Load<BuildSettings>("BuildSettings/Win64-Build");
Assert.IsNotNull(Resources.Load<BuildSettings>("BuildSettings/Win64-Build"));
buildSettings.Build();
its been a while since I did a build from command line but i assume it should work inside a static script
should yes, I'll try that, thanks
it does work if I let it open the editor window while it's building, it doesn't do anything with batchmode enabled
ah yet another thing to investigate ๐
there isn't anything obvious on the editor.log for this either
i'm trying to setup ecs system in editor with the DefaultWorldInitialization.DefaultLazyEditModeInitialize() which give me a world but adding system don't work when i add system on the editor world any idee ?
Do I remember it right that drawing gizmos is now possible from jobs?
Or debugdraw ๐ค ?
PSA if working with subscenes, removing colliders from gameobjects takes the import process down from 30s to nearly instant. Not sure if this is a consequence of not having dots physics installed. Edit: looks like that's not true.. possibly a combo of that with older subscene content. Unsure.
So i want to create entities in my job component structs, but i cant send Mesh and Material to job struct so i cannot set RenderMesh mesh and material and therefore it wont be rendered, any suggestions on how to go on about this ?
Are latest entities packages compatible with 2020.1 alpha?
@opaque ledge maybe you can create entities in a job, and then do a Entities.ForEach(...).WithoutBurst().Run() to set the components if you need references to those things
after the previous job completes... just an idea, maybe there is a better way
I am trying to do with prefab, lets see how it will go ๐
@twin raven some things work, but I'm getting random issues myself
like, for example the moment I can't make IL2CPP builds work on 2020.1, they still work on 2019.3 with dots
@twin raven yes, with fewer issues than 2019.3 (in my limited experience)
Seems more stable, unexpectedly
I'm getting this now:
In 2019.3.0f5, DOTS didn't work at all
so I'm guessing Unity Physics authoring hasn't been updated to the fast play mode enter
What version?
@next glen 2018?
Typo 2019*
and the error I showed happens on both 2019.3.0f5 and 2020.1.0a20
it's just issue with the domain reload, or more of lack of it
I bet it's a trivial fix
also why is dots not working on 2019.3?
it does work here
It works on 2019.3.0f4. Just not f5
any example what's broken?
After adding a [GenerateAuthoringComponent] component and pressing play, it's a silent crash. There is a bug report for it, but it isn't getting a lot of attention. So it didn't seem widespread
Upgrading to 2020 fixes it 100%. Tried a bunch of solutions within 2019, but all failed
hmmm, the line that gives me errors has this comment before it on authoring script: cs // This requires Entity Conversion mode to be 'Convert And Inject Game Object'
if I move the physics step script out of dots subscene and manually change it to that mode, playmode without domain reload works without errors
I do lose the DOTS Editor's entity conversion preview for that component by doing that tho
hmmmm, it's lack of scene reload that breaks it, not domain reload
Hello everyone, I've been doing OOP for 15 years, and I'm starting with dots a few days ago (you can imagine what my brain is undergoing ;)) , and I have so many unanswered questions in mind, but right now, there is one in particular that one of you may be able to help with: when a system (in my case a camera controller system) depends on different set of entities (different archetypes - in my case a camera and a player - which would be the camera target), what is the proper / efficient way to find the player entity components i need (Translation, but we can imagine it to be something else) for my camera system to work?
And a more general question: where to find "software architecture with dots/ecs" examples / tutorials / or other resources, in order to quickly think "ECS"? I'm not really interested in how to do things with unity, but more of the general process of designing stuff using ECS pattern
Welcome to the wonderful world of ECS! You don't "find" things. They find you
If you want to run a system on a specific entity, give that entity an empty component, which acts as a tag
Does that answer the question?
I get that, but does that mean my camera system should first query for the components i need on the player entity, pick the data i need, then query my camera components after that, and update them using the data from player? I know this is very basic question, but I'm really trying to not go in a completely wrong path ๐
Experienced DOTS people generally recommend this: http://www.dataorienteddesign.com/dodbook/
Data-Oriented Design
thanks @opaque ledge
Camera system will never query anything. One of ECS's major features/pains is it's super modularity
Your system will just act on a bunch of components. A system is only logic. It doesn't know what an entity is
I'm sorry, I've gotta get to work. Can't write up a better explanation at the moment
Enjoy ECS though! It's a lot of fun. A great challenge
Thanks, my brain needs to process that. Not sure to get it, if anyone else can help, that's be greatly appreciated ๐
I guess what does your 'camera system' want to do? Rotate towards a target? Well that could be a RotateTowardsTarget system that just requires a target and rotation tag etc.. so what you start of thinking as a specific task can quickly become very generic.
What is your "Camera system" supposed to do?
Then there's the other aspect of it which is dealing with traditional unity monobehaviours and associating them with entities and/or tagging them with components
@amber flicker this is exactly that "I guess what does your 'camera system' want to do? Rotate towards a target? Well that could be a RotateTowardsTarget system that just requires a target and rotation tag". I absolutely understand that, and the data oriented aspect of it. I'm just asking what is the best way in my system to find the player / or register the player in some way, in order to rotate towards the proper entity
In my mind, the camera system is what makes the camera rotate, so it would run of camera related components
this here is a good example of what i want to do @32:00 : https://www.youtube.com/watch?v=BNMrevfB6Q0&t=2093s
but he's using a hack to get the player position. What would be the ecs way to do it ?
In this video, learn about what's involved in migrating existing game code to the new Data-Oriented Technology Stack (DOTS), which comprises the C# Job System, the Entity Component System (ECS), and the Burst Compiler. You'll also gain an understanding of the performance bene...
For my own camera system the camera entity is just a child of the player entity, so by way of the hierarchy, the camera follows the player. But another way would be adding say a PlayerTag component to the player, and in the camerasystem query the tag and look up its translation/rotation etc
so you'd do two queries in a row, 1 (readonly) for finding player translation, and 1 for updating camera component?
One bit of knowledge you may have not picked up (not sure if it's mentioned in the vid) is that you can use a ComponentDataFromEntity (CDFE) to access components related to any other entity. So, if your camera system knows the players entity, you can look up that players translation using e.g. (very psuedo code) allTranslations = ComponentDataFromEntity<Translation>(), allTranslations[playerEntity]
so if its the camera you want to rotate (still not sure what camera specific things this system is doing but anyway...), you could require e.g. <Rotation, CameraTag, CameraTarget> where public struct CameraTarget : IComponentData{ public Entity Value; } - then yup, you'll need to set the target somehow - potentially using another system. There are many ways to achieve a similar thing though.
i get it
how would you deal with a target entity that may change over time?
is it this other target setter system looking every frame for a target change?
is it a lot more costly to query the target entity from an archetype every frame in the camera system?
So much of this depends on your implementation I'm trying to be helpful in a general way.. which may not be very helpful. Feel free to share code here. If your camera system can only ever focus on one player at a time, it may be worth setting the target of a CameraTarget singleton or something. Common patterns for as things change is either to have a special tag in the archetype or filter a job on change of archetype. I guess you might already know but let's say you have 1000 entities with archetype [a,b,c] (let's say c is a tag like NewEntity), you can have a system that requires NewEntity then have another system that runs at the end of the frame that changes archetype [a,b,c] to [a,b] - this is incredibly cheap because it changes the entry for the archetype rather than changing each of the individual entities - so consequently this is a kind of an efficient event pattern where a system would e.g. only run once, when the entity was created
thanks @amber flicker , still processing that
@safe lintel , hmm adding or removing a component or tag for example
@zenith wyvern I still can't contribute much back to the group, but I found that entityQuery.CopyFromComponentDataArray can be used to sync changes made on a entityQuery.ToComponentDataArray array back to the entities.
Hopefully this helps somebody out there
@gusty comet https://gametorrahod.com/minimum-main-thread-block-with-out-jobhandle-overload/ good read about your thing๐
Oh nice! Thank you @warped trail !
Well I guess another system to ensure say a CameraTarget is a unique entity would make sense in the context of this. You can split up this logic as much or as little as you want, using a query shouldn't have a bearing on perf, just remember to create your query in OnCreate and cache it.
understood
If your system is specifically concerned with when a component changes you can also use the ChangedFilters so it will only run when there's a change
thanks for that @zenith wyvern , guys, I'll try to put all of that new knowledge to practice ๐
you can make TargetableComponent and place it on every object which can be a target and HasFolower component on targets that already has something that following it. Then if that 'something' wants to change a target you can query everything that has TargetableComponent but don't have HasFolower component๐
what is a ComponentDataProxy?
ComponentDataProxy were the old way of "linking" entities to gameObjects - they're effectively replaced via the conversion pipeline
ConvertToEntity
can I still use ComponentDataProxy? is it going to be removed?
You can still use it - just not recommended and I've no idea when it will be removed. The alternative is: ConvertToEntity w/ ConvertAndInject
IConvertGameObjectToEntity is part of the ConversionPipeline - if you want to add some custom logic like spawning an entity paired with the gameObject that will be converted, you can do so there
ConvertToEntity is responsible for starting the process of converting the gameObject hierarchy into its entities format and subsequently allowing IConvertGameObjectToEntity to run in the ConversionWorld
5argon wrote a nice tour of it: https://gametorrahod.com/gameobject-conversion-ecosystem-code-tour/
How do you all feel about unity deciding to focus on their MonoBehavior->Entity workflow opposed to focusing on core standalone ECS?
Ppl have their opinions here - for me personally it fits my needs - since the authoring is a traditional workflow so I don't have to change much
standalone ecs wouldnt have rendering beyond tiny's capability or anything so, quite alright..
@safe lintel I think the hybrid rendering is its own standalone module
yeah its the only way it could work really, otherwise everyone would be forced to use ECS
why do some components have [Serializable] tag but some others don't?
how do I tell what needs to have [Serializable]?
[Serializable] attributes allow you to tell the .net backend that you want to be able to object contents into a file
Serializable has nothing to do with dots, it's gameobject related and the same rules it's always been forever
in the context of unity - you can display regular object parameters/fields in the inspector
Plenty of material on google to learn about it if you're curious
I heard hybrid ECS is not as fast as pure ECS, anytime I use the conversion pipeline, it's not pure anymore?
or is related to using the hybrid renderer?
conversion != hybrid
conversion is literally converting data from one thing to another, can be hybrid or pure
hybrid implies using regular unityengine stuff, so any pure equivalent will most likely be faster.
Reliance on MonoBehaviour components would fall into a "hybrid" style of ECS - especially if you need them active in your systems - e.g. like if you needed the animator
and you use a system to set animator params
hey, anybody knows why environment lighting isn't working after my gameobject is converted to an entity?
i am, let me try
thumbs up, thanks ๐
is this a know bug, or just expected behaviour?
known bug, also setting stuff to static causes issues
thanks , amazing feedback, super appreciated ๐
i wonder if next "big improvement" in hybrid renderer will be HDRP only?
i think its supposed to be improvement for rendering nonstatic entities
im dying for some package updates
I realised how important text align is when converting ugui into its entities' format ๐
## [Burst 1.2.1] - 2020-01-23
### Fixed
- Fix issue with function pointers being corrupted after a domain reload that could lead to unexpected function pointer calls.
- Fix potential deadlock between Burst and the Asset Database if burst is being used when building the database.
- Fix `AssemblyResolveException` when loading a project with dependent packages that are using Burst in static initializers or `InitializeOnLoad`.
### Known Issues
- The fix for the deadlock requires to temporarily disable the ability to click on a compilation error in the Unity Editor to jump to the source IDE.
Anyone here ever serialized a WheelFrictionCurve in the inspector? Or am I asking in the wrong thread?
that doesn't sound like DOTS/ECS discussion
Has anyone seen a more up to date guide to Unit Testing DOTS systems? All the versions I have found so far date back a year and enough has changed that tutorial doesn't work
Are you familiar with unit testing in general?
Because the concepts (that differ from normal unit tests) are still the same - make a world, add the systems you want to test, add enough entities with the correct components, run one frame, then check the result.
Depending on how your code is set up you might also straight up test jobs' Execute method as well, which can be done as you would any other unit test in Unity, though I'd recommend using the 'Unity way' for keeping things tidy, unless you plan to do 'normal' unit tests as well.
@opaque ledge Grats ๐ That moment when you see things actually moving on screen is always so nice.
ikr ๐
Does DOTS currently support 2D physics?
There is no built-in 2D physics module(AFAIK), but if you put a restraint on the depth axis you get a similar result
yeah that or just make the physics yourself
or import box2d
or use gameobject dummys with old 2d components
@low tangle box2d?
I dunno what good that would do
I guess if one could port that to DOTS
Unity already uses box2d under hood for 2D physics
also afaik, Unity is working on 2D physics engine for DOTS but no idea where it's at or if their focus has changed
they technically need it for tiny
Yep
Just pull in box 2d and make your physics entities match, then just have a system that does a sync of their transforms in, run the simulation steps, sync back.
Super easy with systems
It's exactly what they do with havok if you think about it
You have full control so it's much easier to do things like this and have them fully integrated with the rest of the world
This is also how physx and unity 2d physics work
someone did that for bullet and some quite early unity ecs version
I upgraded it for some newer ECS when I tried it
I did this with chipmunk2d
is there some magic way to search for specific things on profilers timeline?
there's easy searchbox for hierarchy views
but now with DOTS jobs all over the timeline, it's really tedious to find small jobs there now
not to mention jobs getting spread to all 23 worker threads on 3900x :/
man I wish I had that many
it really makes the whole timeline view pain :/
I can only imagine how this is on new threadrippers
would be nice if you could force unity to limit the worker threads for debugging purposes
you can actually set the job thread count somewhere
was talked about in here way back when
hmmmm
I dont know if it will actually do what you want but its close
let me see if I can find it
You can set the value of this property at runtime to dynamically reduce the number worker threads available to the Unity Job Queue.
worth a shot
np, let me know how it goes. I'd be interested in the results
well, it does limit the ACTIVE worker threads ๐
but it doesn't like limit it to the first available ones
here I set the worker count to 3:
wonder what logic it uses to pick the workers there
it just picks a random worker and sticks to it
it does stay same unless I restart editor
on new restart I got this with same 3 worker threads:
imagine it's just coincidence it placed those three worker threads so that they could fit into same view at once on these cases
@low tangle ^
worst part is that I can't see the main thread timeline at all when scrolled that much down
setting cpu affinity from task manager didn't change anything either as I think Unity really just detects the hw thread count from cpu anyway
true true
it's same with job count of 1, it just places that one worker thread then randomly somewhere
when I tried it first, it happened to go to first worker which would have been ideal
on next startup, it put it on worker 19
would be good to report
yeah I guess
would be nice for the editor to place it at the top
at least we can now scroll this down again
thread on the forum
profilers vertical scroll was broken for a long time
they only fixed it on some recent 2019.3
yeah, I could make a forum thread about this
I still wonder if there's some way to find specific jobs on this timeline view tho
I've never really had issues finding things from this view prior to DOTS
iirc hierarchy view links it up with the block view
so try clicking it there, then switch and hit f
hmmm, I don't think it links it back to timeline
but I might just fail on using this ๐
I have like simplest job here where I just try to see what happens with debug draws
it does let me do the debug draws on it (using 2020.1)
it's also unbelievable how laggy Unity Editor is on startup nowadays. I dunno if it's because of dots or just in general
it takes like 10 seconds for me to become responsive after it opens
once it's revived itself, it's fine
I wonder if it's some burst related delay when running unity physics etc
and I don't mean entering playmode, just getting the editor usable
ah
Is there any way to have synchronization of Editor changes with Convert and Inject workflow? Current workaround is to have Proxy with GameObjectEntity that will allow do changes in Play mode and have them serialized with ECS.
is there a way to continue with the next cycle of a Entities.ForEach()? Like "continue" in normal for loops?
just return from your lambda, then it will execute the next one
Do you guys think i should make a faction components to each factions like FactionAComponent, FactionBComponent etc. or should i put int field to faction component and make ID from there, like 0 means faction A, 1 means faction B etc..
depends on how you want to filter and/or use them later on. if in doubt, use both and measure the performance with large amounts of entities
@karmic pilot that easy, thanks
So umm, my trade ships doesnt render anymore, everything else is working such as movement but it.. doesnt render, i have no idea why
i will just close and re open the unity, maybe it will work ๐
nope, it didnt work ๐ฆ
sigh now i have to deal with this ๐
Ok, so ECS is still in questionable state by the looks of it :P
Depends on what you're trying to accomplish, and how you do it (built-in? Custom? Porting/coupling external library?)
heyo! is there a way to use interfaces in Burst? when I try it gives this error: "Unable to find interface method ECS_Test.MeshJob.IVoxelType.init() from type object" I'm trying to call methods from an array or a list based on an ID
I guess the interface is somewhat an object so that's why I can't do it that way, but is there an other way to achieve something similar?
Burst does some compilation magic, so I wouldn't be surprised if it simply doesn't support interface
What is the intefrace on? Job? Component? System?
it's a struct that has the IVoxelType interface
Huh, but it seems to think there's an object involved
Wait no, bad sleepy brain, I mixed up object and class
this is all I have, it's just an empty method to test if it even works: ``` interface IVoxelType
{
void init();
}
public struct AirVoxel : IVoxelType
{
public void init()
{
}
}```
when I try it gives this error: "Unable to find interface method
ECS_Test.MeshJob.IVoxelType.init()from typeobject"
@surreal grail
Post the code that's giving you this error
The technical issue aside, that's not very good DOD, I believe
At least if that has anything to do with entities and their components. If it's outside that, then... I dunno.
it has nothing to do with entities, but it is BurstCompiled so it is in DOTS ๐
Data oriented
@zenith wyvern it's just this IVoxelType air_vox = new AirVoxel(); air_vox.init();
thats in a job that compiles otherwise
I don't undertsand the best practice well enough to say anything conclusive, so if some DOD folks could weight in and point at best practice, that'd be nice
Try AirVoxel air_vox = new AirVoxel()
You can't use any kind of polymorphism in Burst
yea, thats what I was trying to achieve
I thought that it was only inheritance that was not usable
I have really basic question here , if I wanted to create additional entities on same conversion script I thought could just use dstManager.CreateEntity() for the extra ones. when the script runs, it doesn't give errors but the additional entities don't show up on the entity debugger either.. any idea what's going on with this?
so then, is there a way to get pointers to methods? ๐
cause I can put those in a list ๐
@dull copper Are you doing basic CreateEntity? It seems more coreect to me to make one, then use that as a template/archtype for more
it's super basic
I create entity, add component to it, setname for it so I can ID it quicly
I have system using the component it has, so it's not like it should be inactive either
There is conversionSystem.CreateAdditionalEntity but tbh I'm not entirely sure how it's supposed to be used
wonder if this is breaking due to some dots editor glitch or because I use 2020.1 atm
that's meant for converting additional gameobjects I think
@dull copper you have to use CreateAddd... ah.. Sark beat me to it.. esp if you want to support subscene workflow, that's what you need to use
Sark, yeah I've seen this FunctionPointer but it will cause me lots of pain without any examples, oh well guess I have experimenting to do
I think you can just pass the original GO
ah, I'll try
I did come across that when trying to figure it out on my own but there's barely any mention on how these should be used ๐
tell me about it... caused (causing actually) massive pita for me
There's no getting around it, if you want to do polymorphism or anything polymorphism-like in Burst you need to jump through some hoops. I've messed with FunctionPointer a little but gave up on it when I found out you can't pass any structs into a FunctionPointer
wooo ๐
var childEntity = conversionSystem.CreateAdditionalEntity(this);
I then added that as ref to my main entity
all good now
@zenith wyvern okay, thanks for the info, I think I'll try to return float3s and stuff, that would be enough for me, I don't really need to return anything more complex
one more craaaazy thing, does this sound possible? : new assetbundles that are loaded in would register their own function pointers into a NativeList that is used by a BurstJob so people could make mod-like assets for a game?
I think the FunctionPointers need to be set up at compile-time
yeah, that's what I'm afraid of
If you really want to get wild you should check out the source for the physics package, they mimic polymorphism for the different physics shapes. If I remember right they use temporary blob assets to store the polymorphic data until it needs to be used
oh that sounds exciting and complicated, might look into that, thank you again! ๐
anybody else get allocation warnings the FIRST time you press play in a scene after editor startup? No warnings on subsequent plays...
I am entering playmode with reaload domain disabled
Its amazing, when i pull prefab to subscene it renders, but when i instantiate from a job, everything but rendering works
๐ญ
Okay well, apperantly i had to do:
DOTS->Live Link Mode->SceneView: Live Game State
this is kinda silly, but I didn't know that math.normalize can return NaN
I hope that this helps somebody out there
I was doing this a lot:
var isNan = math.isnan(nForce);
if (!isNan.x && !isNan.y && !isNan.z)
{
force += nForce;
}```
yeah
close to 0 also normalizes to NaN
So, is there a better way than checking for NaN ?
normalizesafe? ๐
so... of course now that I create entities on code, I will not get that nice entity conversion preview for the additional entities anymore
I wish we really had that DOTS editor
like editor that actually just showed the ECS world, let people pick the objects from it, examine the component values...
working on some GUI for that but theres a few missing things in the entity debug api
@dull copper you sure? i see them on mine, could use a little more readability though
@safe lintel whats that ๐
now that i think about it, i actually have ecs editor ui package but i only have entity debugger
does ecs editor ui package give anything besides entity debugger ?
thats the conversion workflow showing on the source gameobjects
huh, i dont think i ever saw that
yeah but three additional spring entities on the camera are just from code
@opaque ledge this only shows up for subscene entities afaik
is that inspector or some other editor window ?
its the inspector
if you drag the "Entity Conversion" bar up, it might be sorta hidden
ah, i dont have it ๐ฆ component datas are just laid out vertically for me
including for subscene entities
what does it look like?
https://gfycat.com/comfortableadolescenthoneycreeper sure it isnt hidden like this?
@safe lintel I'll check, I have bad experience on clicking that part of the preview as it tends to get click underneath it ๐
like, it keeps giving tooltips of the inspector values that would be under it
like.. not bugged at all ๐
but yeah, it's early
@safe lintel ah I have to click the dropdown arrow
yeah, I see all things now, this will help a lot
thanks again ๐
oh, you can convert that to floating window too
much better now that I could dock it elsewhere
ah nice didnt know about the floating window
so much nicer when don't need to resize and reposition it
I need to figure new editor layout for this now
so many hidden little things, docs team is gonna be put to work when this all gets finalised(heh)
I used to stack hierarchy and properties on same side one over another
but with this thing in addition, it's just super crowded
it's possibly been there always ๐
I asked for exactly that. thank you who ever did add that
at least if they added it later on, they forgot to add it to changelog: https://docs.unity3d.com/Packages/com.unity.dots.editor@0.3/changelog/CHANGELOG.html
it was from one of those closed tests
ah if it was prior to first public version, then that would make sense
yeah
but with this thing in addition, it's just super crowded
@dull copper // Just buy another monitor
I have three :p
but I prefer to keep editor mostly contained on single window, usually only have game view out or if I do shader graphs, I have that on another
I keep one monitor for VS and one for browser/discord etc
upgrade them all to those ultrawides ๐
๐
Buy 4th one
I have 4th one on the floor
make a 360 degree setup so you just swivel your chair ๐
what you dont want a 8k 80"
yeah home project tech has lagged hard
anyway, can fit all in the editor, just need to rethink of the nice placing for all this
Why fit where you can just go VR?
oh wait.... if I undock the entity conversion preview... it does it only for that conversion
it doesn't keep updating it for other selections
this must be a bug
as it makes no sense, especially since there can only be one floating window for this
Actually, that would be fun to try working in VR ๐ค
No, I mean just mirroring windows and tricking it into thinking it has more monitors
I could see lack of resolution becoming a real issue there
maybe better in the future
Would it be noticable with virtual screen being close?
You don't need to worry about monitors being in certain position, you will be able to move them
hey, I'm working on a Native quadtree for points and just finished the range query, in case anyone wants to check it out: https://github.com/marijnz/NativeQuadtree/tree/master.
Insertion / construction is very fast, about .7 ms for the given test with 20k elements. Queries should be fast too but need better benchmarks for them.
My experience with VR says you need pretty high-res screens for a PC desktop to be legible. My Vive is 1080ร1200 per eye, And I have to lean in or stand really close to the desktop when using steamVR's 'see your desktop' feature.
Unfortunately I haven't had the chance to try some newer, higher-res HMDs. From what I've heard the Vive Pro and Valve Index's 1440x1600 per eye makes a pretty clear difference, though. Relevant thread:
https://www.reddit.com/r/ValveIndex/comments/dsl31z/index_vs_original_vive_resolution_from_tyriel_wood/
That's all a bit off topic, though, but I'm playing with the a few potential VR experiences/games, and I would likely try to use DOTS for them, because VR is hard enough on your computer as is. On the other hand, if DOTS means I don't get graphics optimizations (batching and such), then it's right out.
When your DOTS code crashes unity. ๐ต
System.InvalidOperationException: HashMap is full
Thrown from job: Unity.Transforms.ParentSystem.GatherChangedParents
Maybe turning off burst might catch the issue.
Even without burst it crashes pretty hard same error. I'm pretty sure I only have 1 parent component on the entity..
Perhaps because of the command buffer something funky is going on:
commandBuffer.RemoveComponent<Parent>(index, selectionEntity);
commandBuffer.AddComponent(index, selectionEntity, new Parent() { Value = entity });
updated my visual studio 2017/2019 snippets for the new for each and added newjob which was missing
new foreach is RunFor
old is still ForEachEntity
@willow creek thanks for sharing!
That is really cool @willow creek ๐ป I am gonna give a it a try replacing my really primitive spatial hash map
Cheers guys, it's still WIP so be careful when using it..
So, when doing Entities.ForEach lambda you can use WithAll, WithAny and WithNone, but how can you do that in a job struct ?
quote from burst 1.2.1 forum post: We hope to release the first preview of 1.3 in the coming days. Stay tuned!
and this was posted earlier about 1.3:
We are also eager to share as soon as possible the next 1.3.0 preview that is almost ready and which is going to bring several improvements: support for cross compilation, cache of generated code between editor restarts, new LLVM version, improved codegen with no-alias analysis, new x86 Intrinsics API for advanced SIMD scenariosโฆ and more.
For strings, we hope to bring basic support for them for the 1.3 timeframe in the case of Debug.Log and also with NativeString.
This is also allowing Burst to completely remove the dependency from Visual Studio SDK C++ installs or from Linux build tooling. But note that certain platforms (e.g Consoles, iOS) are requiring Burst to use their platform SDK to generate an executable. So the cross-platform compilation is mainly for desktop platforms.
of course plans change but looking forward in seeing how much of this actually made into first 1.3 preview
not requiring VS c++ toolchain will make new installs simpler at least ๐
I hope there will be a new entities release soon which fixes those annoying singleton issues....
@opaque ledge There are [ExcludeComponent] and [RequireComponent] attributes. Though i don't remember their correct names right now...
ooooh i see, thanks i will check it out
Was cross platform deterministic floating point setting supposed to come in the first half of 2020?
Would this mean that we can finally compile to linux with 1,3? ๐
Is there a way to keep an entity from rendering without removing the mesh component?
Haven't tried but adding the Disabled ICD might do it
scratch that.. that will stop it working in other systems too
Anyone else bumped into problem of subscenes and prefabs? Seems when I update prefab that is also in subscene it won't get updated.
Quick sanity check on NativeList<> - the capacity is the amount of memory initially to earmark for the list, rather than the initial Length of the list, isn't it?
@twin raven that was supposed to come a long time ago already
wouldn't hold my breath anymore
2022 then maybe? ๐
@stiff urchin http://prntscr.com/qtjsab
maybe you can add "FrozenRenderSceneTag" ?
altenative to that maybe you can also remove LocalToWorld component if you dont use it
It looks like FrozenRenderSceneTag works good.
thanks! ๐
Now I need to figure out how to do OR queries..
I think EntityQueryDesc with any will work..
Hey what are current restrictions for ecs and android ?? I've seen some post here about float precision, and i'd like to know if there are others know restrictions, i use android build for VR
@wary anchor correct
is doing GetBufferFromEntity and/or GetComponentDataFromEntity within a job expensive operation ? i generally store entity in my component data and use those functions to get what component data/buffer i need, but i am not sure if i should avoid it or not
doesn't seem to take a big perf hit- but I didn't stress test it extensively. I use it if I need to recurse and grab data off the children which can happen to be in separate chunks
I think there was a forum post by tertle where he looked at the perf of ComponentDataFromEntity/BufferFromEntity
thanks, i will take a look
Basicly if you need random access, just do it
So... how is everyone bridging between ECS and Monobehaviours ?
That's what ConvertAndInject is for on ConvertToEntity
Gives you full query access to your monobehaviour
@willow creek thank you!
AddComponentObject on select entitys with managing of their lifetime with a SystemState and a lookup dictionary in a cleanup system @opaque ledge
I can't seem to resize a buffer that's a ref parameter in my JCS Entities.ForEach... How does one do that?
.WithStructuralChanges()
and you might need to get the dynamic buffer though EntityManager instead of as a ref
You shouldn't need WithStructuralChanges. Show the code where you're trying to resize it. @left oak
I got it working. It seems like you can't access a dynamic buffer's methods when it's an Entities.ForEach parameter, so I just used a Job.WithCode and grabbed the buffer with entity manager first
inputDeps = Entities.ForEach((ref DynamicBuffer<ABuffer> buffer) =>
{
buffer.ResizeUninitialized(10);
Works fine
huh, the first time i tried i got nothing
must've made some bizarre syntax error
my bad
all good
for some reason I was thinking you were adding the dynamic buffer then resizing it
which is a structure change. my bad
If I've split up my code into many components and now need to access 8 components in Entities.ForEach (I would do chunk iteration, but netcode is giving me problems), how do I approach that?
i havent touched netcode but there is a problem with it and chunk iteration?
@gusty comet if you are using tag components you can add RequireComponent attribute to your job struct
but since you said Entities.ForEach, you make a query in component system so you can use WithAll, WithNone, or WithAny methods
so Entities.WithAll<MyTagComponenet>().ForEach()
hello, how can i request new feature? for example InnerLoop at IJobForEach
forms, but make sure you structure your request post well
hello guys,
does ECS just for optimizing scripts execution on CPU or can be used for GPU massive instanced of gameobjects rendering?
@gusty comet Currently CPU but you have structured data that can be pass to GPU.
so, ECS is just best method to making massive Navmesh Crowds?? and not for simple massive trees?
@low tangle ๐ its so hard, i forget that.
@gusty comet ECS is Data-oriented programming architecture pattern! you should think about any think that you want to implement. i dont know about unity Supported Components ๐
and where is Entities package on 2019.3.0f5?
i don't know, I'm using last preview. other friends should help you.
@gusty comet from package manager, you have to tick "show Preview Packages" in advanced tab
and after that you also need to install Hybrid Renderer package
then probably restart unity ๐
@opaque ledge
nothing :[
umm, did you check the show preview packages ?
you also need to check "All Packages"
in same row with advanced tab
So in the Unity DotsSample I am trying to add a new object the player could spawn with a button. The object has it's own Ghost Authoring component and everything. In Editor this works. It spawns the correct prefab at the correct location. However when I try to replicate this in a client build the object gets the default location of 0,0,0 and it's scale is also reset back to 1,1,1.
Anyone with knowledge of the sample that could tell me if I am missing a step in the build process?
Anyone knows what "EndFrameParentSystem" does ? whenever i instantiate something from commandbuffer.Instantiate it jumps to 800 ms
@opaque ledge it looks like it maintains a parenting hierarchy for transforms; and does work when Child associations need to be added/removed from an entity. see: Unity.Transforms/ParentSystem.cs
2019.3 is now out according to their latest blog post. Seems to be 2019.3.0f6 (still listed as pre-release in hub). Hopefully some dots packages will be updated shortly, too ๐
How can I set up a system for my entities to raycast if they're going to hit a GameObject
Just need help setting up the most basic raycast system
Like a bullet passthrough?
{
protected override JobHandle OnUpdate(JobHandle inputDependencies)
{
var physWorld = World.DefaultGameObjectInjectionWorld.GetExistingSystem<BuildPhysicsWorld>();
var colWorld = physWorld.PhysicsWorld.CollisionWorld;
var job = Entities.ForEach((Entity entity, ref RayDetect ray, ref Destroyable des, in Translation trans) =>
{
if (ray.didHit)
{
ray.didHit = false;
}
RaycastInput rayInput = new RaycastInput
{
Start = ray.lastPos,
End = trans.Value,
Filter = new CollisionFilter
{
BelongsTo = ray.belongsTo.Value,
CollidesWith = ray.collidesWith.Value,
GroupIndex = 0,
}
};
Unity.Physics.RaycastHit hit = new Unity.Physics.RaycastHit();
if (colWorld.CastRay(rayInput, out hit))
{
ray.lastHit = hit;
ray.didHit = true;
}
ray.lastPos = trans.Value;
})
.Schedule(inputDependencies);
job.Complete();
return job;
}
}```
public struct RayDetect : IComponentData
{
public PhysicsCategoryTags belongsTo;
public PhysicsCategoryTags collidesWith;
[HideInInspector] public float3 lastPos;
[HideInInspector] public Unity.Physics.RaycastHit lastHit;
[HideInInspector] public bool didHit;
}```
I realize I have a Destroyable component in there that is not needed. I was just using it for testing before
Not to pass through, I have a bunch of entities that rain down from the sky
No physics, just moving at random speeds
But I want to raycast to see if it's going to hit the floor, so I can tell it to stop moving down once it reaches the floor
The floor is a flat plane at y:0
@civic bay yeah so you would set the move speed in a separate component and have the spawner setcomponentdata on each spawn so the move speed is different
Yeah I got that already
kk you can then attach this raydetect to see if it passes through a certain physics collider...you can add onto this for added funtionality after the hit occurs or you can make another component that compliments this one
Thanks I'll try and implement it now ๐
@velvet oxide How are you creating the Entities.ForEach job here var job = Entities.ForEach((Entity entity
Am I missing a namespace?
I've included Unity.Entities
"Entities" doesn't exist in current context
using Unity.Entities;
using Unity.Jobs;
using Unity.Transforms;
using Unity.Physics;
using Unity.Physics.Systems;```
another way to find out what your missing if you are using visual studio is cntrl-period when clicking on the red and it will suggest what you need
Do you know what version of Entities you're using?
I always update to the latest
yeah the new way of using the job component system is different now
try updating your entity package?
I'm apparently up to date with 0.1.1 but isn't it on 0.2 now?
I'm using Unity 2019.2.11f1 so might need to upgrade the engine
yeah i'de only use dots with the newest beta of unity imo
so you can test out the visual scripting and whatnot
0.1 is very old, 0.5 is the latest
u need 2019.3.+ for latest entities
Use 0.4 there are issues with 0.5 and singletons
if i need push readonly CDFE to lambda job how i will mark it readonly?
ok, thx, will try
and if i have more than 1 RO data i will write Entities.WithReadOnly(...).WithReadOnly(...) ?
I believe so yes
I donโt notice the documentation or is it just the effect of the fact that I started to learn lambda jobs too late and life is pain?
It actually has one of the best docs pages of any of the dots stuff I've seen https://docs.unity3d.com/Packages/com.unity.entities@0.5/manual/entities_job_foreach.html
yes i didn't notice. Thank you
this is what i looked for
int entityInQueryIndex โ the index of the entity in the list of all entities selected by the query. Use the entity index value when you have a native array that you need to fill with a unique value for each entity. You can use the entityInQueryIndex as the index in that array. The entityInQueryIndex should also be used as the jobIndex for adding commands to a concurrent EntityCommandBuffer.
Is there a way to GetComponentData from a specific entity without using the entity manager? I am trying to make a spawn system burstable using the spawn position as an entity transform.
I know @worldly pulsar posted GetComponentDataFromEntity<Thing>(); but how do you use this to get a stored entity?
example: ```void SpawnProjectile(Entity entity, quaternion rot, ref Shoot shoot)
{
var spawn = EntityManager.Instantiate(shoot.projectilePrefab);
//set position and rotation
var local = EntityManager.GetComponentData<LocalToWorld>(shoot.spawnPosition);
EntityManager.SetComponentData(spawn, new Rotation { Value = rot });
EntityManager.SetComponentData(spawn, new Translation { Value = local.Position });
//set shot data
EntityManager.SetComponentData(spawn, new Move
{
moveSpeed = shoot.projectileSpeed,
MoveInput = new float3(0, 0, 1)
});
}```
so I am getting an entity transform from the Shoot component
I can spawn and set component data using the command buffer but I cant GET component data
ah right, like you said you can use GetComponentDataFromEntity<type>(entity), which will return you.. a list of entities that has that component
oh its a list.. doh
then you can get the component data with GetComponentDataFromEntity<type>(entity)
yep, it also has Contains method so you can check if your entitiy has that specific component
beauty thought I was missing something stupid thanks
yeah they are quite good ๐
@velvet oxide btw, for buffers you need to use GetBufferFromEntity
ah okay thanks!
GetComponentDataFromEntity() returns a ComponentDataFromEntity struct which you pass to your job and inside that job you can do
Entity e = someEntity;
var myComp = compDataFromEntity[e];
DoStuff(myComp);
think of ComponentDataFromEntity<T> like a Dictionary<Entity, T>
amazing that makes things so much easier. Thanks
yup, also compDataFromEntity.Exists(e) tells you if e has the specific component
yeah they are quite useful, imagine that someone doesnt know those methods exists and struggle ๐ญ
havent tried the last package but changelog suggested there weren't really that many changes
wonder if it's even functional now
in past it totally ruined rendering with HDRP for whatever reason and also just having the package sitting idle on your project had huge perf impact
Yeah, I find it hard to believe anyone would pay to use dots physics right now
You'd have to be a real brave company to integrate that with something you expect people to pay for
did DOTS sample have landing page before? https://unity.com/releases/2019-3/dots-sample
No. 2019 is "officially" released today
So there's a bunch of new pages
As far as I can tell there's not much new for those of us who have been messing with the 2019.3 preview this whole time
yeah, I know it released, just reading the announcement blog post ๐
yeah, it's expected, whole RC stage was only getting the engine more stable
For some reason the blog post mentions UIElements runtime, but I don't think it's actually available as a package yet
and beta on most parts too
it's available as package
but I dunno if PM lists it automatically
yeah, its like 0.0.3 tho ๐
I know I had it on my manifest few months ago
Yeah it seems weird for them to be advertising it on the blog post when you have to go to the github and manually add their in-development repo to the PM
I was hoping there was something further along that was integrated already
Oh snap
https://bintray.com/unity/unity/com.unity.ui.runtime/0.0.4-preview was actually released on 21st this month
Maybe it's coming soon then
it is but just fyi pretty sure it doesn't support worldspace and might not support overlay either
do note that bintray is the old registry, 2019.3 actually fetches packages now from Unity's own server afaik
it supports overlay but not camera one i believe
so, there could be some differences on the packages between the two
and yeah no world ui either
you can still put that package to your manifest manually
after it's there, it'll show up on PM and can get updates there
I'm actually quite torn about the runtime UI
I know the reasonable thing to do is to use the old setup
but I really dislike it in many ways
at the same time, new system is still half baked
UIElements feels more natural for dynamic UI that changes a lot at runtime
To me anyways
haha you sure you're only talking about the UI @dull copper ๐
Ugui always felt like I was frankensteining stuff together and trying to piece together stuff at runtime is awkward as hell
@amber flicker well, it's just one of the things, new input, most of DOTS etc are still too broken for me
input system bugs me especially since it almost works for me, just breaks on some devices I need to support
also binding breaks on devices where idle state isn't 0 on some axis
(which is typical scenario for wheel controllers pedals where the pedal axis can be from -1 to 1)
Explore the new features: DOTS updates and DOTS sample
literally the entire page on either Experimental or Preview ๐ค
Seems like they're really going out of their way to highlight the fact that this is not a LTS release
Based on their release cycle we can't expect dots to be stable for another year at least
I really liked that they did mention 2019.3 shouldn't be used in production
it's not what they've messaged before about tech releases
they are essentially previews toward the upcoming LTS and should be treated as such
this is new too: weโre reducing the number of TECH stream releases from three to two per year.
it does make sense, considering they keep falling behind on 3rd tech stream all the time now
tbh, they could just have one tech stream and put feature freeze to it on Q3-Q4 and then just keep stabilizing it for LTS
this is bit off topic here tho
surprised the dots sample gets such a fancy landing page when it feels so rough around the edges
Any newbie advice I can solicit here for making accelerator structures (spatial hash maps, trees, etc) that don't take me straight to dependency hell?
Do you mean that as a DOTS-specific question?
Definitely, yes
Everything I do that sounds good normally just screams runtime errors at me about previously scheduled jobs, etc
If you're asking how to share a container between systems without managing dependencies the answer is DynamicBuffers
Otherwise you need to manually manage your job handles.
If you absolutely can't fit your problem into a dynamic buffer you should look at how EntityCommandBuffer handles it with AddJobHandleForProducer
I'll try to rely on dynamic buffers, thanks. Native containers make me tear my hair out.
Are dynamic buffers that exceed their internal capacity a special case? Any special care I need to take?
They automatically resize themselves
As you add to them
If they grow too large I believe they lose some mild performance from not fitting nicely into a chunk but it's not worth worrying about unless you're doing something insane
Better than breaking the DOTS model, at any rate
With DOTS, in many cases you should probably ask yourself why before trying to use some complex collection type (so basically anything that is not basically arrays). Of course you can use them outside jobs, but if you're using such complex data inside a job... why?
It might be valid, mind you, but it might not. I've made a habit to stop and think whenever something I try is hard to achieve
That's worth thinking about. I feel like I'm supposed to jobify all of my code when using dots, but that's obviously a misconception.
Yeah, please consider usage of IJob and IJobParallelFor as well, they are not entity Jobs, and i am using on many cases in systems
Also, native arrays is pretty useful and the only way to get results from a job, so maybe if you explain your issues with it we can help better ?
they are kinda core mechanic imo, maybe you should invest in them
I thought I could do everything with Job.WithCode and Entities.ForEach, but that's seemingly not the case
I.. think you can, but it depends on what you are trying to do
How do I even dispose of a NativeHashMap.ParallelWriter?
It doesn't seem to expose its Dispose method
For example, in one of my systems i run 3 jobs, first job gets faction's owned markets, 2nd job gets some data of owned market to market comparision, 3rd job creates trade ships according to results of 2nd job, so i use native array to carry data job to job, and my 3rd job is IJob, and it calculates what is the most profitable route and creates a tradeship
Are you trying to write to NativeHashMap in a job paralely ?
@left oak ParallelWriter is wrapped around the original container. You dispose the original NativeHashMap.
so, is the original a member variable, and the parallel writer is local?
NativeHashMap map = new ()...
var writer = map.AsParallelWriter();
inputDeps = Entities.Foreach(// Uses writer)
map.Dispose(inputDeps);
if you are only creating that hashmap to carry data for jobs, then you should create with Allocator.TempJob and call .Dispose() after all jobs are finished.
Does that make sense?
yeah that makes sense, thanks
yeah nativearray seems a lot easier, cause you can just DeallocateOnJobCompletion
you cant do that on hashmap ?
All the containers seem to have Dispose(jobHandle), works the same way and makes it clearer when it's actually being disposed
also a side note, if you create a nativearray with Allocator.Temp, you dont need to dispose it, but otherwise you need to, but you cant use it for jobs
interesting
You can create temp containers inside jobs. The only rule is they are disposed as soon as they leave scope, so you can't pass them to anything
I'm torn on how to implement a spatial map: I could see myself using a native hash map that consists of keys that are the occupied integral coordinates; or, I could make an enormous dynamic buffer that's an xyz grid compressed into 1d and just index into it by a hash of the coordinates to check for occupancy. The former seems easier, but the latter seems better.
look at boid sample, i think it will help you with spatial map๐ค
The boid method is a very specific use case though where the map is only used in a single system. It gets a lot more complicated if you want to have a spatial map that's used frequently by different systems throughout your game
Still not sure of the best way to approach that problem myself
yeah, if I was throwing many things into fewer buckets, I would do it like the boid sample
this is more of a voxelized "is this coordinate occupied, or not"
I can't decide if it's better for each system to make its own map, if it needs it, or to find a way to share a single map
The former's certainly easier, but involves a lot of duplication of efforts
You could always fully integrate it with ECS where each bucket is a DynamicBuffer, with a SharedComponentData for it's spatial index. Something about that feels off though, but maybe I'm just not thinking about it right
Is your space limited, as in, do you know how big it will be?
How frequently does contents change? (several times per frame, once per frame, every few frames, once per second, etc)
I was starting to do something like that for my voxel game but it was so horribly annoying to work with SCD I gave up on it
I could def put in hard limits and just eat the space cost of creating a huge "3d" buffer
But I liked the NativeHashMap solution, as it works without setting bounding boxes
For voxels... I have been thinking about how I'd do a voxel game (or 2D equivalent), and basically came to the conclusion that I'd either go restricted (known, bounded) size, or probably move all the generation out of entities and possibly partially systems and just save the end result.
At any rate I'd start in non-DOTS(prototype the logic/algorithm), then jobify the procGen, then put the end result in entities, and see what I did from there.
Yeah I was trying to make a Minecraft clone, with the blocks set up like I described, it was not fun
it's def a hard problem
You have jobs that produce the mesh and then turn that into a ecs render mesh and collision
The end result should hopefully have chunks being single entities with just the mesh (and related), and the actual terrain data existing in ECS-friendly structures elsewhere (when it was loaded - otherwise just serialized to disk)
You will be working with native arrays mostly to create the chunks
If more convenient, I might put the data in entities, but I feel like that would add complexity with little benefit
My biggest headache was, no big surprise, trying to explictly define my spatial map in a NativeHashMap. I think it might be better if I was going that route again to just restrict all chunk access to queries via SharedComponentDataFilter
You can do a full chunk (unity) based chunks
With the data per entity but I would not suggest doing that till you really understand the way memory is stored in them. To do it that way you well be still using a single entity as the output mesh
You mentioned integer cord bullets buckets into a hashmap, that's what boids does and it's quite fast. @zenith wyvern
Actually, some ChunkDataComponent holding the data with an associated ChunkPositionComponent on the same entity, and an external map/dictionary of those entities (Dictionary<int2, Entity> or native equivalent) could work...
@tawdry tree That's exactly what I tried to do
I'd suggest if you need to look lots of things up, just use a hash map, multi if it makes sense, and don't over think it
I really ought to get back to experimenting with that; been distracted from Unity and ECS for too long. Just updated the editor, though.
Managing the native container for access between systems was an annoying headache
Stop trying too make things more complex than you need. You need to just try and figure out if the simplest solution would work.
Yeah that's why I would just stick to entity queries next time for all chunk/block access. Let Unity manage the dependencies for me
Of course like it was said, if the world is bounded everything becomes a lot simpler. In my case trying to fit the concept of an infinite world into a NativeContainer was a bit too much for me
Yes, obviously I would load/unload chunks as needed
Meaning you can add another array that was the index map
I never even got that far because chunk and block access became so annoying to manage I gave up
I'll actually be writing a voxels generator soon
I can share how I solve it and how fast it runs if you like
Sure, I'd be interested to see how other people do it
If you can release the code for the relevant ECS and jobs, that'd be super helpful, partially because it's a common mechanic/feature, and partially as a 'real example'
in fact, the very loose coupling makes that a cakewalk with ECS
Or more like, if you do ECS correctly there is no coupling unless needed?
Yup
Typically the only coupling is the base data types, but not even the structue
Code is a mess
It's not bad
My philosophy when it comes to collection types in C# is:
- Use list. Seriously, why not?
- Arrays if and only if you know the specific, fixed size.
- Dictionary, queue, and stack are convenient and have a place
- Otherwise, ask yourself why?
- Really, though, you can probably just use a list.
That's in general, of course; with games, ECS, and looking for perf there are concerns that outweigh 'just use list, dummy', but as I get familiar with the relevant collections I figure I'll end up with something similar.
Theres a really good section in the dod book on this
Oh, and to be clear: In that philosophy is the assumption that the code is not performance critical, and will run on decent, modern hardware.
Basicly, you can gradually go up the complexity scale if profiling actually says it's slow
But not before
That too.
Premature optimization (root of all evil and all that) is not about being smart about choice of algorithms and data structures - it's about avoiding complexity and losing convenience/readability/maintainability in favor of some nebulous potential performance loss.
I saw a talk, by Kevlin Henney I believe going over that. If you think it's going to be slow, profile it! And if it is slow, make sure it's a part that you care about whether is slow or not.
Exactly
Don't go for the big guns when you are developing something new. Think, plan, prototype with simple solutions
Don't just jump into chunk iteration with 4 hashmaps and 2 custom ones
That's got a good chance of being in the wrong train of thought anyways
How would you represent a chunk?
Think about the data first, not how you would process this complex idea
Meaning a voxel chunk, not the ECS chunks
The raw data would probably best be stored as an array type structure - in this case of known size, and outside ECS you could make it 3D, or 1D for some more complexity but also better perf
I eventually landed on just a DynamicBuffer<byte> for block types. Then per block data could be added as needed with SharedComponentData
For example, I've made 16x16x16 chunks in mono-land, stored as 3D arrays for convenience
It works well since, yeah, a chunk is by definition a finite space
Bear in mind the difference between infinite(unbounded), and finite(bounded) and known(specific) sizes, too
dynamic buffer with internal capacity set correctly to stay in chunk memory. Then a some for each runs over each 'chunk' which is a CD generating and updating it's own mesh
That simple
For me the mesh was the easy part. The hard part was deciding how to iterate over voxel chunks in a readable way
SCD doesn't make it very readable
Got a 'chunk'? Generate a mesh
It's all in a single dynamic buffer
Per 'chunk'
Need to edit a block? Find the chunk, set the index in the buffer
I was wondering, i have a very big DynamicBuffer which exceeds the size of a limit of an entity so i guess Unity carries it to Heap and not in a chunk, does this impact performance ? should i avoid it somehow or its an acceptable loss since buffer needs to be that big anyway ?
Right, and let's say I want to place blocks across three chunks. I figure out the chunk indices my blocks are covering, that's easy. Now iterating them is something like:
NativeArray<int2> chunkIndices;
for( int i = 0; i < chunkIndices[i].Length; ++i)
{
inputDeps = Entities
.WithSharedComponentFilter(chunkIndices[i]).. Iterate
}
Does that seem right to you?
well, right now its 1190 item amount and size is.. 120 KB
Personally I don't use shared components
That's basically the direciton I was heading
But yeah that looks fine
What would you use instead?
Yes that will never fit, 16kb is chunk size @opaque ledge
There pointer to unity heap is fast
So don't worry about it
ah cool, thanks ^^
Profile if you are ever worried
Always use large n when you do
Typically 1000, 10000
@zenith wyvern I'd use a format that doesn't need to be sorted
I'll get up and write some code hold up
If you can give me a better alternative to SCD that would be amazing
Because SCD sucks
what is this spatial thing you guys are talking about ?
@opaque ledge Basically a spatial hash map that's fully integrated with ECS IE: Not a native container
Yup
You should, but tl;dr grouping data by 'position' in 'space'.
it's a mathematical concept, and as such applies to 'space' that is not about actual positions, but in games it usually is.
space as in 2d/3d space or.. arbitary type of input ?
yeah actually nevermind, i am too noob for those i think
i will just make some simple ECS systems and go happy when they work so i can boost my self confidince
thats the sprit
the way I look at it is ecs games are wide not deep when it comes to the code
if you can make simple systems to achieve the little bits of logic you want, you can make the whole engine
The same data structures are used in some AI stuff, among others. Except there the 'dimensions' tend to be pretty much arbitrary data, and a lot more of them.
@opaque ledge Just look up spatial hash or spatial partition tutorials, there should be plenty online that are outside dots so much easier to understand
Spatial partitioning, that's the good keyword
will do ๐
Btw, does ECS works with Unity UI or UIElements Runtime?
like.. can i turn them to entities ?
its going to eventually work with UIElements
