Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    6
    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:
    149
    Possibly code stripping?
     
  3. beatt22

    beatt22

    Joined:
    May 31, 2016
    Posts:
    6
    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:
    1,231
    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:
    6
    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:
    1,231
    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.
  7. silenterus

    silenterus

    Joined:
    Nov 8, 2019
    Posts:
    10
    Same problem here. I will try to froward them and post if it works.
    Any other solution so far?
     
    Last edited: Jul 24, 2020
    pegorari and Sibz9000 like this.
  8. pegorari

    pegorari

    Joined:
    Nov 19, 2009
    Posts:
    60
    Having the same problem here, I hope the next update fix this!
     
  9. Sibz9000

    Sibz9000

    Joined:
    Feb 24, 2018
    Posts:
    149
    I'm watching this post too in case a solution presents. Definitely a feature I would like.
     
  10. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    696
    Hello all! Can one of you submit a bug report? We'd like to take a look at the issue and possibly solve it. Thanks in advance!
     
  11. Tomana5

    Tomana5

    Unity Technologies

    Joined:
    Jul 16, 2019
    Posts:
    4
  12. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    771
    The issue has been fixed in 2021.2.0a12