Forum rules - please read before posting.

Change object's sprite with ActionList

Hi everyone,
I hope you are having a wonderful day!

I am trying to make a 2D minigame in which you have to dress your character. There are 3 layers of clothing (underwear, middle and top). Higher layer is unlocked when all items from previous one are present on the character.

I dragged all underwear layer clothing on the character, gave each Hotspot and Polygon Collider and then deleted sprite from Sprite Renderer.
Hotspot has Inventory Interaction - when you drag right item to it, it's sprite should appear on it and both Hotspot and polygon collider gets deleted, so only newly added sprite remains.

I read you have to add sprite to object with ActionList's Object: Animate function, but I was unable to make it work. Can anybody, please, help me with it?

I was able to work around it by dragging all underwear layer clothing on the character and giving each Hotspot, Polygon Collider and Sprite Fader. Then I created OnStart cutscene and inserted Object: Fade sprite functions to fade out each and every sprite immediately. After that, if you drag right inventory item to it, it's sprite appears with Object: Fade sprite - fade in.
I am not sure if this is the most elegant solution and I would really like to know if there are any better ones out there.

Thank you in advance for your help.

Comments

  • I'm not totally clear on how you're handling the interactivity aspect, but on the topic of how things appear: the way I would recommend things be handled would be to rely on animation.

    Rather than having each possible item of clothing be a separate sprite object, animation would allow you to "recycle" the same object for each clothing type - since you only need to show one of each type at a time.

    For example, a "Shirt" GameObject could be used to display the current shirt, by swapping out which shirt sprite is loaded into its Sprite Renderer component.

    With animation sub-layers, you should also be able to make use of just one Animator to handle everything.

    The bulk of this approach just uses Unity's own animation system - AC would only be used to control which animation is actually shown. I would recommend reading up on Unity's Animator docs if you need an introduction to the animation system, but essentially:

    • Keep your Animator at the top of the Hierarchy
    • For each clothing type, create a new GameObject child, and attach a Sprite Renderer with a default Sprite to test with
    • For each clothing type, and for each piece within that type, create a new Animation that simply animates which Sprite is loaded into its respective Sprite Renderer
    • Creating new Animations will have them be placed automatically in the Animator's base layer - delete them from here
    • For each clothing type, create a new Layer in your Animator, and place all of its associated animations in there. For example, all the animations that control the Shirt appearance would go in a Shirt layer
    • For each clothing type, create a new Integer parameter in your Animator, which will represent which animation is shown. Then, in that clothing type's Layer, create transitions based on that parameter's value. For example, if the Shirt Integer = 1, it causes the "Shirt_Blue" animation to play, = 2 causes "Shirt_Red" and so on.
    • You should then be able to test things out by manually changing the Integer parameter values in your Animator window at runtime
    • When things are working and you're then ready to hook up to AC, you can then use the Object: Animate Action to change the value of the appropriate parameter.
  • Thank you very much, Chris!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.