0 votes

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.
ButtonsManager.cs:18 @ void ButtonsManager._Ready()()

Godot version 3.3.4.stable.mono
in Engine by (12 points)

1 Answer

0 votes

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.

by (1,067 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.