PSD Importer 1.2.0 Not Creating Sprite Library/Resolvers

,

I’ve been trying out PSD Importer 1.2.0 with Unity 2019.2.6f1 Personal and have really been appreciating the easy splitting of the different layers into a single prefab.

One feature I was interested in as mentioned here: Sprite Swap Manual Setup | 2D Animation | 3.0.8 is the PSD Importer automatically creating a sprite library and adding a Sprite Resolver to each object for easy sprite swapping during the game. The use case we’re looking at is swapping clothing and visual items on a character.

While I’ve been able to get the Prefab with the split components when importing the PSB file, one thing I haven’t been able to get working was the automatic sprite library/resolver creation. Each object just has a normal sprite renderer and we’re having to go to each sprite to manually build the sprite library asset, and add sprite library components and add resolvers, etc to each object. Looking through PSD Importer | 2D PSD Importer | 1.2.0-preview.4 I didn’t see any config options that would control this.

How do I get the PSD importer to handle the auto-creation of sprite libraries and sprite resolvers for PSBs imported using PSD importer?

Hi @ChubbyPitbull ,

The Sprite Library Feature was only added in 2D Animation version: 2.2.0-preview.1 onward.

Would recommend you to try the latest Packages on 2019.3 to grab the latest changes.
2D Animation 3.0.5
2D PSD Importer 2.0.5

Previously I had been using 2.20-preview.2

I installed Unity 2019.3.0b7, and confirmed I now had 2D Animation 3.0.5, and 2D PDF Importer 2.0.5.

I freshly imported the PSB file, and the result was the same as previously; a prefab with the layers split into objects, each only with a Sprite Render component with the specific sprite. No Sprite Library Assets were created, nor was any Sprite Library Components or Sprite Resolver components.

I did see numerous warnings in the console on import:
“File’s Layer ID is not unique. Please report to developer. 0 PLAYER SELECT::SQUARE SELECT
UnityEditor.Experimental.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)”
“File’s Layer ID is not unique. Please report to developer. 0 Buttons::Remaining Boxing for Layout
UnityEditor.Experimental.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)”
“File’s Layer ID is not unique. Please report to developer. 0 Remaining Boxing for Layout::SINGLE INVENTORY BOX
UnityEditor.Experimental.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)”
etc

Could the lack of Sprite Libraries/Resolvers be a function of some aspect of the PSB file?

Sorry for the confusion but the functionality of the 2D PSD Importer has changed and the documentation is in the process of being updated to reflect this.

Starting from 2D PSD Importer version 1.2.0-preview.3, the Sprite Library asset is no longer being created automatically upon importing the PSB file. Instead, the Sprite Library asset will be added to your PSB once you use the Skinning Editor and assign a Category and Label to a sprite.

The Sprite Library asset that was automatically created in earlier versions of the 2D PSD Importer was empty and not immediately usable so you would still have to go into the Skinning Editor and assign Category/Index to your sprites.

2 Likes

Thanks for the info! After reading your post, I did some more Googling and found https://docs.unity3d.com/Packages/com.unity.2d.animation@2.2/manual/EditInter.html

The PSB importer I had imported originally only showed me the “Bone” category and not a “Sprite” category, so I re-imported the PSB, went straight to the Sprite Editor and then the Skinning Editor, and now my Sprites are listed once I opened the Visibility tab. I was able to assign Categories and Labels and confirm that the Sprite Library/Resolver Assets and Components were being created. Thank you so much!

1 Like

Thanks for that. Today, the doc doesn’t mention using the Skinning Editor to create the library, or maybe it’s hidden somewhere? Sigh…

@ which Unity version (and 2D Animation package version) are you using?
In Unity 2021.1 (2D Animation 6.0) we moved the Sprite Swap out of the Skinning editor, so that there wouldn’t be two flows for users to learn depending on if their source file is a .PSB or any other image file.

The flow to work with Sprite Swap in 2D Animation 6.0 is as follows:

  • Create a Sprite Library Asset by right clicking in your Project view, selecting Create > 2D > Sprite Library Asset
  • Select the newly created Sprite Library Asset and add Categories and Labels. Note that once you have created a Category, you can drag and drop Sprites into the Category’s label area. (Do note that this does not work with Textures, only Sprite assets).
  • Once you have created a Sprite Library Asset, either create a new GameObject with a SpriteRenderer, SpriteLibraryComponent and a SpriteResolver in the scene, or drag in a .psb prefab into the scene and add the SpriteLibraryComponent in your GameObject’s root and SpriteResolvers on each GameObject with a SpriteRenderer you would like to be able to Sprite Swap.
  • Drag in the Sprite Library Asset into the SpriteLibraryComponent, and you should now be able to select a Category and Label in the SpriteResolver components.
  • Animating the SpriteResolver works pretty similar to how it worked in Unity 2020.2/3, with one change. Instead of having two values (Category and Label) we now combine these two into one value (Sprite Key). This (hash) value is a combination of Category name + Label name. If you update either the Category or the Label in the Sprite Library Asset, you will need to update the animation as well.

You can read more about Sprite Swapping in our Sprite Swapping chapter in the 2D Animation package documentation. Also note that we ship samples with every version of 2D Animation. In these samples you can find a few Samples about Sprite Swap. We also have a chapter in our documentation on how we created these samples.

2 Likes

Hi @Ted_Wikman and thank you for the long answer! :slight_smile:

I’m currently using 2020.3.3f1 and the 2D Animation package is up to date, version 5.0.4.

It appears that using the Skinning Editor does the trick and does it very easily.

(Note: In case people would wonder where this Skinning Editor is, it’s in the Sprite Editor, at the bottom of the drop down list on the left.)

There is a Visibility panel on the right, there you can assign categories and labels to each sprite in a very easy way, just right-click on the sprite in the list and select “Convert Layer to Category”. There also, you can organise and name your bones. (This visibility panel no longer exists in Unity 2021, as @Ted_Wikman already mentioned.)

7045633--835441--Capture d’écran_2021-04-16_08-32-48.png

Do that for every sprite in the list, apply and then:

  • the Sprite Library component will be added to the character,

  • the Sprite Library asset will be created inside the character prefab,

  • all the Sprite Resolvers will be created.

7045633--835444--Capture d’écran_2021-04-16_08-40-00.png

7045633--835450--Capture d’écran_2021-04-16_08-47-24.png

I hope this will be helpful. :slight_smile:

1 Like

Amazing, thank you for your detailed answer!

1 Like

You’re welcome! :slight_smile:

I’m about to update the project to 2020.3.4f1. Things should go well but I’ll come back here if needed.

1 Like

I upgraded to 2020.3.4f1, no apparent problem. Except that I cannot find Collections in the Package Manager, even in the preview packages.

In the meantime, Collections being installed in another project of yours, I just copied:

"com.unity.collections": "0.15.0-preview.21",

into my project packages manifest and it was installed but why isn’t it available in the list?

Thanks. :slight_smile:

Thanks for letting us know, and I’m happy that the upgrade was fairly painless!
Let me have a look at why Collections is not displayed even after you enable Preview packages in the project settings.

1 Like

Useful tutorials:

:slight_smile:

1 Like

I tried to switch from 2020 to 2021 because the sprite swapping with the .psb was quite buggy when I reimported a newer version of the .psb file.

I understand, that there now is only one way to setup the sprite swap, but the automatically generated sprite library had one big advantage and I cant find a way to achieve something similar in 2D Animation 6.5

In the older version, when I configured the categories and Labels in the skinning editor, the generated prefab had only one gameobject for every category, which makes absolutely sense. Now in the newer version, i have a child for every sprite, which means I have several gameobjects that I don’t want to use and I cant remove them because it is an automatically generated prefab.

The only way I see, to achieve this is to have two psb files. One that has only one sprite per body part and one that has all the sprites, which i can make the sprite library from.

Am I missing something? How would you achieve this?

1 Like

[quote]
I tried to switch from 2020 to 2021 because the sprite swapping with the .psb was quite buggy when I reimported a newer version of the .psb file.
[/quote]
What kind of buggy behaviour did you experience?

You are right that in 2D Animation 6.x and newer, all visible parts in a .psb are added to the prefab. My advice is that you hide the non default parts and either create a new prefab based on these changes, or save the changes into the scene you are working in. Another way to organize your parts is your suggestion, of having different sets in different .psbs.
We explain a basic setup of an animated swap using a .psb in our samples.

It is good feedback though to understand how you would like to organize your art/assets, and it is something we will take into account when planning future improvements to the 2D feature set.

In version 5.x I discovered multiple problems, that appeared when I updated the .psb (by simply exchanging it in the folder outside of unity) for example when some objects of the .psb moved in the hierarchy or where taken out.
It resulted in some labels beeing somehow occupied because it seemed to still keep some reference to old objects and said there is another sprite with that label, but there wasnt. Also some layers/sprites did not appear in the skinning editor but then still appeared as a seperated gameobject in the generated prefab. The only way to fix these things was to delete the .meta file and make the whole skinning new.

Of course I could do that, but I like to have my prefabs cleaned up, and not full of inactive gameobjects that I never use.

I just found a solution that fixes my problems in version 5.x

Edit: I was wrong, some problems still remain. Here is what I thought would help maybe its helpful for someone else:

I can reset all categories by doing the following:

  • select all Groups and layers in the skinning editor
  • right click > Clear All Category

  • click on the category dropdown of a layer > Remove Empty Category

  • click apply (don't know it this is necessary)

  • create the categories new (in my case by selecting all groups and right clicking > Convert Group To Category)

  • click apply

So after doing this, here is what remains: when I move a layer above another, it is not possible to “Remove Empty Category”. this leads to having occupied labels and the generated gameobject does not have a sprite for this category.

But! I found a solution:

If I do “Clear All Category” and “Remove Empty Category” before updating the psb I have all Categories cleared and can then create new ones afterwards.

Thanks for sharing what goes wrong @Tehenauin

Which exact version of 2D Animation are you using in 2020.3? In 2D Animation 5.0.6, we released a fix for the issue you seem to experience

[quote]
[5.0.6] - 2021-06-08
Fixed

  • Fixed Unable to remove Empty Category in Sprite Editor after changing Sprite Layer name with external image editor (case 1328475) [/quote] Link to changelog

If you are not using this version, do try to upgrade to at least 5.0.6 to see if the issue persist. If you still see this issue, we would love to get a bug report submitted to get more insight into how we can reproduce the issue in-house.

Thank you, I indeed didn’t have the newest version after reverting tu 2020.3. I am at 5.0.4 right now. I will update now and will open a bug report in case that the error persists

1 Like