Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Question Animate a C# script variable by animation?

Discussion in 'Timeline' started by SMal99, Jun 4, 2023.

  1. SMal99


    Mar 23, 2023
    Hello everyone

    I was wondering if it is possible to animate a custom C# field in an animation with the animation tool.

    I want to animate a radius around my player while it is doing an animation for a VFX. I want it to be precisely timed in my animation to avoid any synchronization issue.
    I thought that having a public float in my script to control the radius and then adding a property in my animation then changing it with some keyframes could work but apparently it doesn't work like that.
    When I modify the property in my animation file it works as intended but when I select my prefab with the animator and the c# script the value stays the same as it is in the inspector and doesn't change while doing the animation in game.
    When I try changing the values in my prefab keyframes they're automatically assigned to the value showed in the inspector for my script. I guess it's because the animation properties are used to be changed by script but is there a way to do the opposite?