#archived-dots
1 messages ยท Page 22 of 1
yeah maybe, but I'm only syncing the main character so don't really care about performance. I don't think I knew about the built-in options when I wrote it and haven't gone back to it yet.
companion transform already creates garbage per companion so id say anything else is gonna be better unless 1.0 brings improvements
IIUC, the scriptable object bridge thing is mainly there to make it easier to access input from lots of different mono behaviors. If you go the ECS route, most of the input handling will be in systems instead. It is still possible to do something similar, but the workflow will be different.
I would stick with normal game objects in this case. And just keep DOTS in your back pocket as an optimization tool.
Thanks. It does feel like I'm setting myself up for a lot of pain otherwise. I really want to start getting a handle on DOTS, especially for my more ambitious projects, but it feels a little like coding with one hand behind my back. :p
ECS is totally other way of thinking
From my experience, ECS is great once you get the hang of it, but even then, I spend a ton of time figuring out nicer ways to handle certain problems. Input is actually one of those areas that I've been meaning to come back to. There aren't really best practices for a lot of things yet so you'll need play around with things and be willing to refactor everything.
I have found a nice approach for input for me
using components as input, and making systems run based of existance of queries
Yeah, I can't remember if I already asked you but weren't you doing the thing where you had a singleton per action?
yeah, this
tbh
this approach is not THAT good, now that I think
because you can always extend any input
by creating new input component
and extensibility was key for me
I'm ok with this, I've been "around" Unity for a long time, but never really had time to settle into a committed period of working on it. Meaning I start getting some things figured out, then life and work happens and I step away for 6 months, and when I come back it's ground zero again. I have been wanting to jump on the DOTS bandwagon, as I think it's the future, but I also have some hard deadlines for this prototype, so will need to balance desire with reality.
I have a lot of systems that start with something like:
if (!GetSingleton<Input>().ActionIsHappening) { return; }
Using RequireSingletonForUpdate seems like a nice way to solve this.
actually I just figured
someone else's approach
by creating huge struct of all inputs
is just better
the idea is this
you create entity, give it this component data struct
and never touch it ever again
it'll be static entity, kind of like world time entity
you grab pointer reference to that struct
and viola
the fastest access
to any field of this struct you want
for now I just don't see how to ease all code boiler plate it brings
as in my approach I used reflection
I assume some system needs to update the component data and would need to be done safely. And I would still need to check for an input in each system instead of conditionally running the sytem. It seems pretty much the same as the GetSingleton<MyBigInputStruct> approach but presumably faster and without and dependency tracking
well, you're supposed to only write data through New Input System
which is done even before Initialization group
so it would be safe to use as pointer
quite literally just like Time component
Ah, didn't know when it ran. I use the C# class generation thing to receive callbacks but then write input in a system at the start of the init group
That seems like a good option for performance, but you can no longer make systems conditional on some input.
well, you can
but you shift that check
into Update method
tbh, not even sure what's faster
early return in Update, or not calling system at all through query
yeah that's basically what I'm doing now with the early return. But GetSingleton is a query so I guess its probably similar to the RequireSingleton approach. So I guess your pointer idea avoids any query.
GetSingleton is super slow
if it's only one entity
which gets this singleton
you should cache entity
and then use GetComponentData instead
Good to know, thanks. I'll can try that, although I don't look forward to having more boilerplate
RequiresSingletonForUpdate and GetSingleton go pretty much hand in hand. does it even help to cache the entity when the system has to calculate if it can run?
GetSingleton has to find required query
while get component data looks for exactly what you want
read again ๐ not what i'm getting at
but I didn't mean RequiresSingletonForUpdate to be required
when you don't need RequireSingletonForUpdate because the singleton gets created in OnCreate of the system, sure thing. with the update requirement the query would still get evaluated
still, GetSingleton is simply slower, because it has to find required query
problem i see, most singletons are not created in the systems that also use them. otherwise, why make a singleton and not just cache the data directly in the system
i'm not saying otherwise
Let's say I want a system to update when left mouse button is pressed. From the options we talked about:
- Have one big input singleton. Return early if GetSingleton<Input>().LeftButtonPressed is false. Can use RequireSingletonForUpdate on the big input singleton, but let's just assume it always exists.
- Same as above, but cache the singleton entity. Check GetComponent<Input>().LeftButtonPressed instead.
- Have singletons per action. Use RequireSingletonForUpdate<LeftButtonPressed>.
- Create something like the world Time component.
I may be grabbing the cat by the tail here, but I would think the Singleton pattern won't work well with Jobs and the Burst compiler. Unless the info in the singleton is read only?
Its basically readonly, yeah. And in my case, I check inputs prior to scheduling jobs so this is on the main thread anyways.
singleton pattern doesn't usually contains data
The new Input system is Event -driven though, so the singleton approach kinda pushes it back to the old Input. Is there no better way to take advantage of this event-driven model in combination with DOTS?
and if it does
it doesn't matter anyway
because input rarely gets to work with jobs
all of my input systems are ISystems
that run on main thread
icomp singletons are nice for options/settings the player has. shared between many systems, mostly readonly and only some options menu can write to it
I have a system that collects these events and writes them all at once at a specific time during the frame. Maybe that is not the intended way to use the new input system, but in my game, I need a specific ordering of systems and input handling. I don't want systems getting triggered by input at arbitrary points in the frame
I'm curious, how do you handle input?
i have written a few ways but i settled on nothing special, not even a system. MBs Update run before entities update so I gather inputs there and done ๐
again, at the risk of being the noob in the room, is anyone using ScriptableObjects? it sounds like many of these singleton problems can be solved with them.
how do you imagine that?
Do you then write the input to a singleton and read that from systems?
not quite, it's manually done and written to the correct entity. player/ai are all driven by the same input format so singleton wouldn't work. well, it would just for the player but it's not necessary, i know which entity to write to anyway
about singletons in general, use them when the data is shared between systems. otherwise, just use system data. that works also fine
(or just work with a known entity)
unless your system has like 100s of queries getsingleton isn't that slow...
(i'm all for caching things though)
agreed, it never catched my attention to anything i've done. if it makes life easier go for it. (i keep queries/systems down to a minimum - i can see a point where it could get problematic - some devs have like 300 systems or something crazy ^^)
everyone enjoying their dose of dots news?!
yeah forum is very active recently
i for one love the, everyone speculates before release /s
i'll say the same thing i say every week. next week!
we'll see ๐
eventually i'm right. just a matter of time
i've said this a couple of times, i'm a bit dissapointed there's no mention of other things. sure, the new baker is nice and looks very streamlined but what about the other stuff. there must be more
no one's asked
lol, maybe that's it ๐
Sorry, I meant specifically rendering ECSs using the hybrid renderer on Quest 2...
Personally, I'm most excited about the better editor integration stuff they showed off: https://www.youtube.com/watch?v=p4ct4vHWYt0
This video covers the improved Editor tooling in the upcoming Data-Oriented Tech Stack (DOTS) 0.50 release, including the Hierarchy, Inspectors, Profiler modules, Systems window, and entities journaling. It also addresses a new Editor workflow, coming in Entities 1.0, which allows artists, gameplay programmers, and level designers to author with...
and now i did ๐
anything specific? journaling and the conversion switch i know of
i'm not sure if hr runs on quest 2 but just as a general comment, it does seem like quest would be a good use case for leveraging it
given it's basically a mobile platform with quite limited performance
i for one am quite excited by a few features or potential api changes
(though I am still concerned about 128 entity limit, but i'll profile and bring it up once i get to test rather than jumping on the anti-hype train)
Journaling is the main thing
Also, I don't remember if I they confirmed in that video, but scene view picking of entities is something I've wanted for a while now. Based on some commits to the graphics repo a few months ago, I think it is going to be in 1.0
oh i implemented this a long time ago
i can just give you this
Oh nice. I have something similar that works in the game view already. Hover an entity and press a button to pull it up in the inspector. But haven't tried to get something working in the scene view.
even works with skin meshed renderers that you've attached to entities as hybrid
If you want to share it, that would be cool
i think this is the primary code - it's definitely going to miss something small
i keep saying i'll release this core library but i keep getting lazy to cleanup some editor tool i need to remove first
i'll see if i can do it today because it's getting ridiculous
Yes it would.
I'm getting shadder compiler errors (I forget what exactly since I'm not at my computer right now)
When I googled it, I get the impression it's not supported yet but I can't find a definitive answer...
afaik quest is android right which would be Vulcan ( the graphics driver )..
a quick search on here brought this comment:
in the #๐ฅฝโvirtual-reality channel
as far as i know, hybrid renderer does support vulcan so i'm guessing it's a case of getting the right combinations of unity editor and graphics driver version
in the Hybrid Renderer docs:
I tried disabling everything but Vulkan and still have the error
Think it's an actual shader error, don't think the shader is designed for this use-case
ok done, wasn't even that time consuming. going to head to gym and do a final build check when i'm back
and release when i'm back
wait what's the news?
Read forums, flurry of posts
don't worry, there's more ๐ my top two personal favorites, if i have to pick, are the job system rewrite (purely under the hood) and bursted isystems actually working. together they represent a pretty significant speed boost
(probably biased because i work on the team for those things though)
great to hear, i'm mostly excited about ISystem stuff. are nativeContainers also working now in ISystems or do we still have to use UnsafeContainers?
yep nativecontainers work now
np! also p.s. enableable components and unmanaged shared components are pretty good too
includes "actually working" ECB system too? that was also a roadstop for some of my systems
you mean if I stack 10 ISystems in 1 system group they all will run with 1 burst call?
wow you got it all covered!
ehm. let me check.
(i would be kind of surprised if that was a big deal either way? because the burst call overhead should be small compared to a whole system update. but checking...)
I think it is a big deal, because this way it can run both, internal logic that determines whether system should run AND system's update all in one go
add to that stacked systems and it save quite some overhead
it's 10 separate calls because it wants to have a catch around each update, and you can't catch in burst. i would be very interested in a profile where burst call overhead made a big difference here
i should say that in 1.0, systems are [alwaysupdatesystem] by default, and you have to sign up if you want to require matching queries for update. this is because everybody was always going insane because their systems weren't running and they forgot to say alwaysupdatesystem.
also, if you don't require matching queries for update, and you have a bursted isystem, you can just check if the queries match at the top of your update, and it should be just as fast
(i haven't profiled this comparison, it's just my intuition)
interesting, that change is probably for the best.
don't be a stranger! we'd welcome to have more involvement from team members around here ๐
{
// This reference provides read only access to the Turret component.
// Trying to use ValueRW (instead of ValueRO) on a read-only reference is an error.
readonly RefRO<Turret> m_Turret;
// Note the use of ValueRO in the following properties.
public Entity CannonBallSpawn => m_Turret.ValueRO.CannonBallSpawn;
public Entity CannonBallPrefab => m_Turret.ValueRO.CannonBallPrefab;
}``` so this look like unitys way of giving us reference types without unsafe code. otherwise i'm confused what the purpose of the aspect is when every value is in Turret anyway
uh [BakingType] attribute is cool. we are then able to put a dynamicbuffer or whatever on the entity which is removed after conversion
and GameObjectConversionSystem is obsolete in favor of [WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)] on SystemBase/ISystem
Well that's good because i like cakes
i always felt what was missing was a good baking system
deceptively hard to get a good sponge
yep it felt a bit tacked on and not very streamlined
yeah a bit of a mess tbh
How do you currently handle transform.position in entities?
is that question related to the aspect?
burstable transform access?
i mean you could just directly access the underlying components of a transform. aspects are just convenient
I mean the every equiv
Like translation is local
So is you want you want to set world position you need to check for parent, use local to world
Update translation to make sure you're world value isn't overridden
It's a huge pain replicating game object transform in entities atm
This is what I believe aspects can help solve
well isn't the problem also that we can only get access to transform in IJobParallelForTransform? TransformAspect looks like a built in helper for that
I'm not talking about gameobjects
I'm talking about replicating the same easy to use api that object transforms have but for pure entities
ah i see
In entities 0.51 how do you set an entity in a hierarchy to (10,0,10) world space
but how would aspects solve that problem? the comps are local to the entity still and the same kind of data queries need to be done to determine what has to be set
It wraps all the data for you and provides an api
yeah sure, not 20 ComponentTypeHandles needed then
as you can directly query aspects the question comes up, how does it handle comps that are not added. like where we are using chunk.Has<T> now
Without actually having source, hopefully transformaspect provides, position, localposition etc
Does it manage getting parent/hierarchy translation data etc in order to get set world and local values to a child?
So I guess it could potentially be expensive if not done optimally
if it doesn't it's kind of superfluous, just reducing boilerplate code isn't enough to get me to use aspects ๐
To me aspects are the most important feature of entities in the future
That was kinda my thought tbh enzi
But yeah i think that's very true also
I'll be preaching for 6 months and finally convince everyone
it's not the same as subscene hate. it's like Entities.ForEach hate ๐
when aspects give the same control, fine. ๐
ForEach are great tho ๐
same goes for, can i get the pointers
and does it actually play nice with burst and simd
If you want entities to be popular you need to make it as easy to use as gameobjects
And the first step is making transform usage that easy
Kinda true tbh
Stop people having to write complex maths to do basic operations
The ground level stuff is currently way too involved, I do see the point
yeah agreed - i have to say though, because i have written the current project so often in different forms. entities will never go actual mainstream. OOP is just too convenient and fast to write
i've been doing this a long time now and my productivity just can't catch up to OOP shenanigans.
so in that sense, a LOT has to happen for entities to get really mainstream
I think theres still too much obvious stuff not benefitting from dots, animation etc
99% is developers don't care about this though
Most gameplay programmers will never touch a pointer in their life
One of the true benefits of unity is rapid prototyping and the ability to just throw together a game in couple of weeks.. that's really not possible with dots atm, too many hidden traps etc
Conversion is the ballache of all ball aches
How so
Jeez, dont get me started, it's all over the place
Monos subscenes this works this breaks that breaks this but not that etc etc, endless headaches
Works flawless for me ๐
Though I will say I put a lot of effort into getting my architecture how I want
i guess we have to stop talking about different target audiences. i strictly talk about myself and what i want ๐ anyway, i agree with what you are saying and the steps to be more appealing for mainstream. that said, i just don't see any junior gameplay programmer doing anything in dots for a while.
Once you know what you're doing and have a workflow yeah
I feel like that's a tricky problem to solve. Are you are suggesting that Aspects should be able to read/write data from other entities? Even if that were true, I feel like there are complications. Like what if the parent's Translation was modified earlier in the frame but that change wasn't been written to the parent's LTW yet. And then you try to set the world position of the child. Is the aspect supposed to use the parent's LTW or recompute the parent's LTW from the parent's TRS components?
You don't need to read other entities
You have a local to world
You just have to know if you're a child or not
i'm definitely a child
lol
๐
All this type of stuff is secretly done under the hood for you in game object land
What about when that LTW isn't up to date? Like something else modified the Translation component of the entity earlier in the frame.
i think the simple answer is, don't do it ๐
Up to the user really
I'm curious if the transform aspect will write to LTW immediately when you modify the local position.
and cases where LTW is not up to date could mean an ECB is involved
You can make your world changes after transform system group is you need up to date positions
it probably will. too many problems otherwise i think
but we don't even know if TransformAspect covers this. it's just speculation
Entities promotes flat hierarchies where possible
Which is good, it's performant and why this problem hasn't come up that much
Yeah definitely. But that requires knowing how the transform systems work. If the goal is to make it as easy as game object transforms, I think they would need to remove the delayed updates of some of these components. And maybe aspects are a way to do that.
But there are still cases where you might want to move a child in world space
aspects are just convenience; all this stuff you're talking about is to do with the new proposed transform system (not for the first experimental release), which is supposed to help with some of the harebrainedness, but still has some kinks to work out
are there any more tidbits about the new transform system you can share? will physics utilize it?
also will it(new transform system) be part of the upcoming experimental releases this year (if it is not in the initial release)?
https://gitlab.com/tertle/com.bovinelabs.core
here you go, I've probably posted like 90% of the stuff in here at one point or other but at least now when I post something you can get the dependencies
it should be non-destructive in the sense that adding it to your project should change nothing by default (if you open settings though it will generate a scriptable object)
will be here once processing is done: https://openupm.com/packages/com.bovinelabs.core.html
lots of great stuff in there. you should make a readme at some point what's all included ๐
in 0.5-2 years i'll release my game library
took me 6 months to delete a folder and make it public, that might take a while
haha, i was half joking
ah bloody hell i already screwed it up didnt delete a meta updated
so for a simple close button in UIToolkit i can write btnClose.clicked += () => { asset.ShowVisualElement(false); }; the asset (main container) is snapped there. all good, but what about when i want to move this to a method? i haven't found a way to provide the necessary paramaters to a clickEvent
what do you mean?
can't rider just generate a method that matches the delegate for you
i can make a delegate but that would also have no parameter. It's just a simple Action, no parameters. there's also RegisterCallback<ClickEvent> - it's really the typical problem that UnityUI solves with EventSystem.currentSelected or something. a method has been called but it doesn't know from where. the UIToolkit sample mostly uses methods that rely on private variables from the class. i haven't found anything else.
https://forum.unity.com/threads/core.1340078/
i included a few highlights
okay! i mean, oh K is in there.
oh so you want to know what button selected?
you want to have have multiple buttons mapped to same method?
btnClose.RegisterCallback<ClickEvent, VisualElement>(Clicked, asset); private void Clicked(ClickEvent evt, VisualElement root) { root.ShowVisualElement(false); } that's kind of sick. i'm warming up to UIToolkit ๐
hehe, i wondered the same thing with ClickEvent. how many events exist? - in my case, i can remove it. i just need the root which needs to be closed by the button
what i find really cool is how we can provide parameters for methods. that was usually not so great
i just want this, but on a single page
instead of having to click through each individually
yep, overviews are always nice. first time i reported a problem on a help page because these basic examples are kind of meh. without a forum post i would never have guessed RegisterCallback has a custom parameter. on 2nd view, rider would've shown me but i missed it
honestly i didn't know
i don't recall having a case for it, but my UI use is pretty basic atm
learning these things is why i hang out on discord!
how do you handle close button events now?
i just change UI states
{
var state = this.GetSingleton<ClientState>();
state.Value = new BitArray256 { [K<ClientStates>.NameToKey("host-game")] = true };
this.SetSingleton(state);
}
private void JoinButtonOnClicked()
{
var state = this.GetSingleton<ClientState>();
state.Value = new BitArray256 { [K<ClientStates>.NameToKey("join-game")] = true };
this.SetSingleton(state);
}
private void OptionsButtonOnClicked()
{
var state = this.GetSingleton<ClientState>();
state.Value = new BitArray256 { [K<ClientStates>.NameToKey("options")] = true };
this.SetSingleton(state);
}```
rest is handled for me by my UI management/state systems
switching states would close current panel
(i probably need to add a shortcut for this in the base class to clean up this api a bit - been ages since i've touched it)
oh i see ๐ you circumvented the need for it
yeah for example when that clientstate for options is set
my OptionStateSystem starts running
protected override void OnStartRunning()
{
this.UIStateSet(K<UIStates>.NameToKey("options"));
}
and changes my UI state to the options window
the menu knows nothing about my actual options UI
it's a good system. i have the use case where i build several shops that include upgrades and every shop is another panel. so i don't have that 1:1 relation but a 1:n
building a system for each would be a bit of an overkill
how to kill productivity in 2 simple steps: install entities, install uitoolkit ๐คฃ
oh i'm definitely going to have sub panels and stuff at some point
i just haven't really built anything for it yet
these states are only used for top level panels
so i'm sure i'll have more regular back buttons etc at some point
this whole UIToolkit thing has set my knowledge about making UIs pretty much to zero. but i think it's for the best and probably a lot better once i've figured it all out. right now it's a veeeery slow process ^^
entities 2.0 experience
gitlab uh, you're in Europe?
no
are we still waiting on worldspace for uitoolkit?
yes - definitely a big limit atm
gitlab provides a lot more free lfs space
i don't understand why anyone uses github for personal game projects
Since I was coaxed to using gitlab by a german I'm considering moving over, it's cleaner too
well i am neither
I think so, but iirc wasn't there an API to translate world space to screen space ๐ค
think I was thinking of this method (can't remember if they've changed it): https://docs.unity3d.com/Packages/com.unity.ui@1.0/api/UnityEngine.UIElements.RuntimePanelUtils.html
does UIToolkit even have some kind of update event? i have a simple (cost) label that turns red when player has not enough funds. i mean, it's better when i loop over every active cost, evaluate and set - still wondering if there's any form to quickly prototype.
tick every frame, something that related to a MB update
no wonder it performs better. it disallows shitty code ๐
i already stumbled over this but i forgot where. i know it's possible to query all those active cost elements
do you just mean .Q<T>() ?
yep and then followed by foreach
these selectors are pretty cool
that only works with query _rootVE.Query("shopContainer").ForEach(shop => { });
untested but Q has no ForEach
oh yeah Q returns single element
yeah, right. man, i knew that at one point - i'm getting so much information overload haha - anyway, works great to select it like that. kind of cool to have batch processing
the selector isn't a full css selector, is it? wonder if shopContainer:visible works
have to find that out tomorrow. now it's time for bed ๐
Hey, just got started with DOTS.
public partial class RelativeMoveSystem : SystemBase
{
protected override void OnUpdate()
{
new RelativeMoveJob
{
DeltaTime = Time.DeltaTime
}.Run();
}
public partial struct RelativeMoveJob : IJobEntity
{
public float DeltaTime;
void Execute(ref Translation translation, in Rotation rotation, in VelocityComponent velocity)
{
translation.Value += math.mul(rotation.Value, velocity.dir) * DeltaTime;
}
}
}
If I want this to run on multi-threaded jobs, I just change Run() to ScheduleParallel() and that's it?
And I'm getting this warning message, not sure how to fix.
Yes. You schedule job
Is this everything I need to do to create an efficient system? What about disposing? When do I do that?
Disposing of what?
You can optimize it further by using ISystem instead of systembase
Since you don't use anything managed here
Nvm I just realized only NativeArrays need to be disposed off after its done
Ok I'll give it a go
Has anyone attempted to use the DOTS hybrid renderer on the quest 2?
missing BurstCompile attribute
is this crazy? can you have a base type for a component?
ie/
public abstract FooBaseComponent : IComponentData
{
public float Value;
}
public class BarComponent : FooBaseComponent
{
public float OtherValue;
}
no
well i guess if you used a class based component?
but 99% of the time you should be using struct components
and structs can't inherit
Love you tertle ๐ Great value for the community ๐
what makes more sense in an ECS system for types of projectiles (tower defence game):
Have different components for different types of way a tower can fire: ie/ TowerProjectileDefaultComponent, TowerProjectileInstantComponent, TowerProjectileBeamComponent
where Default is like shooting a single projectile to a certain location that has flight time, Instant has no project just hits the enemy as soon as it fires and beam is well... a beam and hits whatever comes into contact first
Or should i just have a common component called TowerProjectileComponent that has a field that contains the type and I have one system that does everything?
or do i go even deeper and have the projectile built out of components
so TowerProjectileComponent just really only has data to build the Projectile
I'd say make some component of Default tower shooter
Which will have most standard settings for basic towers.
System will use it for shooting
In case you need something special, you'll use different component and different system
meanwhile Projectile is a whole different story
so package the whole shooting into a component
hmm
the problem is
there is no default
default is do nothing (i guess)
thats defined by the user
projectiles each should have their own logic I think
I don't think having smth generic for projectile specific logic should be the case
again, aside from basic logic
for context - you build towers with components
like for example normal movement, from tower to target (like arrow)
each component changes what its suppose to do
so there isn't really a default behaviour
so you are given a base tower that literally just does nothing
and upgrades you drag onto the tower to give it abilities
like to shoot
(and how it shoots)
only came up with this idea cause testing out ECS
ECS is composition
not inheritance like OOP
so you should probably drop any good practices while thinking in ECS world
in ECS logic will be hardcoded 99% of times
then maybe I didn't quite understand you well
so consider an entity
that gets lets say afew components added to it
systems act on those components driving functionality right?
systems act based of queries of required component
they will go through all entities that match query
thats a low level overview
regardless of how many components you added
yes
so you agree right?
at a high level thats how it works
you could literally replace "driving functionality" with what you said
if you want
i just didn't think i needed to go that indepth for that
if you want "replacing" functionality of logic
Unity ECS has write groups
which can filter entities if they have components that belong to chosen write group
i'm not asking for help on how to write this on a low level
i'm trying to figure out what the best way to tackle this is
cause it depends on how i want to separate out the responsibilities depends on how i write my systems
which was basically the question
anyway dw about it i'll just think on it maybe i'm not wording the question right?
thought i was as clear as i could be in the initial question
Nah, it's just me not being smart ๐
If I wanted to make TD I'd first figure functionality categories
Tower shooting | Projectile movement | Unique projectile logic
so most towers will have most basic shooter, smth like CD based with different settings
For some unique towers, that need to shoot differently (for example based of player input) - their own component, which can also be shared among different types of towers
but you are under the assumption there are tower templates right?
for projectile movement I'd just implement logic for each kind of movement required. Linear, drop from sky, make some zig zags and etc
would you make each type of movement a component or a value in a component?
not really
I'm just imagining old TD game
fair enough
There is no one size fits all solution of course, you just need to think about all your requirements up front. Projectiles can move , maybe they can pierce, when they hit or end what do they do... Damage, debuffs, these things can be aoe...?
Imagine now how you want to configure a projectile with these things in mind, think of how that data will drive through into systems.
You may have a debuff system here, a damage application system, the concept of damage instances, how to determine damage instances (aoe? Immunity?)
There are many ways this problem could be broken down
yeah
Imo start with understanding your requirements, then draw up a mock config for yourself
The problems will start revealing themselves
basically yolo'd in and had to refactor so many times so its why i've stopped and considered this question
In my company I'm the diagram guy now cause thats how I figure out how to proceed with a new feature haha
hmm so my main problem with the solution right now is
if you allow a user to "build a tower" - so lets say they add a projectile to it
and they add another projectile to it so lets say it fires with two different projectiles now
you can't actually do that
due to unique constraints on projectiles
since you can't make them a component
so i'd have to make them an entity
but then if i make them an entity how does other things the user adds to the tower effect the projectile
You're revealing some requirements
lets say they add the on hit effect AoE as you mentioned
I rewrote one of my projects 5 times before I achieved my own zen in ECS ๐
A turret can shoot multiple projectiles
So turrets spawn projectiles. Seems perfectly fine.
Why can't they shoot 2?
is that game rule or some technical bug you are looking to fix?
cause you can't add two components of the same type to a entity
so lets say we have TowerProjectileArrowComponent or something
you can't add that again
I'm just saying, given you have your requirement, this is one possible solution
Some projectile config
yes, you can't add same type of component, but why do you even need it?
that would make more sense
Projectile settings
why wouldn't you if the user can author towers
Thst can define appearance, audio, speed, aoe, piercing, etc. Oorrrr do it differently
Maybe you just give it an entity prefab
If you want tower to shoot 2 different projectiles based of some upgrades to it, you should probably make component set that allows for that
like mentiond dynamic buffer + config
Sooo many possible ways
Don't imo
i'll be back probably
Start with thinking through other options lol
this makes sense however
Just jump on first suggestion
Ok up to you lol
i can't think of any edge cases right now
just do smth first kek
anyway thanks guys @rustic rain @minor sapphire
Maybe you have a 'firing' config
Thst references projectile prefabs
Defines what you shoot when
The projectile entity has lots of components on it to define its behaviour
Ok enjoy ๐
config will be created by an SO i guess
Go forth and compile
thats my train of thought so far
Hey everyone, where can I find the ECS pool table example scene on github? I heard that it somehow uses physics deterministically.
I would like to use deterministic physics but couldn't get it to work with my initial attempt.
The positions and rotations after the physics simulation are always slightly different between machines.
How I tried making physics deterministic:
protected override void OnUpdate()
{
...
fixedDeltaTime = (float)env.GetVirtualTickRate().TotalSeconds;
physicsSimulationWorld.SetTime(new TimeData(elapsedTime, fixedDeltaTime));
elapsedTime += fixedDeltaTime;
physicsSimulationWorld.EntityManager.MoveEntitiesFrom(
EntityManager,
entitiesToTransferQuery
);
physicsSimulationWorld.Update();
}
(physicsSimulationWorld is my only world where the physics systems are present)
IIRC they use another world that they tick multiple times in the future to predict positions and collisions
and com.unity.physics is supposed to be deterministic between nearly every platforms yeah
Thanks @karmic basin I'll have a look.
As far as I remember MoveEntitiesFrom jumbles up the entity IDs non-deterministically,
so my suspicion is that this causes the physics systems to behave non-deterministically aswell.
any DOTS updates I should know about?
1.0 has entered experimental within Unity. Not yet public yet. Probably gonna release within 2 or 3 months
Yeah, it's odd seeing trainers using 1.0 but no way to actually use them. My guess is sometime next month 1.0 will release.
well its company training, not end user training unfortunately
Hmm... I guess it's still good news that they're making actual training projects with 1.0
i think unite will be the big reveal of 1.0exp. maybe even 1.0 and exp earlier
What makes you say that?
Hi everyone, I don't think I can use Unity physics for my project.
I would like to simulate physics for up to 1000 objects every 33ms.
I need a deterministic simulation. I think this should be possible with PhysX or Bullet.
(I know ECS physics can do this aswell, but not in my case)
Do you have any recommendations for a physics library which would be a good match for Unity ECS?
2D physics would also be fine
just speculation. unite seems like a good way to get many (new) eyes on it.
There are only 2 physics engines on Unity ECS: Unity's and Havok
In what way is Unity physics not deterministic enough?
It probably wouldn't be deterministic enough for something like lockstep networking, maybe that's what he's trying to do
@muted star There's also a framework by DreamingImLatios if you're unaware might be worth a look
afaik dreamings is deterministic. at least as far as possible, true determinism over several cpu architectures doesn't exist yet in unity
it would require a custom datatype. (has a name, but i forgot) photon engine uses that
Ooh I thought I remembered even Unity were pretty close to a 99%+
but maybe I remember wrong
Well, there's physics determinism, netcode determinism, and cross-platform determinism which are all kettles of fish
Unity physics AFAIK is deterministic
- on same hardware
yeah that's why I called out cross-platform determinism
has anyone tested out the performance of uitoolkit queries?
i'm not sure if it's wise to build systems that rely on querying each frame
hm, i really have some conceptual problem with how updating should work best with uitoolkit. if you imagine a spellbook that has like a 100 spells, not all visible and they can turn active/inactive based on if the player has the resources. previously such a spellbook button would have a simple cost and Update method that turns the button either white/red. now with uitoolkit, hm, i don't really know. should i build data in parallel to the visualElement. one system that queries visible spellbookButtons and then updates from that (would require some kind of hashmap to get the associated data) - bunch of ideas for it but nothing really great
How do I transfer data between GameObject <-> Entities?
the simplest answer is, don't. at least make it one way only. that aside, the entry point is relevant. from a gameobject you can just query entityManager and the components. from an entity, it only really works in non-burst code and having a Transform on the entity. other MonoBehaviours are supported but not all so the question is bit broad to answer specifically
i'm not really sure why you need queries outside of your setup
to determine visible spellbook buttons. otherwise i don't even know what to update - can't update all
spell X unlocked, set X spell visible
what you need is to determine when a spell is activated/inactivated
i don't think you should be querying your UI to determine this
should be part of your model
also i assume you would be populating this spell book dynamically from your game data off a template
so you don't even need to query the elements, you would be creating them and already have the reference you can map somehow
hm, i'm very familiar with the MVC pattern. big difference there, i can have code in the view, which is nice and powerful. here it's just a bunch of xml tags. and what i want to avoid is creating more code - i don't feel like that's elegant at all
hmm i disagree
i think you should be writing code to build yourself custom elements to encapsulate their behaviour
i think you should have a SpellElement for example
and that spellElement is a monobehaviour or what do you mean with that?
spell element
is a VisualElement
this is the kind of thing unity does if you look through their code
they build elements from a collection of other elements and attach logic to them
etc
nvm yeah found it ๐
they were from the Version Control package
collaborate namespace threw me off
at least that solves the issue of where do i even store model data ๐
thanks man ๐ these are the kind of concepts that i wouldn't have found in the docs
Is there any public list of changes coming in ECS 1.0? I just ran into a really odd situation around the BlobBuilder, and was wondering if there's going to be an update to it or if this is just the way it has to be?
Well, it's not necessarily an issue? It's just that it's a disposable struct. So if you wrap it in a using statement, you can't pass it by ref into a helper function.
So in order to get it to work, I had to unroll the using statement manually into a try/finally. Which is just really odd, to me.
ah yeah, classic c# limitation
Yeah. There's a lot of words online about how disposable structs aren't really a good idea. But I'd guess that this is probably a struct because it needs to be in Burst or something?
What really caught me off-guard is that I was just using Resharper's automatic extract method functionality in my code while refactoring... and it broke it because it didn't pass it by ref into a helper function.
Which it obviously couldn't do because... disposable struct with a using statement... Just odd. Was wondering if there's anything for it in the next version. If there's no clear documentation yet I'm perfectly happy to wait!
sooo, the dragon crashers uitoolkit sample uses monobehaviours as controllers (mostly individual) and for something like a progressbar (ability cooldown in their case) a simple Update routine. really not much difference here other than everythings decoupled from UIToolkit
the big question now, why the roundabout way and not just a link from a templateContainer/visualElement to a mono script
i still don't quite get it. the nice thing about UnityUI was that with a gameobject enable/disable the UI and scripts were disabled. now i have to manage them in some way and it's quite hard to build a generic system for it. if i have any cost label that should turn red when the player doesn't have enough gold/resource i need to handle every occurrence where a cost label could show up and toggle the script based on the visibility of the uitoolkit element. this form of decoupling is total nonsense - doesn't help in the slightest
(pardon my negativity as I'm figuring this out) ๐
this is true for high-throughput stuff, but if youโre not transferring very much data, itโs actually totally fine and indeed necessary to control things like cameras, audio, and anything else that may not have a dots-native interface. if nothing else, you can just have a static variable on a monobehaviour that you update from a systemโs onupdate or similar, as long as itโs not bursted. (If itโs bursted you can still do it but it gets complicated.)
sigh been putting this off for a couple of months as i knew it was going to depress me
but i finally tested entities 1.0 128 entity per chunk cap
and my effect system update time goes from 2.03ms +-0.1ms to 4.74ms +0.2ms
on 10mill idle effects
1.0 is here?
Ouch
Yea but that doesn't mean that we can't use different libraries when necessary
Moving entities between worlds seems to mess up the determinism of unity physics. Probably because the order of the entities keeps changing non-deterministically.
Theoretically it should be deterministic enough for lockstep networking as long as all machines are using the same CPU architecture. So Intel or AMD is okay but they all need to be either x64 or x32.
There is a library I was using up until recently called soft floats. It does what you're talking about.
I've already taken a look at his code and it his psyshok physics implementation seems geared towards his demo and not a universal physics solution ๐ค
hmm i think this should be deterministic (though i haven't tested enough to be certain)
moving entities between worlds though would definitely require the exact same tick on physics though
moving then would have to be done in fixed update
Do you mean fixed update from a monobehaviour?
This is how I'm doing it currently.
protected override void OnUpdate()
{
...
Debug.Log("Moving Entities from Simulation World to physics World");
fixedDeltaTime = (float)env.GetVirtualTickRate().TotalSeconds;
physicsSimulationWorld.SetTime(new TimeData(elapsedTime, fixedDeltaTime));
elapsedTime += fixedDeltaTime;
physicsSimulationWorld.EntityManager.MoveEntitiesFrom(EntityManager, entitiesToTransferQuery);
physicsSimulationWorld.Update();
}```
no fixed update system
what you're doing there doesn't look deterministic at all to me though
you aren't updating a fixed update potentially multiple times in a single frame
it's update could drift quite far away from what it needs to
hmm actually wait no
maybe that's fine
i can't tell if your fixedDeltaTime
is actually fixed?
you seem to set it every frame
implying it's not the same
but if you're using fixed step simulation group inside your world this doesn't matter
fixedDeltaTIme is always the same, I could have set it in OnCreate
so you're passing a fixed time to a world
in a regular update?
aren't you just either ticking your world faster or slower than it should be
or did you remove FixedStepSimulationSystemGroup
I removed all physics systems from all my worlds except for the physics world
yes but do those physics systems still update in FixedStepSimulationSystemGroup?
and if so why are you passing in a fixed step to the world from a non fixed update
I was under the impression they did when I called physicsSimulationWorld.Update() but I'm not 100% certain they do this every time.
Should I transfer the entities from a system in FixedStepSimulationSystemGroup?
FixedStepSimulationSystemGroup manages the fix step for you
converting non-fixed time to fixed time
hence i'm unsure why you're managing this yourself
and it's doing my head in if it'll actually be a problem
i think it definitely could be if you haven't set the timesteps up to match
but i'm pretty sure it is. if you're updating at 100 fps (10ms tick) and fixedDeltaTime is 50fps (20ms tick) then you're passing 20ms into the physics update and updating every frame when it should only be updating at 10ms and skipping every 2nd frames
yeah the more i write this out the more wrong it seems. you're basically updating your physics world in Update with the wrong delta time
you can quickly test if i'm right/wrong
change your (float)env.GetVirtualTickRate().TotalSeconds to be x10 larger
if the simulation is the same i'm wrong
if it speeds up 10x i'm right
save me thinking about it
I can try to explain how my code works overall perhaps it will be more clear then:
-
Simulation world systems run.
The last system in the simulation world transfers all simulation entities to the physics simulation world and manually updates it (once all long running jobs were completed). -
The last system to run in the physics simulation world immediately transfers all simulation entities to the presentation world.
-
The presentation world copies all the data from the simulation entities to presentation entities.
The last system in the presentation world immediately moves all simulation entities to the transfer world. -
The transfer world's only job is to wait for the next message from the host.
The host sends a message to all clients every 33ms in production. (This is the GetVirtualTickRate().TotalSeconds seen in the code above)
Once the wait is over, the transfer world moves all the entities to the simulation world and the process starts from step 1 again.
TLDR: It's fixed lockstep
hmm so it's lockstep
have you set your FixedStepSimulationSystemGroup to use the same FixedStep?
that said it shouldnt matter
it might just tick twice per frame
The physics simulation world is the only world with systems in the FixedStepSimulationSystemGroup
I use SetTime on the physics simulation world before I update it. Could it still update twice in a single frame?
yes
FixedStepSimulationSystemGroup sets the fixed update to 1/60
so your physcis world is ticking at 16.67ms
if you're updating it at 33.33ms
it's going to tick twice per update you call
maybe once, maybe 3 times depending on float rounding
Could it be a solution to move all the physics systems outside of the FixedStepSimulationSystemGroup then?
(if thats even possible)
easier to just set FixedStepSimulationSystemGroup.RateManager = null
so it stops running it's own fixed update
and will use whatever you pass in
okay I'll try that ๐
is there a parallel way to do GetComponentDataFromEntity ? I need to access some nested entity components and errors get thrown when I don't use [ReadOnly] but I need write access
disabled parallel restriction, seems to work fine
thats the way
I guess CDFEs are atomic internally when it comes to R/W?
no
you are responsible for ensuring what you are doing is thread safe
when you turn off safety
you are saying that no other thread will be reading this element
when you mean element, you're referring to the CDFE or the specific component that is being written to?
the specific entity/component
so why does the CDFE need to be a container-type?
I did some digging in the source code, and I couldn't find anything
what do you mean by container type?
it's a native container
why else would it require NativeDisableParallelForRestriction for parallel r/w?
because that's what safety is for?
yeah that's the thing
if you aim to do parallel r/w on it, you can get into race condition
unless you know for sure you don't
if it's not a container type needed to be initialized from the system, why are we not able to initialize a CDFE from within a job?
because you need system version
when you write to component
you also write version
Well, instead of using a CDFE, why not just a utility struct that you need to initialize for each job?
? what utility struct?
Hypothetically
I don't get it
var ecs = m_Access->EntityComponentStore;
ecs->AssertEntityHasComponent(entity, m_TypeIndex);
CheckComponentIsZeroSized();
void* ptr = ecs->GetComponentDataWithTypeRO(entity, m_TypeIndex, ref m_Cache);
UnsafeUtility.CopyPtrToStructure(ptr, out T data);
return data;
that is what is being done to read a component from a CDFE
because you don't have any safety?
What Im saying is why does there need to be an individual CDFE for each type in your job when it could be just some utility struct that also has safety like a CDFE
because safety is per component
otherwise your utility struct would cause a dependency on every component and every job
yeah, if system doesn't know what component you'll use
your job will be isolated from any other
this safety shit is starting to really annoy me lmao
I think that's what dynamic type handle does
but you can disable it for your specific use case
if your solution is thread safe
yes it's thread safe, hence why I find it odd needing CDFE in the first place
absolutely nothing other-than a single thread is accessing the specific component, and no other system ever will write to it
but how else would you declare for other jobs that your job is using specific component
what if other job wants to write to that component
yes but entities doesn't know this
you could well be giving it non-nested components for all it knows
it does since I cached them in a DynamicBuffer ๐ค
what nested means?
Is that rhetorical?
no, I don't know definition ๐
child entity, exactly the same as GameObjects being children to a parent GameObject
ah, what makes them special then?
ok so to be more specific, I have a component called a VehicleBase and a buffer DynamicBuffer<WheelBase> that is of type WheelBase. There are x amount of wheels per VehicleBase and each WheelBase has a reference to an Entity (along with other data)
it works perfectly fine the setup I currently have
but
I always questioned the requirement of CDFEs (disregarding safety) for my specific use case
when I could in theory just read/write to a pointer of that specific component
which is all cdfe is wrapping for you?
that's what I mean, why is it even needed per-type when a simple utility struct can be used instead
because otherwise you don't write it to dependency
and provides caching for speedup
you can make your own clone
idc about safety because I am r/w to isolated components that are never accessed outside of a single thread
or use Enzi's unsafe implementation
that won't write to dependency
and can access any component
with internal access pretty much anything is possible
Pretty much all I want is a utility struct that allows me to r/w to any component in complete disregard for safety, while not having to specify for each type.
can do it yourself
I would, but idk how to actually access a component outside of a CDFE
just copy whatever [int] of cdfe does
it's pretty simple
considering internal implementation does it for you
I would but it uses an EntityComponentStore which is internal and I have no access to it. I really dont feel like reverse-engineering what the GetComponentDataWithTypeRW does
just get access
there's Assembly Reference asset
which gives you it
with internal access everything is so much brighter ๐
not sure what that even is or where to find it
one thing I wont be doing is modifying packages
but it's totally fine
you don't modify package
you reference it in your own
and extend it from different assembly
Unity works with it
oh alright, I'll look into that eventually
create folder somewhere, create assembly reference asset
choose whatever assembly you want to extend this way
And then create class with that attribute for assembly
in attribute you can simply define string namespace
of your choice
sad part, that only works on initial developper
modders can't access it
BUT
modders have publicizer
which is even better, cause it makes even private fields public
kek
I imagine 1.0 will add more unsafe stuff
I only hope 1.0 will swap most private fields to internal
doesn't make sense if they only made NAs have unsafe alternative
allthough doubt
they want to add more unsafe
I have a feeling that at some point
they will even have some sort of safe wrapper on pointers
kek
well, I notice a lot of their methods are public, but struct/class is internal
my guess is they just want people to work in a safe context only for now
so they dont get bombarded with issues/questions regarding unsafe context that unity devs dont want to answer right now
which makes perfect sense
But ppl demand more unsafe stuff ๐
so far the only issue with DOTS for me has been the physics engine lag that appears out of nowhere
and a few GUI glitches
yeah but they're nothing horrible
usually just a refresh or similar will work
On a more unrelated note: I'm finding Span<> to be a bit faster than a NA when allocated on the stack. Nothing massive, but a 0.1-0.3ms decrease is pretty good imo
well, it's a stack allocation so it's always going to be faster than an array (which NAs are similar in preformance to IIRC)
plus, no need to manage memory as it does it for you
best way I can put it is "unsafe safe code"
better than NAs initialized in a job imo
I just ask for some screenshot of codeblock as example
in Unity ECS context
if possible
Span<ContactData> contacts = stackalloc ContactData[buffer.Length];
for contact solving for my wheels
well you have limited stack
but yes it's just stackalloc with safety
and my ContactData is just a wrapper for some data:
public readonly struct ContactData {
public readonly WheelCollider wheelCollider;
public readonly RaycastHit hit;
public readonly bool collision;
public readonly float force;
public ContactData (WheelCollider wheelCollider, RaycastHit hit, bool collision, float force) {
this.wheelCollider = wheelCollider;
this.collision = collision;
this.force = force;
this.hit = hit;
}
}
Quick question:
When I want to represent a temporary state on an entity, for example a "poisoned" status effect. My first intuition would be to just add a component containing the relevant data to that entity as soon as the state is triggered. However I have read that adding and removing components during runtime is not the best practice performance-wise because of the chunk system. What would be the idiomatic approach for that problem? Should I just have all components that an entity might need in it's lifetime there from the start and activate/deactivate them by need?
It's totally fine if you do it not often (meaning, not every frame)
so feel free to add/remove comps
alternatively
you can come up with a system that does it without structural changes
but I bet, it won't be as extendable as components
if you want a flexible system first question to ask is why is poisoned a special component
what about burning
or radiation
or acid
etc
are you just going to make 1 component for every effect? at end of day why are they any different
do the same thing, maybe slightly different tick rates and damage types but that's just data
Okay thats reassuring. I watched the interview with the v-rising developers and they said they rarely add or remove components on entities because of performance.
But you are right, for my example it would make much more sense to have a status effect component that can represent different effects if they are not too different
(Personally my effect/condition system is completely static archetype. in fact my entire game is except for state components)
I assume you have dynamic buffer for DOTs?
(but this is not easy to do without a lot of experience)
i have effects, that's it
+1 strength is the same as 50 poison damage/second
Out of curiosity, how do you handle state transitions? Like actions that should only be performed when first entering/leaving a state?
I think I just found the reason for my physics not behaving the way I want.
I just added a system into the FixedStepSimulationSystemGroup of the physics simulation world for debugging purposes and it turns out Time.DeltaTime is always different.
For instance Time.DeltaTime was 0,0128766 even though I called physicsSimulationWorld.SetTime(0, 1000) before calling physicsSimulationWorld.Update()
yes because FixedStepSimulationSystemGroup has its own fixed update
this is what i'm saying
In my ECS bootstrapper I did as you suggested
physicsSimulationWorld.GetExistingSystem<FixedStepSimulationSystemGroup>().RateManager = null;
i only have Start/Stop state transitions for application level states
my individual actors don't really use any
i do have limited states
and you can see how i handle states here: https://gitlab.com/tertle/com.bovinelabs.core/-/tree/master/BovineLabs.Core/States
Oh thanks that is very helpful. Still trying to wrap my head around thinking in systems so every example is great!
this basically turns a bitfield into state components
without having to know the components
supports both only 1 state or multi states
yes because
I wonder if there's a way to quickly generate wrapper for bits
so you can have struct size of 4 bytes with 32 possible states
you mean like a bitmask of any size you want?
practically
private struct Bytes4 : IFixedSize { }```
define a struct of any size you want
or if you want some huge size, feel free
private struct Bytes1337 : IFixedSize { }```
nnnah, I just wonder about using bitmasks
for sake of keeping size low
for multiple boolean fields
https://gitlab.com/tertle/com.bovinelabs.core/-/blob/master/BovineLabs.Core/Collections/BitArray.cs
also have a bunch of masks 8 to 256
with a lot of functionality
for example my vanilla game input most probably won't use over 32 bits
so why bother creating huge struct
of 16 bools
ouch! that's wild
stop saying that. ๐ it only uses no safety in one obscure method where no system state is available. normal usage still sets reader/writer dependencies.
I just meant that in a way, that you came up with it long before anyone else I know
yeah but it still requires a [NativeDisableParallelForRestriction] which you were talking about
not if you don't implement safety
which is even easier
kek
What's the fastest way to create a List from an UnsafeList? Is there some way to just set the list's internal array?
yeah, there is a way to add through pointer
lemme check if I can find it
public static unsafe void AddRangeNative<T>(this List<T> list, void* arrayBuffer, int length)
where T : struct
{
if (length == 0)
{
return;
}
var index = list.Count;
var newLength = index + length;
// Resize our list if we require
if (list.Capacity < newLength)
{
list.Capacity = newLength;
}
var items = NoAllocHelpers.ExtractArrayFromListT(list);
var size = UnsafeUtility.SizeOf<T>();
// Get the pointer to the end of the list
var bufferStart = (IntPtr)UnsafeUtility.AddressOf(ref items[0]);
var buffer = (byte*)(bufferStart + (size * index));
UnsafeUtility.MemCpy(buffer, arrayBuffer, length * (long)size);
NoAllocHelpers.ResizeList(list, newLength);
}
/// <summary> Resize a list. </summary>
/// <typeparam name="T"><see cref="List{T}" />.</typeparam>
/// <param name="list">The <see cref="List{T}" /> to resize.</param>
/// <param name="size">The new length of the <see cref="List{T}" />.</param>
public static void ResizeList<T>(List<T> list, int size)
{
if (list == null)
{
throw new ArgumentNullException(nameof(list));
}
if (size < 0 || size > list.Capacity)
{
throw new ArgumentException("Invalid size to resize.", nameof(list));
}
if (size == list.Count)
{
return;
}
if (_resizeListDelegates == null)
{
var ass = Assembly.GetAssembly(typeof(Mesh)); // any class in UnityEngine
var type = ass.GetType("UnityEngine.NoAllocHelpers");
var methodInfo = type.GetMethod("Internal_ResizeList", BindingFlags.Static | BindingFlags.NonPublic);
if (methodInfo == null)
{
throw new Exception("Internal_ResizeList signature changed.");
}
_resizeListDelegates = (Action<object, int>)methodInfo.CreateDelegate(typeof(Action<object, int>));
}
_resizeListDelegates.Invoke(list, size);
}
_resizeListDelegates
that should be a field in your static class
Hey guys, I would like to set the update rate of the FixedStepSimulationSystemGroup to something really fast, like 1 ms for instance.
At the same time I would like the deltaTime used by the systems within that system group to be 33 ms.
This is so I can manually call .Update() on the world every ~33 ms without having to wait up to another 33ms for the system group to be updated with the 'correct' deltaTime.
Is this possible?
If not the only other option I see currently would be to make my own version of the systems within that update group to fit my needs and to put them in my own update group.
physicsSimulationWorld.GetExistingSystem<FixedStepSimulationSystemGroup>().RateManager = null didn't work btw.
It would of course be ideal if the rate manager could be ignored completely and all the systems within the group be updated manually (without having to wait for a rate manager at all)
it's extension from tertle
as this is very specific, take a look at the fixedsimulation group implementation and copy it
i think the code should answer your questions
okay, thank you!
and yeah i would suggest setting up your own group for this
what you can also do is call .Update on the group every frame. basically ticking it yourself. (ah you already do that)
I didn't know that was a thing. Currently I call Update() on the world
Hey everyone. Started messing with ECS this weekend. Certainly liking the idea of it. But I'm also running into complications and all the usual setup issues. I'm thinking for the project in question I probably dont need URP either.
I really just need a subscene type setup. Thats what I was setting up with ECS for - to be able to break up levels into sections and toggle them on and off as needed.
Given I'm uncertain about URP and aiming for a pretty graphically simple game, do you think better off making a simple custom system to just activate/deactivate sections of the level as needed instead?
yeah, it's pretty convenient. i was utilising this to implement a timelapse/fast forward for the game. just needed a custom group and called update on it once. the group itself called update on itself then a bunch of times which triggers the update of the systems. just need to handle scheduled jobs because those need to be completed before the next update call
To be specific, I only use dots for bullet movement and bullet collision detections in a bullet hell. But I am not sure how to inform GameObjectโs component to take damage if the bullet hits.
Both bullet and player have entity representation
on conversion you can use AddComponentObject and your transform. the transform will be then on the entity and can be used to GetComponent a monobehaviour. you either whitelist your manual MB components or make a hashmap/dictionary for faster lookup to not always have to call GetComponent
Okay that sounds good. Will give it a try :) Thanks!
So i think i'm failing to see the wood for the trees here.. I'm getting this error:
Appears to be coming from BuildPhysicsWorld, complaining that the Projectiles job is reading from collision world
This is the projectiles job:
Which runs inside fixed step, before build physics world
I have another system which also runs before build physics world ( right after this one ) which also passes in 'world' as read only, but it doesn't throw any complaints about that one
have you registered in onStart?
Yeah
sometimes a dependency problem doesn't occur because it's finished before. at one point i had several when i only tested with 1 entity and no errors with 100k
hm, looks fine to me on first glance
Only difference with the other system which runs after this is, it's a job schedule rather than an Entities.ForEach that i'm passing world into
But yeah no complaints on that other job
oh you sure its coming from world?
Seems to be stemming from build physics
hm yeah
this is projectile system here:
TriggerFX as i say also uses readonly world to do i think an overlap sphere and has no issues
i had a similar issue before which arose when i changed ordering of certain jobs that lean on build physics, where i had an error pop up that actually wasn't an error, it was actually masking a different error from another job that was running
so it was basically impossible to debug with a lot of f***ery
I think it might be related to using ECB during physics step
Does this only happen during double ticks?
and/or setting translations etc ( although the entities themselves are not physics )
i doubt it because it's really simple test case
Simply swapping the order or Projectiles system and TriggerFX exposes this error:
I wanted the projectile system inside step physics because although they are not physics ( i'm translating them manually ) i wanted smooth motion and accurate raycasts for hits
moving the system out to simulation system fixes the error, but i'm pretty sure last time i had this outside of fixed step it was missing collisions
although technically, i think if my fixed step is reigned in and running 1:1 with the frame that shouldn't really happen right
Why can I do .WithDisposeOnCompletion on a NativeReference but I can't put it in a job with [DeallocateOnJobCompletion]... 
only native array supports DeallocateOnJobCompletion
(honestly they should remove this attribute)
What's the correct way to dispose from a job then?
container.Dispose(Handle)
Does that not incur any scheduling cost?
the same cost .WithDisposeOnCompletion does
if you don't want allocation/dispose costs
just don't allocate/dispose it every frame
just store in the system as persistent
That's what I usually do (now), but this is pretty old code where I wasn't doing that yet
I'm trying to add some functionality, I'll refactor it eventually (i.e. never)
This is also kind of weird code tbh, I should probably change it, but I'm not sure if that would make it slower. I still have no idea how long scheduling takes.
Basically what the job does is calculate a bunch of stuff so that I can then set tiles on a tilemap at the end. It gets a bunch of world chunks as an input, but instead of scheduling it as an IJobParallelFor I schedule a bunch of IJobs
The reason I did it this way originally is that I don't need a lot of the chunks immediately, since the enqueued chunks take up more than the camera's viewport, and chunks currently calculating are only forced to completion if the chunk enters the camera's viewport
And you can't complete only some of an IJobParallelFor
Wouldn't that be slower?
Rather than temp allocator
why?
also it's not temp allocator if you're allocating it outside of the job - it's going to be TempJob
Huh
Anything to watch out for when using Nullable<T> in jobs?
Ain't that just wrapper for value and Boolean of whether it is null?
TempJob vs Persistent
Yes
Huh
What's the difference between tempjob and persistent then?
0.43ms for allocating the 1mill element tempjob every frame
vs 0.006ms on the system re-using persistent
I thought it was where the memory was taken from
allocation speed
I see
There's a really good and interesting article on it, although I'm not sure how much of it is still relevant: https://www.jacksondunstan.com/articles/5406
so, tertle. your 128 entities test is pretty concerning
you should bring that up in the forum
how did you do the test to get 128 entities cap? pad the data?
or manual job queuing with 128 length?
i still have hopes this is opt-in and not a general rule now
i've already brought it up privately
yeah just added a 53 byte component
i don't really want to put fuel on fire and create speculation on a forum post, I was hesitant to even bring it up before 1.0 released without testing
why not?
this component never queried
it wasn't an existing component, just a new one
ah ok, then it's fair
imo it represents the empty space in the chunk that will exist in 1.0
i couldn't say, but i don't expect anything to change
at least not near future
not expecting them scrap 2 years of work ^_^'
just because i'm not excited on enable components i think a lot of people/studio will use them a lot
well, if they hardcoded this i don't know what to say ...
archetypes and chunks should support both forms. uncapped and capped with enabled/disabled comps
i'll probably just do my best to find use for these 50 bytes
maybe add support for my effects to do multiple things using a buffer instead of 1:1
etc
will it perform better then? ๐
than it currently does? doubtful
than it will, probably
i could significantly reduce entity count if instead of a piece of gear creating 6 entities for 6 stats
just creating 1 entity that can set 6 stats
so i should be able to make up a be bit of the loss
good example why development shouldn't be internal for so long. but then again, we voiced our concerns when it was first talked about so. i dunno. bad move (in case there really is no uncapped chunks anymore)
maybe the results are better with the new job system. after all, this is where the most overhead comes from
i understand the reasoning cort posted on forums
it's more just sadness for potential
in reality i don't think it will change much
yeah and i see the point, it just can't be generalised so much to ignore every possibility
like sure, the big gameplay entities have a massive size but what about the others
specialized ones more importantly
so now we have hardcoded chunk size and hardcoded entities cap. ugh
this is clearly not built for the future lmao
while I would really like small chunks especially with unmanaged shared components coming in 1.0, i wouldn't that far to say it's not designed for the future
you see chunk size of 16k and 128 entities cap in 5-8 years? it's not even appropriate for todays hardware.
640k memory was also a really nice number ๐
128 is simd register
i can see it slowing down if you increase this value
and 16kb fits nicely in cache
now would it be nice to have dynamic sizes per cpu
sure
is it needed right now? i hardly think so
would also breaks determinism which is something unity seems keen on maintaining
anyway, as i said, they should have made effort to make these numbers tweakable very easily. especially chunk size was one of the first major questions i saw. and as our tests show, more fitting chunk sizes can mean drastic improvements. that goes for any archetype and entities should be able to make every archetype configurable how much data it allocates.
the 128 simd register is only relevant with the enabled/disabled feature, right? the 16k was stated that it's not about caches. sure it fits in nicely, cache sizes will be bigger at one point though
and to have optimised a feature so aggressively over a complete framework only to be optional is ... not good to put it mildly
eh i'll shut up now. maybe it's really optional and not even a problem. i'll wait and see what's what
i should say that in 1.0, systems are [alwaysupdatesystem] by default, and you have to sign up if you want to require matching queries for update. this is because everybody was always going insane because their systems weren't running and they forgot to say alwaysupdatesystem.
been thinking about this for a couple of days
this is such a scary change (for old code)
i think this kills any hope of updating our existing project to 1.0
though the chance was already little to none
doesn't it just require to flip? [alwaysupdate] -> remove - no attribute add [requirequery] or whatever it will be called
but yeah, it is quite the change. probably made because of beginners. i certainly will have to get used to it.
not exactly
if you have 2 queries
previously either one having entities would make system run
you can't just make requirefor for both queries otherwise it would only run now if queries had entities
not either
you have to do early outs on each query individually on what they use
