Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How get newly added PSB layers' categories and labels to exiting sprite library?

Discussion in '2D' started by streeetwalker, Sep 26, 2022.

  1. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    OK, previous to the PSD importer v6.0.6 you used to categorize and label layers right in the Skinning Editor. So it was easy to add new layers and bone those up and then categorize and label them and voila they appeared in the Sprite Library.

    Now in new version, I can't seem to understand the work flow. When I apply the bones for the newly added layers in the Skinning Editor, the new layers do not appear to be categorized or even visible in the Sprite Library that is associated with the PSB, and its Sprite Library is not editable even if I could.

    What do I need to do? The previous version everything seemed to be pretty automatic. How do I get from the old method to this new process?
     
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    827
    Hello @streeetwalker,
    From PSD Importer's documentation:
    To see how to work with Sprite Libraries in Unity 2021.2 and onwards, please have a look at the Sprite Swap documentation.

    We noticed that some users would like to export the Sprite Library data contained within a .psd/.psb file, so in Unity 2022.1, we created a tool which can extract the data and place it in an external asset file. To see how this tool works, please take a look at 2D Animation Asset Upgrader section in the 2D Animation documentation.
     
    streeetwalker likes this.
  3. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    Thank you for your reply, Ted! To clarify the project we are working on is Unity 2021.3.10f1. The conversion tool is not available. (we need to stick with the 2021 LTS version of the editor - is 2022 going LTS soon? )

    Yes, I have been looking at that documentation and I can create a library and can add the sprites, categories and labels to a Sprite Library, But I don't understand the connection between the PSB (that I have added new layers to) and the Sprite Library that "used to be generated from the PSB". I put that in quotes because I am not sure what is going on.

    I mean there is a Sprite Library asset in the project, but it does not look like it is updated with the new layers I added.

    Here is another clue:, while the skinning editor and Import Inspector's "Layer Management" tab shows the new layers in the correct position in the hierarchy, the prefab created shows the new layers as their own objects (note in the below image the RonJons layers should not be child objects in the prefab hierarchy):

    upload_2022-9-26_9-28-9.png

    What is going on there?

    Looking at the documentation, again, when I edit a PSB and then re-import it, the correct Sprite Library asset is no longer generated? I have to manually create a Sprite Library?

    Thanks again for your guidance!
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    827
    In Unity 2021.2 and newer, we no longer add more data into Sprite Library Assets generated by .psb/.psd files. The Sprite Library Asset is read only, so the data can be used but not edited.

    It is good to stay with 2021.3 LTS, so to circumvent this issue, what you could do is
    - Create a new 2022.1 (or newer) project
    - Add the .psb/.psd files containing Sprite Library Assets (plus their respective .meta files) into the project
    - Use the conversion tool
    - Take the extracted Sprite Libraries and move them into your 2021.3 project

    I don't really understand what you mean here and how it relates to Sprite Libraries, could you expand on it?

    Correct.

    Let me know how it goes!
     
  5. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    [EDIT] Sorry, Ted! I fixed the problem - some how the "Use Layer Group" option in the importer had come unchecked. That is fixed now and the layers do not appear as separate objects in the hierarchy, so you can ignore this reply! (I'm leaving it here for people who are as dense as I am!)

    Sorry if I wasn't clear: I added several new layers to the PSB file and when Unity refreshed the edited PSB the new layers appear as child objects in the prefab that the importer creates. I don't know what happened, but we definitely don't want these layers as child objects:

    upload_2022-9-27_13-48-46.png

    this image highlights (I hope for you!) the mental disconnect I have with the new PSD Importer and 2D Animation update - something I didn't really understand before:

    You create a PSB file in Photoshop with all these layers grouped in layer folders. For example, within a layer folder named "arm_right" What determines whether or not those end up as child objects in the prefab that is created from the PSB?

    In the previoius system I thought it was the process of associating the layers with the rig's bones, and then the categories and labels applied, that told the system "these layers are not to be created as child objects in the prefab, but will end up as swapable sprites in the sprite library" Perhaps that is not the way it worked?

    How can I tell the importer to omit these new layers from the prefab hierarchy?
     
    Last edited: Sep 28, 2022
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    827
    I'm happy you managed to resolve the issue!
    Let me know if you experience any other funky things while upgrading to 2021.3.
     
  7. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    OK, @Ted_Wikman sorry I inadvertently posted this reply to another thread so I am re-posting here where it belongs. Also, I resolved the previous reply in this thread and edited it to show the solution for that question. But onward:

    I did the conversion and got the sprite libraries back into my 2021.3 project, but I am not quite sure what to do with them:

    1. I can't apply the library to the parts of the PSB's prefab ... so I have to manually add it to each body part category of the Prefab Variant of the PSB?

    2. Then also, to clarify: the new layers I added after the conversion to 2021.3 are not added to the sprite library any longer, so I have to manually add those in?

    Another issue:
    3. I see that after the 2D Animation and the PSD Importer upgrade in 2021.3.10f1, the PSB's prefab has been given a hierarchy that matches its layer folder names where as the previous version the hierarchy is flat, however the new layers that were added after the upgrade are now objects in the prefab:

    upload_2022-9-28_7-29-30.png

    I don't want those new layers to show as objects, and will not be sprite swapping on them.

    Is this going to happen every time I add new layers to the PSB? What can be done about that?

    (note that this problem seems related to my previous reply - when I checked the Use Layer Group option in the PSD Importer inspector, it seemed to remove the child objects. How now they are in the hierarchy, in a different position, which is only visible when you create an instance of the PSB's prefab)

    I think this issue hits on a work flow question that has been nagging me: If we want to add new swappable sprites to the Sprite Library dynamically, programmatically, how do we author those so that they will work with the rigging of the PSB Variant instance without adding layers to the original PSB? work on a copy, or what?

    (I don't know if I am thinking the wrong way about this, but we want to add swappable items to our avatars from Addressables content and if we are forced to update the original PSB, it seems to defeat the purpose... )
     
    Last edited: Sep 28, 2022
  8. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    827
    In Unity 2021.2 and newer, PSD Importer and Sprite Library does not have any connection anymore with each other. If you add a new layer to your .psb file and import it into Unity, the Sprite Library will not detect this new layer. You need to add this new layer as a Category/Label in the Sprite Library yourself.

    When you import a new .psb into Unity and you want to set it up for Sprite Swap, the most straight forward path is to drag the generated model prefab into the scene, remove any of the generated GameObjects you do not wish to have, add Sprite Library components and Sprite Resolvers to the GameObjects which requires them, and then create a prefab of the updated model prefab.

    In the inspector, we only show one hierarchy down, not the full hierarchy, in a model prefab. So if you have the following hierarchy:
    - root
    - child_0
    - child_1
    - child_2
    You would only see root & child_0 in the inspector. But the whole hierarchy once you drag it into the scene.
    Does that answer your question?

    I'm not sure I understand this question, but you can add/remove and update the content of a Sprite Library Asset using the methods provided in its public API. See the full API list here: UnityEngine.U2D.Animation.SpriteLibraryAsset

    In Unity 2021.2 and newer, there is also Skeleton sharing, so that you can share a skeleton from one .psb/.psd file to another file. We demo this feature in 2D Animations samples, so you can take a closer look.

    For your addressables swap, you can take a look at our DLC Swap sample, to give you some ideas on how to approach it.

    I hope I managed to clear some things up. Let me know if you have any further questions.
     
  9. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    Yes, you're answers are helping a lot!

    As to this last question about the work flow, to try to clarify what I am getting at:

    For example: we have a rigged avatar with swappable clothing items on it body parts. This avatar is instantiated in our app. We want to then add new clothing options without having to alter that avatar's PSB, thus requiring us to push out an app update. We don't want to do that every time we add clothing options.

    I think, from the documentation and discussions that we can provide those new clothing options via Addressables dynamic content in Sprite Library, but I am not sure how we would author that "external" Sprite Library so that the new sprites will work with the rigging of our app's avatar.

    Does that make sense?

    If so, can we author new swappable sprites in a copy of our avatar that is not instantiated in our main app, create the sprite library from that, and then provide that Sprite Library via Addressables to our main app - that is one way of accomplishing the goal of providing new swappable items without forcing an update of our app?
     
  10. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    827
    To test your flow out, you could split it up into two parts:
    1. How can you dynamically load a Sprite Library with non skinned (static) Sprites, and have these static sprites applied to a prefab instantiated in the main app.

    2. How can you change the sprite in a SpriteRenderer & Sprite Skin to a different Sprite from a different file, while having Sprite Skin still working and deforming as expected.

    The reason why its good to split this task up into two is because sprite swapping (Sprite Library & Sprite Resolver) is not connected to sprite deformation (Sprite Skin). So having them work one by one and then merge the systems, makes it easier to reason about the implementation.

    To get Sprite Libraries to work should be fairly straight forward, and you can get most of the setup from the DLC Swap sample.

    To get Sprite Skins to work with a new Sprite requires the new sprite's mesh to be skinned to an exact copy of the previous sprite's skeleton. Using the copy/paste tools in the skinning editor can help a lot with this task. See this post and thread for some more insight into how you can work with Sprite Skin bone structures. And as a teaser for newer Unity versions, we have also greatly simplified this flow in Unity 2022.2.
     
    EvOne likes this.