Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Custom visual element in DLL

Discussion in 'UI Toolkit' started by beatt22, Mar 23, 2020.

  1. beatt22

    beatt22

    Joined:
    May 31, 2016
    Posts:
    3
    I am currently implementing the new UIElements system.

    When creating a custom element that uses the factory pattern. The source works just fine. However, when I create a DLL of the assembly I get the following error: "Element 'type' has no registered factory method". Any ideas why this is happening?

    Thanks in advance
     
  2. Sibz9000

    Sibz9000

    Joined:
    Feb 24, 2018
    Posts:
    120
    Possibly code stripping?
     
  3. beatt22

    beatt22

    Joined:
    May 31, 2016
    Posts:
    3
    Thanks for your reply!

    The DLL is not created by Unity. And the factory pattern is visible inside a decompiler.
    To my understanding, A DLL that is not built by Unity does not strip code (to my understanding).

    I have a custom c# solution that gets build separately for this setup.
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    611
    If your element is in or inherits from an element that is in the UnityEditor.UIElements namespace, this will not be included in any player build (but it will "seem" to work when in playmode inside the Editor). It might be why you see this error.
     
  5. beatt22

    beatt22

    Joined:
    May 31, 2016
    Posts:
    3
    Let me better explain my setup.

    I am creating a Unity editor plugin. For the deployment of the plugin, I want to create DLL's of my source code. I have not created a player build.

    When testing in my source code everything works just fine.
    After creating a DLL of my source code I get the above-mentioned error.
     
  6. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    611
    You're in uncharted waters, I'm afraid. We have not really tested this use case and, as an advanced use case, it's not high on our priorities at the moment as we try to ship the toolkit. Not saying it's not a valid use case, just can't say when we can officially support it right now.

    Some hints from the team point to a potential problem in how we look for assemblies when we try to find the correct element to instantiate when cloning a UXML asset. My suggestion would be to ship a shim text-based assembly on along-side of your dll-based assembly that contains the types you want to instantiate via UXML but just forwards them to the dll-types. Just something to try.

    If you do find the solution (or the problem), I'd be curious to know. If it's something simple we can fix on our end, we might be able to squeeze it in for the next release.
     
    beatt22 and Sibz9000 like this.
unityunity