Weird flicker (flash) when I switch between scene

Godot Version

4.3

Question

Hi there !

I have build my first game with Godot…
But when I switch from my “made with Godot” scene to my “Level 1” scene, there is a small flicker that happen for some reason…

Flicker happen at 0:07

The scene setup is like this :

  • “Made with Godot” scene is a 2D scene
  • “Level 01” is a 3D scene
  • “Canvas_Layer_Background” is a canvas layer scene that used as the same background for my two scene

Could you share your level 1 loading script?

3d and 2d rendering happens simultaneously, so there shouldn’t be any concern there.

It looks like the default gray when it flickers.

My guess is that it’s a resource handling issue, and, depending on how it’s handled, you are overrunning the frame time, or deferring some resource management to another pass, leaving you with one or more frames with nothing to render.

Sure,

Here is my “made with godot” scene script

extends Node2D

@onready var sprite_2d = $Pivot_Point/Sprite2D
@onready var sprite_2d_2 = $Pivot_Point/Sprite2D2
@onready var pivot_point = $Pivot_Point

func _ready():
	var tween = create_tween()
	
	tween.tween_property(pivot_point, "rotation", 0, 2).set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_IN_OUT).set_delay(5)
	tween.tween_property(sprite_2d_2, "modulate:a", 0.01, 2).set_delay(1)
	tween.parallel().tween_property(sprite_2d, "modulate:a", 0.01, 2).set_delay(1)
	await tween.finished
	
	get_tree().change_scene_to_file("res://Scenes/Level_01.tscn")

And here is my Level_01 scene script

extends Node

@onready var ball = $Ball
@onready var timer_long = $Timer_Long
@onready var control = $CanvasLayer/Control

@onready var end_level = $Node3D/Gameboard/End_Level
@onready var gameboard = $Node3D/Gameboard

@onready var piece = $Node3D/Gameboard/Pieces/Piece
@onready var piece_2 = $Node3D/Gameboard/Pieces/Piece2
@onready var piece_3 = $Node3D/Gameboard/Pieces/Piece3
@onready var piece_4 = $Node3D/Gameboard/Pieces/Piece4
@onready var piece_5 = $Node3D/Gameboard/Pieces/Piece5

@onready var pieces_group = get_tree().get_nodes_in_group("pieces_group")

var animation_finish = false
var rotate_speed = 45

func _ready():
	end_level.visible = false
	
	gameboard.rotation = Vector3(0.002,0,0)
	gameboard.scale = Vector3(0.001,0.001,0.001)
	piece.scale = Vector3(0.001,0.001,0.001)
	piece_2.scale = Vector3(0.001,0.001,0.001)
	piece_3.scale = Vector3(0.001,0.001,0.001)
	piece_4.scale = Vector3(0.001,0.001,0.001)
	piece_5.scale = Vector3(0.001,0.001,0.001)
	
	tween_at_start_of_game()

func _process(delta):
	var rotate_left_right = (Input.get_action_strength("left") - Input.get_action_strength("right"))
	var rotate_up_down = (Input.get_action_strength("up") - Input.get_action_strength("down"))
	
	if animation_finish == false:
		rotate_left_right = 0
		rotate_up_down = 0
		ball.freeze = true
		
	else:
		gameboard.rotation_degrees.x += rotate_left_right * rotate_speed * delta
		gameboard.rotation_degrees.z += rotate_up_down * rotate_speed * delta
		ball.freeze = false
	
	if gameboard.rotation.x > deg_to_rad(30):
		gameboard.rotation.x = deg_to_rad(30)
	if gameboard.rotation.x < deg_to_rad(-30):
		gameboard.rotation.x = deg_to_rad(-30)
	
	if gameboard.rotation.z > deg_to_rad(30):
		gameboard.rotation.z = deg_to_rad(30)
	if gameboard.rotation.z < deg_to_rad(-30):
		gameboard.rotation.z = deg_to_rad(-30)
		
	if are_all_pieces_invisible():
		end_level.visible = true
		

func tween_at_start_of_game():
	var tween_start = get_tree().create_tween()
	var tween_start_piece = get_tree().create_tween()
	
	var pieces = [piece, piece_2, piece_3, piece_4, piece_5]
	
	
	tween_start.tween_property(control, "modulate:a", 1, 2).set_ease(Tween.EASE_IN_OUT)
	tween_start.parallel().tween_property(control, "scale", Vector2(2,2), 3).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
	tween_start.tween_property(control, "modulate:a", 0, 0.01).set_ease(Tween.EASE_IN_OUT).set_delay(1.5)
	
	tween_start.tween_property(gameboard, "scale", Vector3(1,1,1), 0.5).from(Vector3(0,0,0)).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)

	for piece in pieces:
		tween_start.tween_property(piece, "scale", Vector3(0.75,0.75,0.75), 0.4).from(Vector3(0,0,0)).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK).set_delay(0.05)
		
	await  tween_start.finished
	
	animation_finish = true
	
func _on_area_3d_body_entered(_body):
	reset_board()
	timer_long.start()

func _on_timer_long_timeout() -> void:
	ball.linear_velocity = Vector3(0.001,0.001,0.001)
	ball.angular_velocity = Vector3(0.001,0.001,0.001)
	ball.position = Vector3(0, 6 , 0)
	timer_long.stop()
	
func reset_board():
	var tween = create_tween()
	tween.tween_property(gameboard, "rotation", Vector3(0.002,0,0), 1).set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_EXPO)

func are_all_pieces_invisible():
	
	var pieces = [piece, piece_2, piece_3, piece_4, piece_5]
	
	for piece in pieces:
		if piece.visible == true:
			return false
	return true

How do you swap them?

What i can tell is that your made-with-godot has its own background, i assume the level_one has the same background, but its own copy?

If this is the case i would probably move the background to the main scene swapping so that it persists and is always in memory ready to be shown.

Thx !

*As it stand now, my background is it’s own scene that is instance inside my two other scene (made with godot and level_01)…So I make sure every scene have the same background


So I should have a main scene with only the background and then load my other scene inside that main scene ?

Thx, Autoload did it :slight_smile:

Never used that fonctionnality before !

1 Like

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