#Adding an ISystem explicitly
1 messages · Page 1 of 1 (latest)
Adding an ISystem explicitly
World.GetOrCreateSystemsAndLogException
is how DefaultWorldInitialization creates its systems
i'm pretty sure World.CreateSystem(type)
will let you create ISystems
public SystemHandle CreateSystem(Type type)
{
CheckGetOrCreateSystem();
if (typeof(ComponentSystemBase).IsAssignableFrom(type))
return CreateSystemInternal(type).SystemHandle;
return Unmanaged.GetOrCreateUnmanagedSystem(type);
}
they all check if type is managed otherwise create an unmanaged system
It doesn't return the struct itself
I guess it makes sense under dots point of view, a sort of protection mechanism
However this means no easy way to inject external dependencies
you can't (shouldn't) access isystem structs
you'd only be using a copy of it
isystems are strongly designed to not be accessed ever
Yep I see why. I wonder how this works out in real life
and instead using the entity it generates to pass data in/out
very well?
isystems are amazing
Did you make complete games with them already?
But yes on paper it is how it should be
95% of my systems are isystem
none of my systems ever interact
even when they were all systembase
i never had references to systems
Obviously
But if you need to make somehow your system interact with 3rd party libraries is going to be challenging but very possible
the whole ecs pattern is about systems reacting to data
Yes did your make full product with it? Many fundamental part of what is needed for a game is not converted to ecs yet
Often you need to mix and match
yes
Starting from the ui?
i work for a company with a published game
that was written in entities
my libraries are used in at least 3 other companies games
So how do you make the ui interact with entities?
my systems control the UI
(i should say work project is still and will forever be on 0.51)
(my personal UI library is for 1.0 though)
i have a whole UI management system
using UI toolkit
So you made an ecs based ui framework?
ISystem?
Ok makes more sense
UI is pretty much the only SystemBase in my project
and input reading
i don't inject anything into this system though
Ok that makes sense
protected override void OnStartRunning()
{
if (this.panelElement == null)
{
var assets = this.EntityManager.GetComponentObject<UIAssets>(SystemAPI.ManagedAPI.GetSingletonEntity<UIAssets>());
var asset = assets.Assets[this.stateKey];
Assert.IsNotNull(asset, $"No UI asset set for {this.StateName}");
this.panelElement = asset.CloneTree();
this.panelElement.name = this.StateInstanceComponent.ToString();
this.panelElement.pickingMode = PickingMode.Ignore;
this.panelElement.AddToClassList(RootClassName);
this.OnLoad(this.panelElement);
this.localization = new UILocalization(ref this.CheckedStateRef, new LocalizedStringTable(assets.StringLocalization), this.panelElement);
}
this.OnShow(this.panelElement);
this.AddToParent(this.documentSystem, this.panelElement, this.Priority);
}```
all my VisualTreeAsset are baked in subscenes
Yeah ok now I can see it
The ui problem can be solved in many ways
(I think UI toolkit fundamentally works better with entities than ugui)
The point is that atm not everything can be done with ISystem
@kindred flax last question for the day, time to go to sleep:
between burstified entitymanager setcomponent with iteration of native array like we discussed and component lookup like in this example:
which one do you think is faster?
the example has the benefit to go in parallel
kind of do different things
the boids one lets you do it off thread which is nice
if you can there's no real harm in doing it in a job
yes both solve my problem tho
that's true
if you only have a small set then you may as well just do it main thread
cost of scheduling etc going to be higher
didn't schedule parallel revert to schedule if the set is small?
no
I may add an if myself then
but there's not a huge difference in scheduling performance anyway
if they were running on the main thread ,you think EM would be faster?
than what?
than the dictionary lookup
component lookup is just doing the same thing under the hood as EM
it accesses the same component store
ah ok makes sense