Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Official 2D PSDImporter 5.0 released for Unity 2021.1

Discussion in '2D' started by rustum, May 10, 2021.

  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    2D PSDImporter 5.0 released for Unity 2021.1

    PSB to Unity.png

    What’s new?

    With the release of Unity 2021.1 2D PSDImporter 5.0 is now available. This release includes:
    About 2D PSD Importer
    The 2D PSD Importer is an Asset importer that imports Adobe Photoshop .psb files into Unity, and generates a Prefab of Sprites based on the imported source file. Read the complete documentation here. Read more in the 2D PSD Importer documentation.

    Getting Started
    In an existing project in Unity 2021.1:
    1. Open Package Manager by going to Window > Package Manager
    2. Select Unity Registry in the Packages drop-down menu.
    3. Choose 2D PSD Importer from the list and click on Install at the bottom right of the Package Manager window.
      2D PSD Importer Package.png
    Creating a new project in Unity 2021.1 by selecting the 2D Template in Unity Hub will also install 2D PSDImporter 5.0 by default.

    What can you do?
    Try it out and let us know what you think of the package. We want to know what works as expected, what doesn’t and what is missing.
     
  2. Deleted User

    Deleted User

    Guest

    I had 5.0.1 already installed in my project and I got an update to 5.0.3. Upgrading the package also upgrades 2D Animation to 6.0.3.

    On your image, the sprites are visible; in my project they are not, it's been like that since several versions now.

    Capture d’écran_2021-05-12_23-28-48.jpg
    I notice that the package and others require Mathematics 1.1.0 but I have 1.2.1 installed and I have no option to downgrade the package to 1.1.0.
     
    Last edited by a moderator: May 12, 2021
  3. Deleted User

    Deleted User

    Guest

    I'm using the PSD file Importer Override scripts mentioned here so that I can import my psd files directly. They work, mostly, provided you add
    Code (CSharp):
    1. using UnityEditor.AssetImporters;
    to the PSDImporterOverride.cs and you set the class to "public" instead of "internal". :)

    There is a small problem though; in
    Code (CSharp):
    1. [ScriptedImporter(1, "psd", AutoSelect = false)]
    AutoSelect is deprecated and supposed to be replaced by overrideFileExtensions. Unfortunately I don't know how to do that and I'm not good enough to guess by myself, since the documentation is useless in the matter.

    Help would be welcome! :)

    Capture d’écran_2021-05-13_20-43-33.jpg
     
    EvOne likes this.
  4. Deleted User

    Deleted User

    Guest

    Well, the documentation proved useful after all and I found a suitable replacement fot the deprecated code:
    Code (CSharp):
    1. [ScriptedImporter(1, new[] { "psb" }, new[] { "psd" })]
     
    Gaidzin, EvOne and Leo-Yaik like this.
  5. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    We will update the sample code as soon as we can!
     
    Deleted User likes this.
  6. Deleted User

    Deleted User

    Guest

    The code works but I sometimes get the following error message on entering play mode. This message doesn't prevent working on the project though. I guess something should be added to the override script to avoid this kind of confusion?
    Code (CSharp):
    1. Multiple scripted importers are targeting the extension 'psb' and have all been rejected: UnityEditor.U2D.PSD.PSDImporter (assembly: /media/anne/SSDSamsungT1/Faire/Unity Technologies/Projets/Personnels/Unnamed Game (2D tools - 2021.2)/Library/ScriptAssemblies/Unity.2D.Psdimporter.Editor.dll), UnityEditor.U2D.PSD.PSDImporterOverride (assembly: /media/anne/SSDSamsungT1/Faire/Unity Technologies/Projets/Personnels/Unnamed Game (2D tools - 2021.2)/Library/ScriptAssemblies/Assembly-CSharp.dll)
    2. #0 GetStacktrace(int)
    3. #1 DebugStringToFile(DebugStringToFileData const&)
    4. #2 DebugLogHandler_CUSTOM_Internal_Log(LogType, LogOption, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)
    5. #3  (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    6. #4  (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
    7. #5 mono_print_method_from_ip
    8. #6 mono_perfcounter_foreach
    9. #7 mono_runtime_invoke
    10. #8 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
    11. #9 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
    12. #10 ScriptedImporter::RegisterImporters()
    13. #11 MonoManager::EndReloadAssembly(DomainReloadingData&, dynamic_bitset)
    14. #12 MonoManager::ReloadAssembly()
    15. #13 ReloadAllUsedAssemblies()
    16. #14 EditorSceneManager::RestoreSceneBackups(std::vector<EditorSceneBackup, stl_allocator<EditorSceneBackup, (MemLabelIdentifier)123, 16> >&, EditorSceneManager::PlayModeChange)
    17. #15 PlayerLoopController::EnterPlayMode()
    18. #16 PlayerLoopController::SetIsPlaying(bool)
    19. #17 Application::TickTimer()
    20. #18 MainMessageIteration(void*)
    21. #19 g_main_context_dispatch
    22. #20 g_main_context_dispatch
    23. #21 g_main_loop_run
    24. #22 gtk_main
    25. #23 main
    26. #24 __libc_start_main
    27. #25 _start
     
  7. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    You can do it by removing the "psb" in the override
    i.e.
    ScriptedImporter(1, new[] { "" }, new[] { "psd" })
     
    Deleted User likes this.
  8. Deleted User

    Deleted User

    Guest

    Trying that...

    and it's working, the message has disappeared. Thanks! :)

    I don't know if this is your area of expertise but each time I load my project I get this warning:
    Code (CSharp):
    1. SceneView rotation is fixed to identity when in 2D mode. This will be an error in future versions of Unity.
    2. #0 GetStacktrace(int)
    3. #1 DebugStringToFile(DebugStringToFileData const&)
    4. #2 DebugLogHandler_CUSTOM_Internal_Log(LogType, LogOption, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)
    5. #3  (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    6. #4  (Mono JIT Code) [SceneViewStageHandling.cs:128] UnityEditor.SceneViewStageHandling:LoadCameraState (UnityEditor.SceneView,UnityEditor.SceneManagement.Stage)
    7. #5  (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    8. #6 mono_print_method_from_ip
    9. #7 mono_perfcounter_foreach
    10. #8 mono_runtime_invoke
    11. #9 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
    12. #10 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
    13. #11 ScriptingInvocation::InvokeChecked(ScriptingExceptionPtr*)
    14. #12 SerializableManagedRef::CallMethod(Object&, ScriptingMethodPtr)
    15. #13 MonoBehaviour::AwakeFromLoad(AwakeFromLoadMode)
    16. #14 AwakeFromLoadQueue::InvokePersistentManagerAwake(AwakeFromLoadQueue::Item*, unsigned int, AwakeFromLoadMode, bool)
    17. #15 AwakeFromLoadQueue::PersistentManagerAwakeFromLoad()
    18. #16 PersistentManager::IntegrateAllThreadedObjects()
    19. #17 PersistentManager::LoadFileCompletely(core::basic_string_ref<char>)
    20. #18 LoadSerializedFileAndForget(core::basic_string<char, core::StringStorageDefault<char> > const&, std::vector<Object*, std::allocator<Object*> >&)
    21. #19 InternalEditorUtilityBindings::LoadSerializedFileAndForget(core::basic_string<char, core::StringStorageDefault<char> > const&)
    22. #20 InternalEditorUtility_CUSTOM_LoadSerializedFileAndForget(ScriptingBackendNativeStringPtrOpaque*)
    23. #21  (Mono JIT Code) (wrapper managed-to-native) UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget (string)
    24. #22  (Mono JIT Code) [WindowLayout.cs:368] UnityEditor.WindowLayout:LoadProjectLayout (bool)
    Should I worry?
     
  9. Deleted User

    Deleted User

    Guest

    I did that and it works as I already said but now the menu line for the default importer doesn't appear in Assets, in 2021.2. The fix is easy:
    Code (CSharp):
    1.         [MenuItem("Assets/2D Importer/Default", false, 30)]
    instead of:
    Code (CSharp):
    1.         [MenuItem("Assets/2D Importer", false, 30)]
    does the trick.

    The script looks now like this:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor.AssetImporters;
    3.  
    4. namespace UnityEditor.U2D.PSD
    5. {
    6.     [ScriptedImporter(1, new[] { "" }, new[] { "psd" })]
    7.     public class PSDImporterOverride : PSDImporter
    8.     {
    9.         [MenuItem("Assets/2D Importer/Default", false, 30)]
    10.         [MenuItem("Assets/2D Importer/Change PSD File Importer", false, 30)]
    11.         static void ChangeImporter()
    12.         {
    13.             foreach (var obj in Selection.objects)
    14.             {
    15.                 var path = AssetDatabase.GetAssetPath(obj);
    16.                 var ext = System.IO.Path.GetExtension(path);
    17.                 if (ext == ".psd")
    18.                 {
    19.                     var importer = AssetImporter.GetAtPath(path);
    20.                     if (importer is PSDImporterOverride)
    21.                     {
    22.                         Debug.Log(string.Format("{0} is now imported with PSDImporterOverride", path));
    23.                         AssetDatabase.ClearImporterOverride(path);
    24.                     }
    25.                     else
    26.                     {
    27.                         Debug.Log(string.Format("{0} is now imported with PSDImporter", path));
    28.                         AssetDatabase.SetImporterOverride<PSDImporterOverride>(path);
    29.                     }
    30.                 }
    31.             }
    32.         }
    33.     }
    34. }
     
    Leo-Yaik likes this.
  10. berdanka

    berdanka

    Joined:
    Sep 29, 2015
    Posts:
    24
    Not sure if it belongs here or in 2d-animation discussion, but current workflow with normal maps has an issue.
    Sometimes, PSD importer has quantum-tier differences in arrangement of sprites in atlas for seemingly identical PSB files. Using such atlas with misplaced sprites as a normal map in secondary textures, naturally leads to wrong results after rendering is done.
    PSD importer is changing the arrangement of sprites in atlas quite often actually, despite me locking transparency of layers when I edit the source.
    This randomness is absolutely killing me. Can we have some control over how sprites are arranged in atlas? Currently, I'm dealing with it by directly exporting atlas texture and drawing a normal version over it. But as you would expect, this method is terrible since, again, PSD importer can change the arrangement of the base file at any moment because it reacted to space radiation, Moon phase, or something else.
     
    koyodi and EvOne like this.
  11. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    The arrangement shouldn't change unless there is a size change in any layer i.e. the visual of a layer has gone bigger or smaller. The size change sometimes can be undetecteable by the naked eye eg there might be residue of a pixel that has very low alpha value from previous paint and erase. We are considering adding a 'alpha tolerance' parameter during import so that it can be tweak to prevent this from happening.
     
    koyodi likes this.
  12. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    At the mean time, we are also relooking at a better workflow for having secondary texture
     
    koyodi and EvOne like this.
  13. berdanka

    berdanka

    Joined:
    Sep 29, 2015
    Posts:
    24
    It looks like combining a few layers during edit caused edited sprites to get a combined alpha channel (despite locked layers) which is triggered rearrangement. After I restricted my workflow to using clipping masks only, I've managed to prevent my atlases from rearranging sprites. Still... limiting artists in their workflow is not a good thing.
    I understand where the issue lies but I can't suggest any elegant solution. Maybe... sharing atlas coordinates for sprites? Since we need a normal map to be exactly the same as the main file, it's kind of logical for main file to share its arrangement if our layers named identically.
     
    koyodi likes this.
  14. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    Yes, we are thinking along that line as well for how it works under the hood. On top of that, we would also thinking of a UI/UX flow that makes sense and hassle free as much as possible.
     
    koyodi likes this.
  15. gtraillllllllllllllllllll

    gtraillllllllllllllllllll

    Joined:
    Jul 8, 2021
    Posts:
    1
  16. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Hey @berdanka, thank you for your helpful feedback! Yes, this is definitely something we would want to look into.
     
  17. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
  18. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,262
    6.0.1 with unity 2022.1.0a13. This is not working

    upload_2021-11-7_20-19-51.png

    Doing anything and the default importer is not changing. Reimport, copy new psd into project, delete meta file, any and everything cannot change default importer

    upload_2021-11-7_20-20-24.png
     
  19. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    928
    Thaina likes this.
  20. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    Are you expecting that it will be imported with the PSDImporterOverride by default?
     
  21. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,262
    I have try to tweak ScriptedImporter by many combination. Non of them work. I expect that there would be some option to imported with the PSDImporterOverride by default. Like there used to be `AutoSelect` in older version