Godot Version:
4.5
Problem:
I am making a script where I can simply press an @export_tool_button, and it will change the palette and the physics material on its staticbody2D child.
When I place one of these objects in a different scene and press the “Change Type” button, it will successfully change the palette and (according to the print statement) its physics material too. However, on loading the game, the object will have the correct “type” value, the palette will stay as the new palette, but the physics material on the child will revert to the original non-bouncy material.
I used another button to test when the material gets reverted, and it’s definitely on loading the game.
My code for this script is below:
@tool
extends Sprite2D
@export_range(0,1) var type : float
@export_tool_button("Change Type")
var change_func : Callable = func():
change_type()
@export_group("Components")
@export var sprite2D : Sprite2D
@export var static_body2D : StaticBody2D
@export_group("Assets")
@export var normal_material : PhysicsMaterial
@export var bounce_material : PhysicsMaterial
@export var normal_palette : Texture
@export var bounce_palette : Texture
# ---CHANGE TYPE
func change_type():
if (type == 0):
##change material
static_body2D.physics_material_override = bounce_material
##change palette
sprite2D.material.set_shader_parameter("palette", bounce_palette)
type = 1
print("bounce = ", static_body2D.physics_material_override.bounce)
else:
##change material
static_body2D.physics_material_override = normal_material
##change palette
sprite2D.material.set_shader_parameter("palette", normal_palette)
type = 0
print("bounce = ", static_body2D.physics_material_override.bounce)
# ---TEST TO SEE WHEN THE REVERSION HAPPENS
@export_tool_button("Check if Reverted")
var check_func : Callable = func():
check_for_bounce()
func check_for_bounce():
print(type)
print("bounce = ", static_body2D.physics_material_override.bounce)
func _ready() -> void:
check_for_bounce()
Question:
Why does the physics material property on the child get reset when loading the game, and how can I prevent this?
Hints:
At this point, the object is simply structured: Sprite2D → StaticBody2D → CollisionShape2D.
Both resources are set to “Local to Scene.”
Extra 
*For now, I will simply use the type variable to reassign the material on load, but I’m not satisfied with that band-aid ![]()
*Also also, I am using my laptop, and it has this problem where when certain apps are left without anything moving on the screen, my graphics card will crash the computer. So if you know what to do… please tell me. This particularly happens in Godot, and in Hades2 when it is in the pause menu. In Godot its very funny cause even just the flashing mouse when entering text will prevent it lol