Forum rules - please read before posting.

sprite visibility within the player prefab

ac1.53,u5.3.6p1

good morning,

I have several sprites I would like to hide or show permanently on my player prefab.
Like a hat for example.
So the hat-sprite is nested somewhere in the sprite unity complex player.
adding the remember visibility script to the hat gives it a constant id.

In the scene I have a action that hides the hat and show the hat.
But this doesn't work.  When I remove the player prefab the action looses the reference.

Am I doing something wrong?
I thought I ask before I create animation clips just for showing and hiding sprites.

Comments

  • When you add a Constant ID number to a prefab, ensure you have Retain in prefab? checked so that the original prefab also has this ID.

    However if you're using Sprites Unity Complex, the neater way to accomplish this would be to animate the alpha value / sprite field of the child Sprite objects as part of the Animator component itself, so that you can control their visibility using Mecanim parameters.  If you place these animations on a new layer, you can control them separately to the rest of your player's animations.
  • retain prefab doesn't help in this case.

    as it is a player prefab I'm gonna delete it from the scene after working on it
    and the reference from the visibility action to the sprite within the player-prefab is lost.

    Your animation hint is my workaround.
    I just would have prefered to keep simple display and don't display things out of mecanim
    mecanim has to check the parameters all the time, and I'm just disabling and enabling that sprite once in one scene.
  • If a Constant ID number exists in a prefab, and you drag that object into an Action field, then the Action will record that ID number - this allows Actions to find objects that leave/enter the scene.

    An Action field will show the referenced object's ID number if it's successfully recorded it.  If an object with that number is present in the scene when the Action is run, the Action should then find it - even if the object itself wasn't present in the original scene file.
  • I know now what you mean. just tested it
    When I drag it from the hierarchy window the constant id doesn't show up in the object-visibility action
    when i drag it from the project window the constant id is recorded and shows up in the action.

    In my case it is not possible to drag the "hat"-sprite from the project window into the action because it is deeply nested within the player prefab.
    I can expand only one leaf of the hierarchy of the player prefab in the project window.

    so special case and I ve used the animator with 2 animations to show and hide the hat
  • An unfortunate issue with Unity.  You could try moving the sprite to the first level of the hierearchy, assigning the Action, and then moving it back to where it should.  The Action only cares about the number - not it's location.
  • thx I will try that next time
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.