#Adding an ISystem explicitly

1 messages · Page 1 of 1 (latest)

ornate yew
#

I cannot find a world.AddSystem that accepts an ISystem implementation. What am I missing? CreateSystem doesn't seem to work either

#

I don't see how the fact that are struct may affect this logic

ornate yew
#

Adding an ISystem explicitly

kindred flax
#

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

ornate yew
#

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

kindred flax
#

you'd only be using a copy of it

#

isystems are strongly designed to not be accessed ever

ornate yew
#

Yep I see why. I wonder how this works out in real life

kindred flax
#

and instead using the entity it generates to pass data in/out

kindred flax
#

isystems are amazing

ornate yew
#

Did you make complete games with them already?

#

But yes on paper it is how it should be

kindred flax
#

95% of my systems are isystem

#

none of my systems ever interact

#

even when they were all systembase

#

i never had references to systems

ornate yew
#

Obviously

#

But if you need to make somehow your system interact with 3rd party libraries is going to be challenging but very possible

kindred flax
#

the whole ecs pattern is about systems reacting to data

ornate yew
#

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

kindred flax
#

yes

ornate yew
#

Starting from the ui?

kindred flax
#

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

ornate yew
#

So how do you make the ui interact with entities?

kindred flax
#

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

ornate yew
#

So you made an ecs based ui framework?

kindred flax
#

not really

#

each panel is owned by a system that's all

ornate yew
#

ISystem?

kindred flax
#

no

#

UI is managed

ornate yew
#

Ok makes more sense

kindred flax
#

UI is pretty much the only SystemBase in my project

#

and input reading

#

i don't inject anything into this system though

ornate yew
#

Ok that makes sense

kindred flax
#
        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

ornate yew
#

Yeah ok now I can see it
The ui problem can be solved in many ways

kindred flax
#

(I think UI toolkit fundamentally works better with entities than ugui)

ornate yew
#

The point is that atm not everything can be done with ISystem

ornate yew
#

the example has the benefit to go in parallel

kindred flax
#

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

ornate yew
#

yes both solve my problem tho

kindred flax
#

instead of EM.setcomponent

#

it depends how many you have anyway

ornate yew
#

that's true

kindred flax
#

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

ornate yew
#

didn't schedule parallel revert to schedule if the set is small?

kindred flax
#

no

ornate yew
#

I may add an if myself then

kindred flax
#

but there's not a huge difference in scheduling performance anyway

ornate yew
#

if they were running on the main thread ,you think EM would be faster?

kindred flax
#

than what?

ornate yew
#

than the dictionary lookup

kindred flax
#

component lookup is just doing the same thing under the hood as EM

#

it accesses the same component store

ornate yew
#

ah ok makes sense