So pretty simply, I have two scripts operating on a TextMeshPro - Text component. One manipulates the vertices of the text to give it a wobble, and one changes its alpha value over time so it fades in and out. If I disable the alpha script then the wobble works fine, but if I enable the alpha script the wobble script has no effect. In my mind these should be independent so I’m not sure what the conflict is.
Wobble:
TMP_Text textComp;
Mesh mesh;
Vector3[] vertices;
private void OnEnable()
{
textComp = GetComponent<TMP_Text>();
}
private void FixedUpdate()
{
textComp.ForceMeshUpdate();
mesh = textComp.mesh;
vertices = mesh.vertices;
for (int i = 0; i < vertices.Length; i++)
{
float x = (Mathf.PerlinNoise(Time.time * speed + i, 0f) * 2 - 1) * wavyness;
float y = (Mathf.PerlinNoise(Time.time * speed + i, 0f) * 2 - 1) * wavyness;
vertices[i] += new Vector3(x, y, 0);
textComp.UpdateGeometry(mesh, i);
}
mesh.vertices = vertices;
}
Alpha:
public class AnimateFloat : MonoBehaviour
{
[SerializeField] AnimationCurve curve;
[SerializeField] float animationLength = 1;
[SerializeField] UnityEvent<float> updateFloat;
float timeElapsed;
private void OnEnable()
{
timeElapsed = 0;
}
private void FixedUpdate()
{
timeElapsed += Time.deltaTime;
updateFloat.Invoke(curve.Evaluate(timeElapsed / animationLength));
}
}
I know I could have used an Animation instead of this script, but I was having the same issue with an animation so I tried this in case there was something weird going on with the animation behind the scenes.
So just to quickly reiterate: Wobbly text works on its own. Animating the alpha works on its own. If I have both scripts animate alpha works and wobbly text does not work.