Search Unity

[Request] Expose all System classes

Discussion in 'Entity Component System' started by No3371, Sep 17, 2020.

  1. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    At the moment it seems some systems are private, for example
    AddWorldAndChunkRenderBounds of HybridRenderer V2, this stop us from using custom World (call GetOrCreateSystem) and is not compatible with any framework/plugin that requires non-default World e.g. SpatialOS.

    Is there a particular reason not to allow developers to reference the systems?

    Btw I believe that as there are more and more systems coming with all the packages, it maybe a good idea that every package provide a util function to provide system list or maybe even add all systems it has to a supplied World, what do you think?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    What problem are you trying to solve?
    Is the problem that you want to enable / disable some system depending on what you are trying to achieve?

    It is not desirable for us to expose system since that locks down implementation details and prevents us from splitting systems into multiple at a later point to optimise our code.
     
  3. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    By exposing I simply means make it not private, so I can
    World.GetOrCreate<AmbientProbeUpdateSystem>()
    , not exposing the implementation, or maybe a function to add these private systems to any specific world would do :)

    I mean, there are some systems I can reference but some others I can't upload_2020-9-17_15-35-34.png
     
    Last edited: Sep 17, 2020
  4. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    We are using SpatialOS and it creates World only after it's connected, we have to create systems needed after the world is created.

    But it's not about SpatialOS though, this is a issue of the the custom world feature conflicting with any packages with private systems from my pov.
     
    Last edited: Sep 17, 2020
  5. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    Use Reflection or copy package to Assets folder and change source code, If you have special needs.
     
  6. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    Sure reflection or source modification would do it.
    But is non-default World really a special need? What about ICustomBootstrap? Even if I'm not using SpatialOS, I'll disable the automatic bootstrap to prevent a lot of systems getting created but not utilized.
     
  7. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    If it's a fully custom world.
    Code (CSharp):
    1.  
    2. public class CustomWorld
    3. {
    4.     public void CreateCustomWorld()
    5.     {
    6.         var world = new World("CustomWorld");
    7.         World.DefaultGameObjectInjectionWorld = world;
    8.         var system =world.GetOrCreateSystem<SystemsThatYouNeed>();
    9.         //Go on and make your own world
    10.     }
    11. }
    That's a completely empty world do whatever you need
     
  8. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    Also, systems whose query is never matched are not added to default world's update list.
    and after query match, it is not updated if there's no more match on its query. Why do you even bother? By not adding components that the target system queries for. Default world's update list is almost clean.
     
  9. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    Right thanks for sharing... What I need is to GetOrCreateSystem a system that is private in HybridRenderer package, that's why it's a request to Unity...

    I'm not asking how :)
     
  10. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    For this use case, you can create a system by its System.Type. You can fetch its type by searching for it from the results of DefaultWorldInitialization.GetAllSystems().
    While I 100% understand this rationale, it does cause problems when considering other design choices you have made. Specifically, we cannot use attribute-based ordering relative to these hidden systems. We can get around this at runtime by not using attribute-based ordering, but that doesn't work for GameObjectConversion since we cannot manually create the GameObjectConversionWorld.
     
    No3371 likes this.
  11. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    I can live with needing to change my code when system get added/removed, but it is hard to live with the constant need to use reflection or modificating source to create custom worlds/bootstraps (as the later is much more error-prone, and at least on the former I get a compile-time error that something is wrong).
     
    No3371 likes this.
  12. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    The whole we can't think of a use case so we make it internal doesn't work well when it ignores obvious use cases. The problem is that happens a LOT. Conversion systems being internal, data structures with obvious use cases internal. Systems you might want to order against or remove/move.

    I think actual history shows internal causes more problems then it solves when applied liberally and/or inconsistently.

    Also, this internal thing is the only reason why we have 3 DOTS packages in dev mode. It's always something Unity misses it's been this way pretty much from day one.
     
    DreamingImLatios likes this.
  13. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Also just wanted to say at the same time it's not a huge issue it's more of a minor irritant. Dev mode and InternalsVisibleTo is easy and non intrusive.
     
  14. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    352
    We faced the same problem. We don't want to use default world cause it contains ALL systems from project. In case when we need one world with one system set and second world with second system set the current state of world initialization brings much headache. I tried to use DefaultWorldInitialization.GetAllSystems() and it returns all built-in systems but also with my own systems. And i see no other way to get only built-in systems than use reflection by some parameter (attributes, namespaces, assertion) to separate my custom systems and built-in systems. And like TS said there is some built-in systems that is internal and can't be added manually. Why we have no script define to prevent adding custom systems to default list or some additional flags in WorldSystemFilterFlags?

    What if i use some system not with entities but just do something in system every frame with [UpdateAlwaysSystem]. Don't do that? What else?
     
  15. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    System will no query will be considered Always update
     
  16. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    This could help Add OptionalSystemAttribute to your systems. you may need to customize it for your need.
     

    Attached Files:

  17. No3371

    No3371

    Joined:
    Dec 1, 2016
    Posts:
    42
    I hope we can focus on the core idea here: The custom world feature is there and it's conflicting with package systems being internal, my proposal is either expose all systems, or provides a function call to add all the systems in the package ;)

    I understand there's some good code works provided and reflections do work but it's not what we (me and guys above supporting the idea) needs -- we are providing feedback and requesting feature for a product we enjoy, not looking for external tools.