This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I need help to connect a singleton to Sprite.texture inside Player scene where i can change the texture using a script i wrote.
What should i write in singleton to access the sprite variable mentiond?.
..... |
.... Player
............... |
................ Sprite.texture

to detail my issue: that whenever I change the current scene the Player "Player.tscn" will be deleted and all current values will be lost. and i can't figure how to save the variables in Player to the singleton so whichever the new scene is, it should bring back the Player values from singleton.
Thanks for your precious time.

in Engine by (51 points)
edited by

1 Answer

+1 vote

This worked for me.

by (134 points)

what is the ".get_child(1)" job in this code line?

get_child(1)  will get you the current scene child of the root. Suppose your scene is level1 then It will get you level1 node. But it's not always the case, it all depends on the number of singletons you have in your project. In my project, there was on singleton code, so it took the 0th index so get_child(0) will get me my global script and get_child(1) will get me my scene node. But If I had one more singleton, then to access my scene node I would have used get_child(2)... I hope this explains

yes it explains a lot. this would be a helpful information.

if my Player in the remote tree is shown as the following:




Ysort is a child of Level1 and Player is a child of Ysort
show me how it will be wriiten depends on your earlier code:
thanks a lot.

Yes. Just read the docs for find_node() as there are other overloads too.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.