Luca3317 / TMPEffects

Easily animate Unity text and apply other effects with custom tags
https://luca3317.dev/tmpeffects
MIT License
200 stars 6 forks source link

Error in Unity Editor when accessing/using AnimationDatabases #10

Closed beuzel closed 1 week ago

beuzel commented 2 months ago

Describe the bug Error in Unity Editor when accessing/using AnimationDatabases

To Reproduce Steps to reproduce the behavior:

  1. Start Unity empty project
  2. Install TMP Pro with its resources
  3. Install TMPEffects with its resources
  4. Copy provided TestScene into the project
  5. Show the inspector panel and click on the game object TMPContainer
  6. Observe the error message in the debug console. Clicking on "use default database" shows the error more likely.
  7. (The same error message appears when clicking on any scriptable objects from TMPEffects in my mid-sized project. As a result, they are not displayed in the inspector.)

Expected behavior No errors

Screenshots

2024-07-02 12_54_02-New Issue · Luca3317_TMPEffects - Vivaldi 2024-07-02 13_00_51-New Issue · Luca3317_TMPEffects - Vivaldi

Desktop

Additional context The TMPWriter works as expected, I think. The preview and runtime works. The TMPAnimator does not work. Preview and runtime have no effect. The error log from the console:

TargetParameterCountException: Number of parameters specified does not match the expected number. System.Reflection.RuntimeMethodInfo.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) (at <467a840a914a47078e4ae9b0b1e8779e>:0) System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <467a840a914a47078e4ae9b0b1e8779e>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <467a840a914a47078e4ae9b0b1e8779e>:0) TMPEffects.SerializedCollections.Editor.SCEditorUtility.HasDrawerForType (System.Type type) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/Utility/SCEditorUtility.cs:101) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.CreateDisplaySettings (UnityEditor.SerializedProperty property, System.Type type) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:277) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.gInitializeSettings|49_0 (System.Boolean fieldFlag) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:170) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.InitializeSettingsIfNeeded () (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:179) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.UpdateAfterInput () (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:156) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.OnDrawHeader (UnityEngine.Rect rect) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:325) UnityEditorInternal.ReorderableList.DoListHeader (UnityEngine.Rect headerRect) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect, UnityEngine.Rect visibleRect) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.DoList (UnityEngine.Rect position) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:121) TMPEffects.SerializedCollections.Editor.SerializedDictionaryInstanceDrawer.OnGUI (UnityEngine.Rect position, UnityEngine.GUIContent label) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedDictionaryInstanceDrawer.cs:103) TMPEffects.SerializedCollections.Editor.SerializedObservableDictionaryDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Runtime/SerializedDictionary/Editor/Scripts/SerializedObservableDictionaryDrawer.cs:44) UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUILayoutOption[] options) (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) TMPEffects.Editor.TMPAnimatorEditor.DrawDatabase () (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Editor/TMPAnimatorEditor.cs:235) TMPEffects.Editor.TMPAnimatorEditor.DrawAnimationsFoldout () (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Editor/TMPAnimatorEditor.cs:177) TMPEffects.Editor.TMPAnimatorEditor.RepaintInspector () (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Editor/TMPAnimatorEditor.cs:445) TMPEffects.Editor.TMPAnimatorEditor.OnInspectorGUI () (at ./Library/PackageCache/com.luca3317.tmpeffects@0.1.2/Editor/TMPAnimatorEditor.cs:477) UnityEditor.UIElements.InspectorElement+<>c__DisplayClass72_0.b0 () (at <999670adb4c84ac4bad3ce4f6391c9c9>:0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Luca3317 commented 2 months ago

Hi, thanks for the bug report.

The TestScene in the Tests folder is not meant to be opened manually; it's just a scene that can be reused for TMPEffect's unit tests. For an example scene that gives you an overview of TMPEffects, you can import that through the package manager.

Im still interested in seeing what causes this error, but I didnt manage to reproduce it. If you could clear these things up for me:

beuzel commented 2 months ago

Thanks for the fast answer.

I used Scoped OpenUPM to install TMPEffects.

I double clicked on Packages/com.luca3317.tmpeffects/Resources/TMPEffects Required Resources.unitypackage to install the resources. This created the folder Assets/TMPEffects/Resources inside the project.

I send you the whole project. No panic, it is only 1.8 MB: Test_OpenUPM2.zip

Open the TestScene, click game object TMPContainer, in inspector in component TMP Animator open Animations and assign the asset DefaultAnimationDatabase on it. Click on the plus icon to add an animation. The error appears.

In my game project the same error appears more often, but I have plenty of other assets installed.

Luca3317 commented 2 months ago

Click on the plus icon to add an animation.

By that do you mean open up the DefaultAnimationDatabase asset and add an animation to the BasicAnimationDatabase entry?

If so, I did do that and did not get any error 🤔 Im running the project in 2022.3.7f1 for the record, so that could potentially be the issue.

beuzel commented 2 months ago

I meant in this component in the reorderable list "Scene Animations" there is in the bottom right a button labeled "+" to add elements. (I thought that this list is a way to apply animations, but after reading the full documentation I think it is a definition of animations to be used. Using tags in text is nice but impractical for me to communicate to translators and to maintain consistency for dozens of languages.)

A test with slightly older Unity 2022.2.21f1 with TMPEffects cloned from this git repo shows no errors. So the error was caused by updates from Unity.

Luca3317 commented 2 months ago

I thought that this list is a way to apply animations, but after reading the full documentation I think it is a definition of animations to be used.

Yeah, SceneAnimations are a special type of animation that derive from MonoBehavior, to allow you to more easily reference scene objects. The list on the TMPAnimator registers them as usable tags.

Using tags in text is nice but impractical for me to communicate to translators and to maintain consistency for dozens of languages.

I see, can you elaborate on what system you were hoping for?

Luca3317 commented 1 month ago

Im planning to implement a field "default animations" to TMPAnimator and its inspector, analogue to the current "default show / hide animations" fields. That'll allow you to set animations that will be applied to the entire text without the need of any tags in the text.

Does that solve the issue youre facing? If not let me know, otherwise Ill close this issue once I implemented the new field (so likely next weekend).

beuzel commented 1 month ago

Yes, that would be very helpful. Thanks!

Luca3317 commented 1 month ago

Hey just pushed this to main. You can now set default animations, show animations and hide animations from the inspector. I will probably add support for directly setting TMPAnimation ScriptableObjects alternatively to tag strings.

image image