I’m new to Godot, I’m troubleshooting my first card game via the engine. I’ve created a ~1.5 second animated sprite like so:
extends Sprite2D
func _ready():
pass
func playSampleAnimation() → void:
if $AnimationPlayer.is_playing() == false:
$AnimationPlayer.play("sample_animation")
I have a Sprite Node that has the child AnimationPlayer or perhaps a better why to describe it is I have a Scene with a Sprite as a parent and a script attached.
The issue below is only applicable to testing on lower-tiered devices, e.g my ONN Tablet which only has 2GB of RAM.
I have been troubleshooting the game to find chokepoints and I see that when I comment out the call to the animation function the game runs quicker/smoother.
I’ve been using Time.get_ticks_usec() to time game movements:
-Average Movement Time without Animation: 150
-Average Movement Time with Animation: 30,000
My first thought is if I am using animation player correctly? Or if there are other options? Or perhaps the Animation Scene is too large (.tscn file is 4KB and the .gd file is 450 bytes)?
Or should I shorten the animation, maybe the 1.5 seconds might correlate to the 30,000 average movement time.
Or I was thinking if I am using it correctly, is there a way in Godot to read the size of a devices RAM? So in this case if the RAM <= 2 GB, don’t play the animation.
Any thoughts on this would be helpful, the animation is a nice feature for my game and I don’t want to throw it away. Thanks.
I doubt it is the RAM unless your sprite is an uncompressed 270 mega pixel image. Which probably doesn’t even exist today, unless your looking at a detailed picture of space from the James Web Telescope.
My guess is the hardware is struggling, or limiting itself to conserve battery. The device’s OS is probably not giving Godot enough CPU time to run.
If this is an android device you can get GAME power mode if you add an appCategory of GAME in your AndroidManifest.xml
I have reviewed the System Requirements Link - for mobile it states:
RAM
Native editor: 3 GB
Web editor: 6 GB
I’m not sure what Native Editor or Web Editor are, but still both have a RAM requirement > 2GB. So perhaps this device I am testing on doesn’t meet the Godot minimum requirements. Thanks.
Native editor is the Godot editor itself usually installed from the app store or desktop. The web editor is this.
But if you export your game, it’s min reqs are 2gb, but this is just a general recommendation.
I have a small 2d project, the Godot editor reserves ~750MB RAM, with an exported game only reserves ~150MB RAM. Godot doesn’t use all this at once the OS will store some on disk using a swap. In both cases should work fine for the tablet.
Also your animations are <1MB, small enough to fit on the cache of the CPU! The entire animation is happening on the CPU and you are measuring process time. Which means your not getting scheduled for 30ms on average. VS, 150us when you reduce the workload. This means your process is getting pre-empted before it can finish. Hence the choppy behavior.
A follow up question, how many nodes and tracks are in the animation? What type of properties are manipulated?
I would look to see if you have some inefficient code being triggered within the animation.
There is also game interventions to configure as well.
You can also run profiling to see where your app is taking most of its time.
Thanks for taking the time to assist. Again, I am new to Godot and I am self-taught so I am not as fluent in all of this as your typical Godot programmer might be. I understand better regarding the 2GB RAM, you are sharing that is the available space on the device, and that my game cannot exceed that size. I’m exporting an apk file for testing, size = 300MB. I was misunderstanding that information in the link to infer that 3 or 6 GB was needed to run a Godot game on a device.
My animation has just 1 track, I’m advancing through a different frame of my sprite sheet every 1/10 of a second or so.
My sprite sheet is a png file (3.29 MBs, 1200 x 720) and it’s split into 10 Hframes and 4 Vframes. The animation itself runs at about 3 seconds, but in the Animation Player I set the Speed Scale to 2, so I think that means the animation runs twice as fast, so about 1.5 seconds.
This is a card game, so when a player moves a card to a certain position the quick animation plays (animation A). The player then can tap another card for a move (perhaps before the animation completes) - causing either Animation A to play again or play the new Animation B… and so on. Depending on the players speed at max two animations could be playing at once.
Okay, I still don’t think that is enough to reach a memory limit. I don’t even think that should hit a CPU limit either.
if you are just changing frames have you tried an AnimatedsSprite2d? You can provide it a sprite sheet and and select the frame that is being shown or play the whole set.
My only thought is this could be a render issue, and asking the system to draw may be hanging somewhere. Or you using compatibility or mobile render?
Also another great profile tool for Android is Perfetto UI