Search Unity

How to create custom modules for Unity?

Discussion in 'Editor & General Support' started by alexzzzz, Apr 25, 2015.

  1. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    It looks like this relatively new Modules feature is a nice way to integrate general editor extensions into all the project at once. I think it is ideal for things like Create Script Dialog or Visual Studio Tools for Unity.

    There's a blog post with basic information about how to create a custom module - Unity 4.6 and Modules. I followed the instructions there to build a custom test module and... well, I didn't fail but I can't call it a success either.

    What I did

    1. I built a custom dll with a simple script inside:
    Code (csharp):
    1. namespace TestModule
    2. {
    3.     using UnityEngine;
    4.  
    5.     [AddComponentMenu("Test/TestBehavoiur")]
    6.     public class TestBehaviour : MonoBehaviour
    7.     {
    8.         public string message = "Hello, World!";
    9.  
    10.         private void OnEnable()
    11.         {
    12.             Debug.Log(message);
    13.         }
    14.     }
    15. }
    2. Then I made an ivy.xml:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <ivy-module version="2.0">
    3.     <info version="1.0.0" organisation="alexzzzz" module="TestModule" e:packageType="UnityExtension" e:unityVersion="5.0.1f1" xmlns:e="http://ant.apache.org/ivy/extra" />
    4.     <publications xmlns:e="http://ant.apache.org/ivy/extra">
    5.         <artifact name="TestModule" type="dll" ext="dll" />
    6.     </publications>
    7. </ivy-module>
    3. Then I copied both files to UnityExtensions folder as follows:

    \ProgramData\Unity\5.0\UnityExtensions\alexzzzz\TestModule\1.0.0\TestModule.dll
    \ProgramData\Unity\5.0\UnityExtensions\alexzzzz\TestModule\1.0.0\ivy.xml

    What I got

    1. Unity Editor sees the module:

    Captura.JPG

    2. The new project I created automatically references the TestModule library:

    Captura2.JPG

    3. I created a script in the new project to test whether I can call stuff from my TestModule:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Test : MonoBehaviour
    4. {
    5.     private void Start()
    6.     {
    7.         gameObject.AddComponent<TestModule.TestBehaviour>();
    8.     }
    9. }
    It works fine.

    What is wrong

    Unlike the UnityEngine.UI stuff, the new "Test/TestBehaviour" item doesn't show up in the components menu in edit-time. In run-time, however, it shows up and I can attach my TestBehaviour to the objects using the menu.

    Then I added a new line to the ivy.xml
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <ivy-module version="2.0">
    3.     <info version="1.0.0" organisation="alexzzzz" module="TestModule" e:packageType="UnityExtension" e:unityVersion="5.0.1f1" xmlns:e="http://ant.apache.org/ivy/extra" />
    4.     <publications xmlns:e="http://ant.apache.org/ivy/extra">
    5.         <artifact name="TestModule" type="dll" ext="dll" />
    6.         <artifact name="Editor/TestModule" type="dll" ext="dll" />
    7.     </publications>
    8. </ivy-module>
    and put a copy of TestModule.dll to Editor folder:

    \ProgramData\Unity\5.0\UnityExtensions\alexzzzz\TestModule\1.0.0\Editor\TestModule.dll
    \ProgramData\Unity\5.0\UnityExtensions\alexzzzz\TestModule\1.0.0\TestModule.dll
    \ProgramData\Unity\5.0\UnityExtensions\alexzzzz\TestModule\1.0.0\ivy.xml


    but unfortunately it didn't help. I still can't access the scripts from the module in edit-time.

    I used Process Monitor to see what files the editor reads/accesses while loading - despite the corresponding line in ivy.xml, it never even touches Editor/TestModule.dll.

    ---
    Any ideas?
     
    Last edited: Apr 25, 2015
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
  3. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I dropped the idea.

    I described in detail all my attempts to create a custom Unity module on this forum. If you don't understand what I'm saying there in Russian that's ok, because after more than a year I don't understand it either. However, it looks like I found the solution. What I did was I just added my assembly guids to ivy.xml.

    There are two reasons why I dropped the idea of custom modules:

    1. I was trying to convert Visual Studio Tools for Unity into a module, so that I wouldn't need to import it to every new Unity project I was creating. I almost succeeded but then realized that VSTU was checking the folder it's installed in, and if it's not a Unity project folder it was throwing NotSupportedException. So, it couldn't run as a module. I could hack VSTU dlls removing the folder check, but decided to leave it as it is.

    2. When you update Unity, it uninstalls the previous version deleting everything in its own folders. If you have a custom module there it also gets deleted.
     
    Flipbookee likes this.
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Way too much effort - @Lucas-Meijer is working on a streamlined system for doing this, I'll just wait.