Strange shader color behavior

I have a sprite renderer with a star image (representing the point light of a planet) that is supposed to fade out when the camera gets to close to it. All it does is adjusts the shader’s _Color alpha (the actual color used is set by _Emissive).

It works fine when adjusting it from the inspector without the script,

Alpha 1.0
9003043--1240480--Capture.PNG

Alpha 0.0
9003043--1240492--Capture2.PNG

but when I adjust it from this script:

void Update()
    {
        float distance          = (_cam.transform.position - transform.position).magnitude;
        float alpha             = (distance - _fadeEndDistance) / _range;

        Color color             = new Color(0, 0, 0, alpha);
        _spriteRenderer.material.SetColor("_Color", color);
    }

all of the sudden it leaves this semi-transparent sprite that doesn’t go away unless I also adjust _Emissive to black from the inspector.

9003043--1240495--Capture3.PNG
You can sort of see the red tinted stars (the emissive color is blue-teal) when it should be completely transparent like the second image. The _Color alpha shows as 0.0 in the inspector, as expected.

Now I could just adjust _Emissive by script as well, but it makes absolutely no sense. It works perfectly when I manually adjust it, but adding just the code that does exactly the same thing causes different results?

I’ll include the shader since it’s custom for the bloom effect. Probably not the best way to do it but it was the only way I could (sort of) getting it working properly:

If anyone has any idea of what could be causing this I would greatly appreciate it.

I’m a donkey. I just had to clamp the alpha like so:

alpha = Mathf.Clamp( (distance - _fadeEndDistance) / _range, 0f, 1f);
Wasted a good chunk of the evening messing with shaders, etc… and then I realized it obviously has to be from those 4 lines of code and fixed it 3 minutes after posting.