Search Unity

No support for subclassed Monobehaviours in dlls

Discussion in 'Scripting' started by BMayne, Dec 10, 2015.

  1. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    I doubt this bug will get fixed anytime soon but just in case someone is looking for it. You can't have one dll contain a class that inherits from Monobehaviour/ScriptableObject and inherit from it in a second dll. Once you try to create that component or ScriptableObject it's reference shows as missing and the data get cleared when you hit play. Here is a diagram show casing the bug.
     
    Last edited: Dec 11, 2015
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    This was most recently tested in 5.3.0f4
     
  3. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Are you sure there's no circular dependency?
    Did you check/setup compilation order? It may consider as missing because the dependency DLL must be compilled first.
     
  4. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Yeah I looked into that. The only reason I could create that object in the first place was because it was a CreateAsset Attribute item. The scripts don't even show up in the dll when they normally have that little drop down arrow.
     
  5. ung

    ung

    Joined:
    Feb 22, 2015
    Posts:
    151
    @BMayne Consider that in diagrams you would have arrows going from derived-class to base-class (based on UML that is widely known and accepted as a standard). I'm just saying that cause I had an hard time interpreting the diagram before actually reading your description. Or maybe I just did not understand your whole post, which is quite possible.

    https://en.wikipedia.org/wiki/Class_diagram#Generalization
     
  6. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    The diagram goes hand in hand with the description above. If you just skip to the end and look at the pictures you are going to miss information, that is why I included both. Yes the arrows are backwards according to UML as I was not trying to make a UML diagram. I was trying to show the flow of logic with the final result in Unity.
     
  7. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    475
    Are DLLs 1 and 2 in the same directory? I think that was the solution our company had to go with: all the dependencies in 1 folder (the unity scripts can be elsewhere, it's just the DLLs with the dependencies).
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    6,240
    OK, I'm not sure what's going on for you.

    But I can assure you it's not because you have a class that inherits from a class in 1 dll, that inherits from a class in another dll, that inherits from MonoBehaviour. Because I have a bunch of those. And it works fine.

    I'll even show you an example of it working:

    dll_works.png

    ExampleMovementMotor is part of this project, it inherits from MovementMotor in the com.spacepuppy.Movement.dll. And that inherits from SPComponent in the com.spacepuppy.dll.

    MovementController is in com.spacepuppy.Movement as well, and inherits from SPComponent.

    Both meet your specifications, and they both appear just fine.

    In my production projects I easily have 100 scripts that match this design of your and all work.
     
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    6,240
    So I'll share some things I know about unity and how it deals with dll's. When serializing a GameObject and what scripts are attached, it references the script by a guid that is associated with that script. The guid is stored in the 'meta' file that is along side all files in Assets (if you have meta files hidden, you won't see them, but meta data is still generated).

    The thing is that a dll can have multiple scripts inside of it, so Unity has to add some extra data in the serialized information to determine which class in the dll will be used. So the guid from the meta file for the dll is what dll to use, and it sets a fileID to the first 4 bytes of an MD4 hash of: "s\0\0\0" + Namespace + ClassName. In the case of scripts in your project itself, that fileID is always 11500000.

    This means that:

    1) If you delete the meta file associated with a dll, or otherwise change the guid, it will lose its link.

    2) If you change the name of a class within the dll, you will lose the link.

    3) If you change the namespace of a class within the dll, you will lose the link.

    4) If you move a class from one dll to another, you will lost the link.