Search Unity

How to get assemblies from a loaded package?

Discussion in 'Package Manager' started by Lobolopez, Jul 3, 2019.

  1. Lobolopez

    Lobolopez

    Joined:
    Feb 26, 2018
    Posts:
    15
    This might be a silly question, this is my case:
    I have a package that exposes an interface.
    I have a package with a class that implements that interface.
    (and I've sorted out dependencies manually so the class can see the base it implements)
    What I am trying to do is, on startup, get all known implementations of the interface, but only local ones (to the package) appear, none of the ones that come in packages.
    This is the code I am using:
    Code (CSharp):
    1.     public static IEnumerable<Type> GetAllSubclassOf(Type parent)
    2.     {
    3.         foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
    4.             foreach (var t in a.GetTypes())
    5.                 if (t.IsSubclassOf(parent))
    6.                     yield return t;
    7.     }
    edit:
    It seems that, if I make the code that checks for the assembly a package itself then it finds the implementing classes, but it if is local to the project itself (and the implementing classes are in packages) then it doesn't work
    Any ideas?
     
    Last edited: Jul 3, 2019
  2. Lobolopez

    Lobolopez

    Joined:
    Feb 26, 2018
    Posts:
    15
    I have found a sorts-of solution. Restart unity after every assembly change seems to make it work next time around. It does work with mixing in and out-of package code and so on, but (as of 2018.3) restart is needed every so often. Known issue?
     
  3. BorisMongeau

    BorisMongeau

    Unity Technologies

    Joined:
    Feb 24, 2017
    Posts:
    57
    Hi @Lobolopez,

    Have you tried to create an assembly definition file in your project that includes both packages assemblies?
     
  4. Lobolopez

    Lobolopez

    Joined:
    Feb 26, 2018
    Posts:
    15
    no, but this is for other users so I am trying to give them an interface that's as simple as possible. For this case (and until the behavior stabilizes) it seems simpler to ask the user to "restart" than to "create an assembly that includes both"
    thanks for the tip, though!