Invalid Get Index Gradient With A Day Night Cycle

Godot Version

Godot4

Question

I am getting an invalid get index gradient error with my day night cycle code below. I was trying to make it to where the time kept ticking throughout all scenes and wouldn’t restart anytime the player came back into the main scene but I don’t think it likes being autoloaded as it now has technically no gradient map to pull from do you guys have a fix. Do I need to have the UI in every scene to give it its gradient? here’s my code below

extends CanvasModulate

const MinutesPerDay = 1440
const MinutesPerHour = 60 
const InGameToRealMinuteDuration =  (2 * PI) / MinutesPerDay 

signal time_tick(day:int, hour:int, minute:int )

@export var gradient: GradientTexture1D
@export var INGAME_SPEED = 50.0

var time:float = 0.0
var past_minute: float = -1.0


func _process(delta: float) -> void:
	time += delta * InGameToRealMinuteDuration * INGAME_SPEED
	var value = (sin(time - PI/2) + 1.0) / 2.0
	self.color = gradient.gradient.sample(value)
	
	_recalculatetime()

func _recalculatetime() -> void:
	var total_minutes = int(time / InGameToRealMinuteDuration)
	
	var day = int(total_minutes / MinutesPerDay)
	
	var current_day_minutes = total_minutes % MinutesPerDay
	
	var hour = int(current_day_minutes / MinutesPerHour )
	var minute  = int(current_day_minutes % MinutesPerHour )
	
	if past_minute != minute:
		past_minute = minute
		time_tick.emit(day, hour, minute)