Forum rules - please read before posting.

How to controll another animatior in player's Pfrefab via Actionlist ?

edited September 2023 in Technical Q&A

Hi everyone!
This is my 2D game, So I'm planning to make an "aura" animation above my character, same ideas as the flash light, I just want to add another animation that is attached to my character. And it turned out that I can't figure out how to controll it via Actionlist, is it possible to do so?

Or any more ideas?

Comments

  • You can do this with the Object: Animate Action, setting its Animation engine field to Mecanim. This will allow you to control a specific Animator component.

    If you're controlling an Animator on a prefab, you'll also need to make sure that AC affects the instance of it in the scene at runtime.

    To do this, place the Player's prefab into the scene, and have the Action reference the correct Animator. Then go to the Animator's GameObject, check Retain in prefab? in the Constant ID component, and then apply those changes back to the original prefab. You can then remove the prefab from the scene again.

  • edited September 2023

    (I‘ve put a photo in my original post but seems it dissapeared. Can you see it? I guess it's my VPN issue.)
    So, I followed what you told me to, it didn't work well. Is there anything I missunderstood?

    I dragged my character's prefab into the scene, had my Animate Action (already set to Mecanim) referenced the correct Animator under the prefab, added a constant ID component to it and checked the Retain in prefab?. Then applied the changes to the original prefab and deleted the prefab from the scene.

    Actually, when I remove the prefab, the Animate Action shows the Animator is missing, and when I run it, of course it can't play. Quite reasonalble, haha XD.
    I'm using the player-switching function, and I can see my character's prefab appears in DontdestoryOnLoad while running, so is that mean the AC can affect the instance of it?

    Forgive me if I made stupid mistakes XD.

  • edited September 2023

    Okay, I made it by accident!

    I just opened the prefab in the project (not dragging it into the scene) and drag the GameObject to the Animate Action reference. And it worked.
    Even though the Animate action still shows "Missing Animator" when I exit the prefab and turns to be "None" while running.

    Anyway, thanks for your help, Chris!

  • Even though the Animate action still shows "Missing Animator" when I exit the prefab and turns to be "None" while running.

    This'll be fine. It's not possible to reference a prefab child object directly once you leave Prefab Mode, hence the need for the Constant ID system. When the Action runs, it'll look for the object in the scene with the same ID number, and reference that instead.

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.