Escape Block Textures Not Loading Properly Upon Reentering Room

Godot Version

v4.2.stable.official [46dc27791]

Question

I am trying to have an escape block with a TextureRect that has two different textures–an animated one where it’s awake and an inanimate one where it’s asleep. The textures for my escape blocks display properly sometimes and appear as a blank white texture other times (i.e. when leaving and reentering the scene). I have tried rewriting my code and using different methods and nodes to swap out the escape block textures, but all of them result in the white texture appearing at least some of the time.

Can anyone help me figure out what I’m doing wrong or link me to an answer for reference? I’ve looked around but couldn’t find anything.

EDIT: Even when I changed the wake and sleep functions to something simple:

func wake():
  modulate.a = 1
  texture.set_pause(false)

The textures still fail to load. Looks like it has nothing to do with the code failing to swap out the sprites, but rather the textures themselves not loading.

EDIT 2: I tried rewriting the escape block code to use the wake and sleep textures directly rather than applying them to a single texture:

func wake():
    wake_rect.visible = true
    sleep_rect.visible = false
    modulate.a = 1

(Small snippet shown for convenience - full escape block code is on the pastebin I linked)

Yup…the bug is still there.

Yeah that message I deleted had a thing I thought was the solution but wasn’t. Sorry for the confusion

Gonna bump this post (or whatever it’s called here) since it’s buried under 5 pages of posts

Apologies for the semi-frequent bumping but honestly I don’t think anyone will reply to this if they have to scroll down 5+ pages to find this

Despite nobody responding, I FINALLY FIXED IT LET’S GOOOOOOOOOOOO

I saved both the awake and asleep textures as .tres files and rewrote the code to have a single TextureRect use the .tres files:

extends StaticBody2D

var shape
var awake
var done = false
var temp_texture: Texture2D

@export var reverse = false # Reverse = sleep before panic, wake afterwards

@onready var collision_shape = $CollisionShape2D

@onready var texture_rect = $BlockTexture
@onready var texture = $BlockTexture.texture

const ESCAPE_BLOCK_AWAKE = preload("res://texture/escape_block_awake.tres")

const ESCAPE_BLOCK_SLEEP = preload("res://texture/escape_block_sleep.tres")

func wake():
	texture_rect.texture = ESCAPE_BLOCK_AWAKE
	modulate.a = 1
	set_collision_layer_value(1, true)
	set_collision_layer_value(2, true)
	set_collision_layer_value(3, true)
	set_collision_layer_value(4, true)
	#print("hi hi")
	
func sleep():
	texture_rect.texture = ESCAPE_BLOCK_SLEEP
	modulate.a = 0.5
	set_collision_layer_value(1, false)
	set_collision_layer_value(2, false)
	set_collision_layer_value(3, false)
	set_collision_layer_value(4, false)
	#print("bye bye")
	
func flip():
	if GameManager.panic:
		if reverse:
			wake()
		else:
			sleep()
	else:
		if reverse:
			sleep()
		else:
			wake()

# Called when the node enters the scene tree for the first time.
func _ready():
	texture_rect.visible = true
	texture_rect.size.x = collision_shape.shape.size.x
	texture_rect.size.y = collision_shape.shape.size.y

func _process(delta):
	texture_rect.visible = true
	texture_rect.size.x = collision_shape.shape.size.x
	texture_rect.size.y = collision_shape.shape.size.y

	if GameManager.panic:
		if reverse:
			wake()
		else:
			sleep()
	else:
		if reverse:
			sleep()
		else:
			wake()

(It took me a few minutes to trim out a lotta unused code LMAO)
The textures load! Another issue solved.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.