|
|
|
 |
Attention |
Topic was automatically imported from the old Question2Answer platform. |
 |
Asked By |
DerangedPufferfish |
I have some code that changes the color of the player when I press a button:
var color = SpatialMaterial.new()
func _on_Blue_pressed():
color.albedo_color = Color(0, 0, 1)
$MeshInstance.set_surface_material(0, color)
But when I change the scene it resets the color.
I know the basics of how singletons work but I have no idea how to keep the color the same using them. I assume I would need to change the player’s color in the singleton’s script but I cannot figure out how to do that, does anyone know how I can do this?
|
|
|
 |
Reply From: |
exuin |
You can store the color of the material in the Singleton, like player_color
or something. After reloading the scene, you can fetch the color from the Singleton and set it for the material.
I have tried this but I don’t know how I would get the player’s material.
And how would I detect when the scene is changed or reloaded?
DerangedPufferfish | 2021-05-17 11:49
I figured out how to get the player’s material and set it using the singleton but I have no idea how I would know when the scene is changed.
DerangedPufferfish | 2021-05-17 13:55
The ready function will be called again when the scene is reloaded
So the _ready() function will be called every time the scene changes if it is on the singleton?
DerangedPufferfish | 2021-05-17 14:00
No, the _ready function will be called on the scene that was reloaded/changed.
I think I get it now, thanks.
DerangedPufferfish | 2021-05-17 14:11