Search Unity

Define System order over several Assemblies

Discussion in 'Entity Component System' started by Superheftig, Feb 18, 2019.

  1. Superheftig

    Superheftig

    Joined:
    Mar 4, 2015
    Posts:
    14
    Is ther a proper way to define the execution order of ComponentSystems that are compiled in different dlls that do not reference each other. There exists the three Attributes UpdateInGroup, UpdateAfter and UpdateBefore that you can use to define the order, but as an argument you have to define the c# type of the other class. If this class is in another assembly that should not be referenced by the current one, it´s impossible to use those Attributes.

    A use case: You want to distribute your code in two different modules DLL_A and DLL_B based on two different responsibilites. Your DLL_MAIN (e.g. Assembly-CSharp) references DLL_A and DLL_B, but it´s now impossible to define the order of the systems of DLL_A and DLL_B

    I looked into ScriptBehaviourUpdateOrder which parses the attributes and registers the systems in the unity loop, but it seems that there is also not an easy way to hook into the code

    Any ideas?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    As far as I'm aware there is no easy way outside of the UpdateBefore/After attributes.
    The ordering system is getting reworked so maybe there will be a way to do this in the future, but I don't think it's really an issue.

    If they don't reference each other they shouldn't really care about the order of each other. If DLL_A needs to update in a specific order compared to DLL_B, it should reference DLL_B and set the order.
     
  3. Superheftig

    Superheftig

    Joined:
    Mar 4, 2015
    Posts:
    14
    That is absolutely not true! If you download for example two Assets from the AssetStore, those Assets will definitely will not know each other and it also will not be possible to annotate them. If you want to use know in your project, there is no way to define their execution order. (Right now there are not a lot of assets in the store regarding ecs, but this will be a topic in the future)

    On the other hand, if you want to develop your own modular project you also divide your code into several dlls, in my case i have one dll for a simulation and one dll for creating data. Those should not know each other, but all systems from the one dll should execute before the other one

    If you build the dependency system from scratch anyway, please keep that in mind!
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    You could declare your own player loop of groups in whatever arbitrary order you need in a single common library.

    Then you can just use [UpdateInGroup] on each DLL.

    Be interesting to see what the ordering changes brings.
     
  5. Superheftig

    Superheftig

    Joined:
    Mar 4, 2015
    Posts:
    14
    Thx for the idea! I will try that as a workaround, but i will not work for Assets from the AssetStore
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Side note while I think of it, I kind of like the idea of writing custom unity packages instead of DLLs these days. Easier to maintain.

    upload_2019-2-20_9-56-49.png

    You can even pull them direct from github from your manifest.

    Code (csharp):
    1. {
    2.   "dependencies": {
    3.     "com.bovinelabs.analyzers": "https://github.com/tertle/com.bovinelabs.analyzers.git",
    4.     "com.svermeulen.zenject": "https://github.com/tertle/com.svermeulen.zenject.git",
    5.     "com.unity.burst": "0.2.4-preview.45",
    6.     "com.unity.cinemachine": "2.3.3",
    7.     "com.unity.collections": "0.0.9-preview.12",
    8.     "com.unity.inputsystem": "0.2.0-preview",
     
    Last edited: Feb 19, 2019
    recursive likes this.