#[SOLVED] Animated value always 0

1 messages · Page 1 of 1 (latest)

random monolith
#

Hi could i get some help, i've been stuck on this for a while but can't understand why it behaves like that

I have two animations:
Init resets a value called "offset" from a script to 0 ( 1 frame )
Anim animates a value called "speed" which is a simple addition to offset (offset + speed * Time.deltaTime)%1
States don't use write defaults and transitions are instant

The problem i get is that even though Init finished and Anim state is active, the value offset keeps getting back to 0. As if Init is still playing indefinitely, however it doesn't have a loop time

#

all help appreciated (clip count = 2 when running)

still iris
#

Write defaults writes the default for all animated values...

random monolith
#

Oh sorry i missed typed my thoughts , it is off

#

I am recording some videos. The animation works properly when it is directly the default state and that the other state is not present at all the in the animator

still iris
#

Ok, let's back up and why don't you describe what you're trying to accomplish

random monolith
#

In my game i have a restart button that replays the current section of the game and the animations with it. I am trying to add an initial state to my animation so when i restart the game, i do animator.Play("InitState", 0) and everything is placed accordingly

#

The scrolling asset you see is controlled by a simple script because i needed to control the scrolling speed of it ( instead of the offset in the shader directly which is more painfull to deal with ). Anim is controlling the speed variable while the InitState resets the offset to 0. The calculation of the offset is done in Update loop but always receives offset = 0 in the beginning

If i control directly the shader variable "Offset" of course it works
Also really thank you for your time and attention.

random monolith
#

I realise that just adding InitState without connecting to anything triggers this issue, this is weird

still iris
#

Why not just reset it in the code?

random monolith
#

I think it is less convienent, i just give a animator controller to an other script (that controls the game flow) and thats it

#

i can do it by code

#

So now the questions i am asking my self is: (1) Why InitState seems to still run while it already transitionned to Anim (2) Why it is running without being transitionned to (case above)

still iris
#

That's USUALLY caused by write defaults.

#

But if you have that off on all states then unsure.

random monolith
#

yep all off so even weirder

#

if you need any info tell me

In the meanwhile im still actively trying to figure out the problems, im going to update to the latest 2021 release to see if its because of that

Nope doesn't solve the problem

random monolith
#

Idk if there is a way to debug when animations sets a value but i don't think so

I'll try to make a blank unity scene to isolate the problem

Well i'm able to reproduce the bug with just two animations and the script, either its a animation problem or my script but i really doubt the script is the problem.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static MEC.Timing;
using static MathUtils;

public class ScrollingShaderController : MonoBehaviour
{
    public float offset;
    public float speed;
    Material mat;

    private void Awake()
    {
        mat = GetComponent<SpriteRenderer>().material;
    }

    // Update is called once per frame
    void Update()
    {
        offset = (offset + speed * Time.deltaTime) % 1;
        mat.SetFloat("_Offset", offset);
    }
}

Just the presence of Init state in the graph throws everything off

random monolith
#

(image below), Otherwise if i remove the offset property in the animation everything works

random monolith