renderer.enabled doesn't work but coloring does

I have a prefab with it’s Sprite renderer disabled (nothing else, no children). I want to enable in the Awake function if it meets a certain condition so I have this code:

SpriteRenderer sprite= GetComponent<SpriteRenderer>();

So the sprite is initially disabled and thereafter is enabled… but it does not show the sprite! When I put that code in the Update function is always disabled, even when it is changed to enabled by code every frame.

I wanted to check if the sprite was correct so I tried this:;
and this works and the sprite turns to red

So I tried this also:
and the sprite dissapears. Do I have to use the coloring to enable/disable the sprite or does anybody knows why disable/enable is not working?
Thanks in advance

I found the problem, it is in the Animator Controller, the first State has nothing and there is a transition to an animation activated by a trigger. If I delete that animation (that is not being played) everything works.

In your prefab use the check button to uncheck “Sprite Renderer” and add your script to the prefab. In your script use something like:

function Start() {
    if(true) {
        renderer.enabled = true;

First give that a try, then add your if statement details.