Sprite color reverts to original value in between Update calls
In an update method, I am calling this:
var projectileSpriteRenderer = currentProjectile.GetComponent<SpriteRenderer>();
Debug.Log($"Alpha of {currentProjectile.GetInstanceID()} currently
{projectileSpriteRenderer.color.a}");
var percentageOfRequiredEnergy = player.AccumulatedEnergy / player.QueuedSpells[CurrentSpell].EnergyCost;
var lessThanOne = percentageOfRequiredEnergy < 1f;
var newAlpha = lessThanOne ? percentageOfRequiredEnergy * .75f : 1f;
projectileSpriteRenderer.color = new Color(1, 1, 1, newAlpha);
Debug.Log($"Alpha now {projectileSpriteRenderer.color.a}");
If I force newAlpha to always be 0, I get the following logs every Update call:
Alpha of -94778 currently 1
Alpha now 0
The subject sprite is fully visible in the game and when I inspect it in the Editor, the alpha is at 100%. If I change the alpha in the Editor and then close the color picker, the alpha immediately reverts to 100%. This means that in between calls to Update where the alpha is being changed, for some reason the value is reverting to that of the Prefab. If I change the prefab alpha to 50%, it logs something like:
Alpha of -95248 currently 0.5019608
Alpha now 0
This exact same code was working earlier and now doesn't, for what is as far as I can tell literally no reason.
the code is fine the issue is somewhere else, try disabling the script and then change the alfa manually in the editor, if it continues forcing alpha to one the issue is in other script
Your answer
Follow this Question
Related Questions
Do Something Once 1 Answer
fixed update is not being called 1 Answer
void Update() problem 1 Answer
how's the relationship between updates? 0 Answers
C# Update Function Question 2 Answers