Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Aniamtion overwrite variables

Discussion in 'Animation' started by Grzp, Sep 2, 2022.

  1. Grzp

    Grzp

    Joined:
    Jan 25, 2018
    Posts:
    31
    Hi guys, I have a question about animations. I have Player and player has a Point light, a in this point light I change variables in animation (once, only in this start animation): upload_2022-9-2_11-3-35.png
    And after this animation I want to change variables from Point Light in script: upload_2022-9-2_11-4-39.png
    And the problem is the animations overwrite variables in light and size of inner and outer radius dosen't change. After the start animation I don't use varaibles from this light in any other animations. I tried wait for end "start aniamtion" like: upload_2022-9-2_11-36-27.png
    but it dosen't work.
    Is there any posibility to manage this variables in light and change them via script after this animation?

    I will be greteful for any replies.
     
    Last edited: Sep 2, 2022
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    There's probably a way, but you should just control the light entirely from script, it'll save you a lot of trouble. If you add a property to an animation even a single time, the animator will take control of that property permanently; this is necessary so that your properties can revert to default settings when a new animation is played (at least this is my understanding of it).

    If you need the animation to time changes to the light, you can use events: https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html
     
    Grzp likes this.
  3. Grzp

    Grzp

    Joined:
    Jan 25, 2018
    Posts:
    31
    I found the thread: Animator locking animated value even when current state has no curves/keys for that value | Page 3 - Unity Forum

    Also I made it as you said, I create a function which control variables from lights on start, because size of variables in light are connect with player position on Y axis. So I can crate a math propotion for it and I think it's better because I manage light only in script.

    But if somebody knows how fix bug with lock variables by animations and want to share with solution will be great :)
     
    Last edited: Sep 2, 2022
    Unrighteouss likes this.
  4. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    There might be a way around it, but it's not a bug.
     
    Grzp likes this.