Problem with Resource Loader in C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Arkae

I have been trying to use the ResourceLoader to change a the Normal Texture of a button but I can’t seem to make it work.
Currently I’ve been doing this:

public static TextureButton Struggle;
public Texture Break1;

public override void _Ready()
    {
        Break1 = ResourceLoader.Load("res://Section1/UI/Struggle_Break1.png") as Texture;
        Struggle.TextureNormal = Break1;
        Struggle = GetNode("BattleOptions/Struggle") as TextureButton;
    }

But it just get me this error:
E 0:00:05.003 void ButtonsManager._Ready(): System.NullReferenceException: Object reference not set to an instance of an object.
<C++ Error> Unhandled exception
<C++ Source> Section1\ButtonsManager.cs:18 @ void ButtonsManager._Ready()()
ButtonsManager.cs:18 @ void ButtonsManager._Ready()()

:bust_in_silhouette: Reply From: juppi

First initialize the variable

Struggle = GetNode("BattleOptions/Struggle") as TextureButton;

and then change its properties

Struggle.TextureNormal = Break1;

So you just should switch these lines.