keenanwoodall / Deform

A fully-featured deformer system for Unity that lets you stack effects to animate models in real-time
MIT License
3.29k stars 225 forks source link

Error opening Creator Window #30

Closed tkyleharrison closed 4 years ago

tkyleharrison commented 4 years ago

We installed Deform as a package in both Unity 2019.2 and 2019.3. The Creator Window says "No deformers found." and throws an exception:

ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown. System.Reflection.Assembly.GetTypes () (at <437ba245d8404784b9fbab9b439ac908>:0) DeformEditor.CreatorWindow+d__18.MoveNext () (at Library/PackageCache/com.beans.deform@5c7ccda4236aec3ff1e7ada04879bca945eba466/Code/Editor/CreatorWindow.cs:317) System.Collections.Generic.EnumerableHelpers.ToArray[T] (System.Collections.Generic.IEnumerable1[T] source, System.Int32& length) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) System.Linq.Buffer1[TElement]..ctor (System.Collections.Generic.IEnumerable1[T] source) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) System.Linq.OrderedEnumerable1[TElement].ToArray () (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) System.Linq.Buffer1[TElement]..ctor (System.Collections.Generic.IEnumerable1[T] source) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) System.Linq.OrderedEnumerable1[TElement].ToList () (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable1[T] source) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) DeformEditor.CreatorWindow.UpdateDeformerAttributes () (at Library/PackageCache/com.beans.deform@5c7ccda4236aec3ff1e7ada04879bca945eba466/Code/Editor/CreatorWindow.cs:62) DeformEditor.CreatorWindow.OnEnable () (at Library/PackageCache/com.beans.deform@5c7ccda4236aec3ff1e7ada04879bca945eba466/Code/Editor/CreatorWindow.cs:69) UnityEditor.EditorWindow:GetWindow(String, Boolean) DeformEditor.CreatorWindow:ShowWindow() (at Library/PackageCache/com.beans.deform@5c7ccda4236aec3ff1e7ada04879bca945eba466/Code/Editor/CreatorWindow.cs:56)

keenanwoodall commented 4 years ago

Sorry to hear that! I'll do my best to get to the bottom of it. Can you walk me through the exact steps you took to install Deform?

tkyleharrison commented 4 years ago

All I did was add this line to manifest.json: "com.beans.deform": "https://github.com/keenanwoodall/Deform.git",

tkyleharrison commented 4 years ago

I'm able to add the various deform components to objects manually and it works. So far the UI is the only issue I'm seeing.

keenanwoodall commented 4 years ago

Thanks for the info. I'll see if I can reproduce the error when I get home from work. What were the exact version numbers of Unity that you used?

tkyleharrison commented 4 years ago

I'm using 2019.3.0f3. I also tried it on 2019.2.6f1 with the same error. Thanks for looking into it!

keenanwoodall commented 4 years ago

Hmmm I made new projects on both versions of Unity, installed Deform as a package via the manifest file and was able to open and use the Creator Window without any issues.

It appears the exception that's getting thrown on your end happens when classes in a module cannot be loaded. I'm not sure why this is happening for you though.

Here's the things I'd recommend trying (some of which you may have tried already):

If nothing changes after trying these things, try cloning the repo into your Packages folder (after removing it from the manifest), opening the CreatorWindow.cs file and pasting these two methods over the GetAllDeformerAttributes() method at the end of the file.

public static IEnumerable<DeformerAttribute> GetAllDeformerAttributes ()
{
    var assemblies = AppDomain.CurrentDomain.GetAssemblies ();
    foreach (var assembly in assemblies)
    {
        foreach (var type in GetLoadableTypes (assembly))
        {
            if (type.IsSubclassOf (typeof (Deformer)))
            {
                var attribute = type.GetCustomAttribute<DeformerAttribute> (false);
                if (attribute != null)
                    yield return attribute;
            }
        }
    }
}

public static IEnumerable<Type> GetLoadableTypes(Assembly assembly)
{
    try
    {
        return assembly.GetTypes();
    }
    catch (ReflectionTypeLoadException e)
    {
        return e.Types.Where(t => t != null);
    }
}

I have no idea if it will fix anything since I cannot reproduce the error, but it's the best I can do.

If the error still persists I'm not sure I can do anything further without you sending me a repro. Apologies for the trouble this is causing you, but hopefully we can find a fix!

tkyleharrison commented 4 years ago

We use unity assembly definitions to split our project into multiple assemblies. I suspect the issue is related to how we divide it up, but your change to CreatorWindow.cs fixed it!

Any chance this change will make it into the main branch? That would allow us to switch back to the package version :)

Thanks for your help!

keenanwoodall commented 4 years ago

I'm glad it worked! I'll try and make a new release today. Does it look like all the deformers are present in the Creator Window?

tkyleharrison commented 4 years ago

Yea, it's a long list with Normal, Noise, Mask and Utility sections. All the deformers I've tested are working.

The only minor issue I've noticed it Create Deformable comes in with a pink material since I'm using URP. Easy enough to swap out the material.

Thanks again for your help!

keenanwoodall commented 4 years ago

I created another issue to look into allowing the user to change the default material here #31. If it's cloned into your Packages folder you can change it (I think), but I'm not so sure if it'll work if Deform is installed via git url in the manifest.

keenanwoodall commented 4 years ago

Creator Window fix is in the newest release/on the master branch.