UI counter value does not transfer between scenes

Hello!

Having an issue with a coin counter UI element that displays a numerical value for coins collected. The issue is when you move to a new scene the value disappears and no longer displays the numbers. Moving back to the previous scene does not restore the numbers they just go away completely.

I have searched the topics and read though the UI tutorial but no solutions were presented. If anyone could point me in the right direction I would very much appreciate it.

thank you!

Worth splitting this into two questions before you change anything, because they look identical on screen and have different fixes.

Is the number gone, or is only the display gone. After the scene change, read the coin value somewhere that is not that UI element, a debug print or a second temporary label, and look at what it says. If it still holds the right number, the count survived and what broke is the element’s binding to it. If it reads zero, the value itself did not survive.

That matters because a UI element that lives in a scene is created and destroyed with that scene, so anything held on the element goes when you leave. Two things have to be true for the counter to keep working. The count has to live somewhere that outlives the scene, and the new element has to be pointed at it when the new scene starts, since a freshly created element begins with whatever default it was authored with rather than with your last value.

If the test says the value survived, look for where the element is told which value to read and make sure that runs on scene start, not only once at game start.

1 Like

The UI is fine. It persists through scenes (i.e.there is an instance of the each UI element in each scene. The value/number disappears in the UI element. It no longer displays a value even if more coins are collected. The value for which the counter collects comes from a variable from the player. The total collected variable does not display in the console by default. AGM doesn’t seem to have an easy way to add the variable values to the console display that I have found. It is an easy enough gdscript I suppose so I will do that to make sure the variable itself persist through transitions.

However that still leaves the issue of why the numbers disappear. I get that if the target player variable is wiped on transition the value would disappear but then why doesn’t it reappear when a new coin is collected? I have other UI elements that transfer their values with no problem. The only difference is this one displays a numerical value.

For seeing the value without writing anything, my F1 Debugger has a switch and variable list for both Project and Object scope that you can page through while the game is running: [Plugin] Baz F1 Debugger

Where does the coin count live right now? If it’s an object variable on the player, I’d try moving it to a Project Variable in the Database instead. Those aren’t tied to a scene, so they survive the transition and the UI element can read the same one from any scene.

On the number not coming back when you collect another coin, I’m wondering if the display is pointed at the player object and losing that target on the transition. If it’s resolving the object once when the scene loads and never finding it again, it wouldn’t have anything to show even though the counting still works. Could you post a screenshot of the UI element’s settings, mainly what it’s set to target for the value?

2 Likes

Thank you Baz for the plug in! I will use that quite a bit I think. As for making the coin count a project variable could some one point me to the best way to do that please? I will mess around with it of course but I am not familiar with the proper process of setting up project variables and dbs in AGM or Godot. It seems now is the time to learn :smiley:

Project Variables:

1 Like

Thank you very much! Much easier than I thought it would be

@Baz alright been fiddling with this for a while now and it just is not working despite everything looking correct. Using the Debugger the system is counting all coins collected and maintaining the total on scene transitions. I have switched the variable from the player to the project and pointed all associated scripts to reflect the change.

for the UI counter:

for the coin itself:

The only change is now the UI counter does not display a value at all anymore.

And for some reason your state tracker is throwing errors when i run the game.

Again any help would be much appreciated.

Judging from the error, it seems the signal wasn’t connected. You need to connect it manually.

1 Like

There could be a lot going on here, anyway to send over project to pgmmv-support@gotchagotcha.jp so we can further look into it?

1 Like

the project is sent. Thank you so much for being willing to look at it.

Thanks for sending the project over, I got the counter working.

Your coin, the coins project variable, and the Display Text on the Coin_counter object are all set up right. The problem was the Coin_counter placed inside Lvl_01_01_Ruined_City1 and Lvl_01_01_Ruined_City2. Those two had their own saved copy of the Display Text settings from before you made the switch, and that copy was still looking for the old Gold Coins variable on the player. That variable is gone now, so they had nothing to show. Lvl_01_Ghostwood_North didn’t have a saved copy and the counter worked there without me touching anything.

To fix it on your end, open both Ruined City scenes, delete the Coin_counter from the UI layer, and drag a new one in from coin_counter.tscn. It sits at 187, 30 in both. If any other scene shows a blank counter I’d do the same there.

To avoid it in the future, I’d keep the option that lets a placed object change an action’s settings turned off unless one of them really needs to be different. When it’s on, each placed object keeps its own copy and changes you make to the object later don’t reach it. I don’t think the editor shows those old copies once the option is off, which would be why everything looked right to you.

The State Tracker errors are from my plugin, not your project. It’s complaining once at scene start about a GameObject that doesn’t have the signal it listens for. It doesn’t affect anything and I’ll get a fix into the plugin.

1 Like

Thank you very much! I really appreciate your time on this. I am eager to get this up and running

This fixed the issue when entering a new area Thanks again! But when going back to an area that has already been explored the coin count disappears again. Again I can not seem to figure out why. Any advice would be much appreciated.

I apologize for including the Lvl_01_Ghostwood file that was not in the scope of the issue at hand (it has its own issues LOL).

If you untoggle the Keep State After Scene, it will work:

1 Like

You so good! Thank you again!:vulcan_salute:

1 Like