Search Unity

Using the Sprite Resolver to swap sprites during runtime

Discussion in 'Animation' started by dschu, Jan 11, 2020.

  1. dschu

    dschu

    Joined:
    Dec 10, 2019
    Posts:
    5
    Hey there!
    I'm currently learning Unity and diving into the first 2D adventures. In my current 2d project, I want to have a simple character where its "Upper Body" can be swapped to create different looking npc's in one Prefab.

    For this purpose, I've installed the 2D Animation package and set up my character as described in the docs.



    The swapping works perfectly using the visual editor, but I want to change it using a C# script, but I can't find a way to access the "Sprite Resolver" component. VS cannot find any Component Type called "SpriteResolver" or similar. I couldn't find a package to import (use UnityEngine.XXX) either.

    Could someone please help me out here?
    Thank you!
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    In Visual Studio if you type SpriteResolver and press Ctrl + . (dot) it should pop up suggestions for the namespace that type might be in because it clearly is a C# script so it has to be somewhere.

    Otherwise you could try GetComponents<Component>() to get all components on the object then log the GetType().FullName of each of them.
     
  3. Freigeist1337

    Freigeist1337

    Joined:
    Jun 25, 2016
    Posts:
    10
    currently the namespace is:
    Code (CSharp):
    1. using UnityEngine.Experimental.U2D.Animation;
    as you can read in the unity documentation. So maybe sth like this may work (untested)

    Code (CSharp):
    1. public SpriteResolver mySpriteResolver;
    2.  
    3. mySpriteResolver.SetCategoryAndLabel(String, String);
    4. mySpriteResolver.ResolveSpriteToSpriteRenderer();