dotween icon indicating copy to clipboard operation
dotween copied to clipboard

Does not works from UPM package

Open DmitriyYukhanov opened this issue 5 years ago • 16 comments

Heya Daniele! =B

Would be great to make it possible to use DOTween Pro from the UPM package ^^ For now it does not works - I see errors when adding DOTweenAnimation for example:

NullReferenceException: Object reference not set to an instance of an object DG.DOTweenEditor.EditorUtils.SetEditorTexture (UnityEngine.Texture2D texture, UnityEngine.FilterMode filterMode, System.Int32 maxTextureSize) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTweenEditor/EditorUtils.cs:75) DG.DOTweenEditor.UI.EditorGUIUtils.get_logo () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTweenEditor/UI/EditorGUIUtils.cs:41) DG.DOTweenEditor.UI.EditorGUIUtils.InspectorLogo () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTweenEditor/UI/EditorGUIUtils.cs:124) DG.DOTweenEditor.DOTweenAnimationInspector.OnInspectorGUI () (at Packages/com.modumlab.thirdparty.tools.dotween-pro/Demigiant/DOTweenPro/Editor/DOTweenAnimationInspector.cs:219) UnityEditor.InspectorWindow.DoOnInspectorGUI (System.Boolean rebuildOptimizedGUIBlock, UnityEditor.Editor editor, System.Boolean wasVisible, UnityEngine.Rect& contentRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1625) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

And I see empty settings window with this text (no scripts compilations is in process at that moment): image

DmitriyYukhanov avatar May 09 '20 01:05 DmitriyYukhanov

Dmitriy! :)

I know and I tried various times with different approaches, but the problem is that DOTween relies a lot on the ability to modify its files (that's how the modules work), so they can't stay inside the UPM storage, and it's complicated to implement a mixed system like that aaaand make it work also on older version of Unity :P

Demigiant avatar May 09 '20 08:05 Demigiant

(but in general it's complicated regardless of older versions of Unity :P)

Demigiant avatar May 09 '20 08:05 Demigiant

Ah, yeah, I totally understand this, thank you for trying anyways! Just hope some day you'll be able to solve this, I believe you'll win this battle! \o/

But until this will happen, it would be super great to just let it work from packages as is ^^

I mean something like this:

  • move settings out from the Assets folder to the Project\ProjectSettings using UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget() UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget()

  • make plugin's root path dynamic and try look for resources and such independently from current DOTween \ DOTweenPro path

  • disable ability to change modules when working from packages

So it could be imported and configured as usual in Unity's Assets folder but keep working in that state while it's wrapped in package as is and used in such state from the UPM ecosystem.

DmitriyYukhanov avatar May 09 '20 17:05 DmitriyYukhanov

Ohhhh I didn't know those UnityEditorInteral methods, I like that!!!!

I thought of disabling module changes when using UPM, but the problem is that some modules depend on if the relative asset is present (like TextMesh Pro) so they need to be activated/deactivated. Otherwise if I keep them always deactivated there will be no TextMesh Pro shortcuts, and if I keep them always activated it will not work on projects without TextMesh Pro :|

Buuuut! I could use SaveToSerializedFileAndForget for the modules too. I will test this :)

Demigiant avatar May 09 '20 17:05 Demigiant

Thank you!

Even without possibility to switch modules it would be already great - those who wish to switch could make two different packages =D

Since it's just a workaround - it's totally fine!

DmitriyYukhanov avatar May 09 '20 18:05 DmitriyYukhanov

but the problem is that some modules depend on if the relative asset is present (like TextMesh Pro) so they need to be activated/deactivated

How about the conditional compilation symbols? You could define something like DOTWEEN_TMPRO in the project rather than toggle this #if true // MODULE_MARKER in the source code

laicasaane avatar Jul 14 '20 05:07 laicasaane

but the problem is that some modules depend on if the relative asset is present (like TextMesh Pro) so they need to be activated/deactivated

How about the conditional compilation symbols? You could define something like DOTWEEN_TMPRO in the project rather than toggle this #if true // MODULE_MARKER in the source code

I have seen this in zenject, they have support for unirx which can be enabled if you have unirx installed and define a symbol as seen here, don't know if you would be able to edit asmdef from a upm package

BLaZeKiLL avatar Sep 28 '20 18:09 BLaZeKiLL

Ohhhh I didn't know those UnityEditorInteral methods, I like that!!!!

I thought of disabling module changes when using UPM, but the problem is that some modules depend on if the relative asset is present (like TextMesh Pro) so they need to be activated/deactivated. Otherwise if I keep them always deactivated there will be no TextMesh Pro shortcuts, and if I keep them always activated it will not work on projects without TextMesh Pro :|

Buuuut! I could use SaveToSerializedFileAndForget for the modules too. I will test this :)

Unity a year ago brought out this 2018.4+ compatible package (I don't know if it works in older versions) that I have personally used many times in our code base and it works very well.

https://docs.unity3d.com/Packages/[email protected]/manual/index.html

On the one hand it tries to homogenize the fact of where the configuration files are saved and avoid what has happened so far that everyone has done it as they wanted: ScriptableObjects, XML, JSON, Resources, StreamingAssets, at the root of the project, hardcoded relative paths...

On the other hand, it allows it to be more integrated in the project configuration windows as one more section and to be integrated in the search.

And finally and most importantly, for simple cases the windows are built "alone" through the data model. For complex cases it's also possible and it's not hard to implement (there are examples in the package).

bdovaz avatar Nov 07 '20 10:11 bdovaz

Unity a year ago brought out this 2018.4+ compatible package (I don't know if it works in older versions) that I have personally used many times in our code base and it works very well.

https://docs.unity3d.com/Packages/[email protected]/manual/index.html

Yeah this is nice generalized way to store settings in packages though it makes me upset they choose EditorPrefs over UserSettings folder (default one for 2020.1+) for the UserSettingsRepository (implemented own settings storage at UserSettings \ ProjectSettings in my plugins).

DmitriyYukhanov avatar Nov 09 '20 12:11 DmitriyYukhanov

Relates to: https://github.com/Demigiant/dotween/issues/251

erowe-imangi avatar Apr 07 '21 13:04 erowe-imangi

Hey, just hit this issue as well. I just wanted to point out that the UniTask DOTween extensions only work with the UPM fork. This is because it uses some system that changes precompiler flags based on presence of the DOTween dependency.

This issue could of course be raised with UniTask, but as far as I can tell their approach is pretty airtight, so it'd be best to fix this on your end.

Also, annoyingly, the fork is currently behind this repository by quite a few commits.

I think you can get rid of the conditional compilation of each of the sub-modules by putting them in different asmdefs and letting the user choose which they wish to add as dependencies of their main asmdef. Obviously this is going to be have back-compatibility issues, but perhaps you could either maintain two forks, or simply drop support with a major version update?

Anyway, just wanted to share some thoughts. Thanks for the package. :-)

rhys-vdw avatar Apr 20 '21 06:04 rhys-vdw

Unity also now supports conditionally defining Preprocessor Symbols based on currently installed packages like TextMeshPro: https://docs.unity3d.com/2020.1/Documentation/Manual/ScriptCompilationAssemblyDefinitionFiles.html?_ga=2.36724064.1999471002.1620662952-1271225660.1595348587

This might help with reducing the need to modify any script files.

hulcypdiscord avatar May 12 '21 15:05 hulcypdiscord

+1 For this. Working on converting an internal framework to UPM, and we did use DOTween in some places. Would love to keep using it but since I can't add it as a package dependency it's not viable to keep dragging asmdef files, Started rewriting chunks to remove it as a dependency. PS: I agree, not having modules is an acceptable compromise.

TecsiAron avatar Mar 28 '22 15:03 TecsiAron

Bump

jonathan-lumos avatar Oct 06 '22 16:10 jonathan-lumos

Anyone commenting here should probably take a look at the main thread in #251

rhys-vdw avatar Oct 07 '22 00:10 rhys-vdw

I'm trying to use DOTween inside one of our private UPM packages, and having similar sorts of issues as here. In our case, we already put the Modules folder in the right place, so that worked fine, it was just having trouble loading the right logos and things for the editor windows.

To fix it, I copied the files from Demigiant\DOTween\Editor\Imgs to Assets/s/com.mycompany.mypackage/Demigiant/DOTween/Editor/Imgs

Getting those paths required a little digging, but if you want to do it programmatically (say, in an editor window or menu or something), something like this worked for me:

var PackageImgsDir = $"{EditorUtils.dotweenDir}Editor/Imgs";
var TargetImgsDir = $"{EditorUtils.projectPath}/Assets/{EditorUtils.editorADBDir}Imgs"

Directory.CreateDirectory(TargetImgsDir);

Debug.Log($"Copying {PackageImgsDir} to {TargetImgsDir}");
foreach (var srcPath in Directory.GetFiles(PackageImgsDir, "*.*", SearchOption.AllDirectories))
{
    if (srcPath.EndsWith(".meta")) continue;
    
    var destinationPath = srcPath.Replace(PackageImgsDir, TargetImgsDir);
    Debug.Log($"Copying {srcPath} to {destinationPath}");
    File.Copy(srcPath, destinationPath, true);
    
    AssetDatabase.Refresh();
}

I don't know why there's an /s folder there there. This was done on Windows, use at your own risk, et. al.

xwipeoutx avatar Feb 14 '24 02:02 xwipeoutx