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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Question Getting the names of all States inside a Substatemachine

Discussion in 'Animation' started by PeterPudeltreter, May 15, 2021.

  1. PeterPudeltreter

    PeterPudeltreter

    Joined:
    Apr 1, 2021
    Posts:
    9
    What I want to do:

    Store all names (as strings in a list) of all States that are inside a specific Sub-Statemachine. I want to do this in the private void awake() function in a StateMachineBehaviour script that is attached to that specific Sub-Statemachine.

    How can I do this?

    Things I don't wan't to do:

    - Write a script that reads the state-names at editor-time
    - Manually maintaining a hand written list in a public attribute

    I was trying to find a solution for a quite a while and just can't come up with a solution. I don't want to give up since it's pretty important and all the consequences of the workarounds are pretty bad.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    It's not possible. State names don't exist in runtime builds. A script that reads them in the editor is the most reliable you could get if you continue using Animator Controllers.

    But if you use Animancer (link in my signature), you won't have to worry about problems like this because it lets your scripts directly play whatever animations they want instead of forcing you to use magic strings to identify states that are (hopefully) set up outside your code.
     
  3. PeterPudeltreter

    PeterPudeltreter

    Joined:
    Apr 1, 2021
    Posts:
    9
    Thanks for the reply. Wow, ok that's kind of a big hit...

    I checked out Animancer already a while ago and it already looked promising when I saw it then. After this I might finally switch over from the Animator for my next project. I really wasted a lot of time on this one.