0 votes

I have a singleton named Globals set up in my game. Below is a screenshot of the project settings:

project settings

The main scene for my game is Game.tscn and I have the following code in that scene:

func _ready():
    if get_viewport().size.x > tile_size.x * Globals.GridSize.x:
        zoom_factor = (tile_size.x * Globals.GridSize.x) / get_viewport().size.x
        min_zoom = zoom_factor
    if get_viewport().size.y > (tile_size.y * Globals.GridSize.y) / zoom_factor:
        zoom_factor = (tile_size.y * Globals.GridSize.y) / get_viewport().size.y
        min_zoom = zoom_factor

The game is working fine when I run it on my PC. Yesterday it was working fine on Android via both USB and package install, however today I'm getting the following error when running on Android:

Invalid get index 'GridSize' (on base: 'Nil') (Line 19)

Line 19 is:

zoom_factor = (tile_size.x * Globals.GridSize.x) / get_viewport().size.x

From the debugger I can see that Globals is [null], whereas when I run the game on my computer it shows me the object ID of Globals. It looks like the singleton is no longer recognised on Android.

Does anyone have any idea what might have caused this and how I can fix it?

I have tried removing and readding the singleton with no success. I don't really know what else to try...today I haven't modified anything in project settings or Game.tscn, so I can't work out why this is impacted.

in Engine by (39 points)

Does your apk contain "assets/Globals.gdc" and "assets/Globals.gd.remap"?

(You you should be able to check the apk contents with any unzip tool.)

Check the build log of the apk (output window) if any file access errors or signing errors occur when building the apk.

Yes, I can see both those files in the apk.

There are no errors in the output box, and looking at the command prompt window which is open while Godot is running, there's only a warning at the end to say the jar contains entries whose certificate chain is invalid. I don't think this is related, but including a screenshot here in case.

package  output

1 Answer

0 votes
Best answer

I have managed to resolve this issue.

The problem wasn't with the globals scene, but rather another scene was referencing an image which no longer existed. By deleting the frames from the animation and recreating, this fixed the missing image issue which in turn resolved the error triggered by the 'missing' globals.

It seems the sprite issue somehow led to the problem with my globals / singletons.

by (39 points)
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.