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.
  2. Dismiss Notice

Bug Why is autoRebind on SpriteSkin internal?

Discussion in '2D' started by tonytopper, May 25, 2023.

  1. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    198
    This seems like a bug to me. Should be public so folks can modify this value programmatically.

    upload_2023-5-25_11-26-43.png

    The whole SpriteSkin, SpriteLibrary, and PSDImporter framework needs some love.
     
  2. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    179
    Thanks for bringing that to attention. May I understand what is your workflow? Are you dynamically instantiating objects and adding Sprite Skin component to them?
     
  3. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    198
    I just have a use case where I have lots of pieces on each model that I need to have rebinding on. I don't want to manually check each piece to use rebinding each time we create a new model.

    I want to make an editor button (better yet if I could create an importer override) that just switches this on for all the right pieces on our models. I need a fast-import cycle to iterate model changes and scale the amount of clothing content.

    upload_2023-5-26_13-47-50.png

    I am trying to set up sprite swapping on some of these pieces to change a character's clothing.

    I need the alternative clothing to rebind when the sprite is swapped.

    P.S. As an aside, eventually I'll need a way to bake some of these pieces down into a single sprite, once the player customizes their character. Like combining head and ears into a single sprite for example.

    And then I'd like to use the auto weights generation on that sprite, but I imagine that's not currently available in runtime or even exposed as an API in the editor.
     
    EvOne and MarekUnity like this.
  4. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    179
    Thanks for the detailed description. I'm taking a note of that.

    In the meantime, I've written a small helper class that adds two public methods to the Sprite Skin:
    - SetAutoRebind
    - GetAutoRebind

    You can find it here.

    This shoud allow you to get and set the Auto Rebind property for your use case.

    Hope this helps for now!
     
    EvOne and tonytopper like this.
  5. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    198
    Thanks, this is nice to hear. And it's very nice to have these extension methods.
     
    MarekUnity and EvOne like this.
  6. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    198
    Unfortunately, the PSD asset importer overwrites this setting any time you update your PSB file. This is also a bug IMO.

    Any reason why this field is not public?
     
    EvOne likes this.
  7. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    198
    To expand on the original question some more, why is setting rootBone not public? If I can edit something in the editor, I should be able to edit it with a script. Why is setting the boneTransforms not public?

    Creating rigging automation is harder than it should be IMO.

    We shouldn't have to rely on reflection hacks to do these things.
     
    EvOne likes this.
  8. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    198
    I am running into an issue with the SetAutoRebind method.

    Here's the stack trace:

    UnassignedReferenceException: The variable m_SpriteRenderer of SpriteSkin has not been assigned.
    You probably need to assign the m_SpriteRenderer variable of the SpriteSkin script in the inspector.
    UnityEngine.U2D.Animation.SpriteSkin.get_sprite () (at ./Library/PackageCache/com.unity.2d.animation@9.0.3/Runtime/SpriteSkin.cs:109)
    UnityEngine.U2D.Animation.SpriteSkin.GetSpriteInstanceID () (at ./Library/PackageCache/com.unity.2d.animation@9.0.3/Runtime/SpriteSkin.cs:188)
    UnityEngine.U2D.Animation.SpriteSkin.CacheCurrentSprite (System.Boolean rebind) (at ./Library/PackageCache/com.unity.2d.animation@9.0.3/Runtime/SpriteSkin.cs:557)
    UnityEngine.U2D.Animation.SpriteSkin.set_autoRebind (System.Boolean value) (at ./Library/PackageCache/com.unity.2d.animation@9.0.3/Runtime/SpriteSkin.cs:120)
    System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <b89873cb176e44a995a4781c7487d410>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <b89873cb176e44a995a4781c7487d410>:0)
    System.Reflection.RuntimePropertyInfo.SetValue (System.Object obj, System.Object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) (at <b89873cb176e44a995a4781c7487d410>:0)
    System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) (at <b89873cb176e44a995a4781c7487d410>:0)
    System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value) (at <b89873cb176e44a995a4781c7487d410>:0)
    SpriteSkinHelpers.SetAutoRebind (UnityEngine.U2D.Animation.SpriteSkin spriteSkin, System.Boolean autoRebind) (at Assets/Scripts/MadJoy/Character/SpriteSkinHelpers.cs:48)
    It looks like the animation package is missing a null check somewhere.