#so if system level data is stored on
1 messages · Page 1 of 1 (latest)
partial struct SomeSystem : ISystem {
... OnCreate(ref SystemState state) {
state.EntityManager.AddComponent(state.SystemHandle, new MyComponent{arr = new NativeArray(42, Allocator.Persistent)});
}
OnUpdate(ref SystemState state) {
var arr = SystemAPI.GetComponent<MyComponent>(state.SystemHandle).arr;
arr[23] = 101;
}
OnDestroy(ref SystemState state){
SystemAPI.GetComponent<MyComponent>().arr.Dispose();
}
}
yes, they are not managed anymore
i think i'll have to digest this, but yeah i think all these changes are for the better
We're guchi now
I've been curious about this. Conceptually I like the idea of storing all data on components including system data
Practically, what's the benefit and is there not (tiny) overhead in retrieving this from a component instead of just direct referencing it in the system?
yep, i don't get this either
Benefit - unmanaged
what do you mean?
Can be accessed from any execution lath
faster although it does seem a touch cumbersome
you can get unmanaged isystem data (stored locally in the struct) with a ref
Can be accessed in a very fast fashion through pointer reference to comp data
i am strongly against any cross system references
my favourite part of 1.0 is the removal of physics requiring a system reference
That's the thing, you don't
You access data
yes i get i can do that now
but that's not what i'm talking about
i'm talking about system state that is only relevant to the system itself
Oh, Thay
Wouldn't you just make the state component internal?
yeah if you just need data locally it's a very roundabout way. i don't see the benefit
Locally you literally have direct reference to it
Aka SystemState
There's actually a few things to unfold here!
@balmy anchor is likely the best person to ask here. But I'll try.
It comes down to cross system references. scalability and restoring state.
- It means you can later decide on where the data should actually live.
- You're not directly dependent on a Systems implementation so you can switch things as you go - Your system doesn't need it anymore but another one does? awesome, now just flip where you got the data, no need to do a massive rewrite.
- Calling public methods can cause baddddness to incur. For instance throwing inside will not properly restore state, as we can't do cleaning in the upper part of the call stack.
example here:
MySystem : ISystem {
public void SomeFuncionThatThrows(){
foreach (var q in SystemAPI.Query<SomeComponent>()){
throw new Exception();
}
}
}
causes all subsequent systems to throw an exception stating structural changes == badness cause you're inside an entity iteration (even tho you indeed aren't)
Isn't one the main benefits of using components the automatic dependency management?
- totally agree with
i'm more thinking about the state of simply caching a persistent allocated native container that a system job re-uses (but doesn't re-use data between frames, it's just junk)
it just doesn't seem beneficial to store it on a component
Yeah, for state that only a single system needs, storing it directly on the system seems like a simpler way to go. I assumed this new pattern was designed specifically for the system sharing use case
Yes. There is no problem with storing private system data in the system. The one somewhat possible benefit is an easier migration if converting a SystemBase to ISystem one day and the data is managed. In this case ISystem will not compile unless the managed data is in a managed component.