Hi! Need help, i am in confusion..
So, simple test game, CharacterBody2D moving left/ right, jumping and instantiating bullets (Area2D). While testing on PC, sure all ok (hm, 30 lines of code in total, what can be freezing...)
So, added 4 TouchScreenButtons, linked them to that actions. While testing on PC again (using mouse to push touch buttons) - sure all normally working.
Compiling APK, testing on device. Left/ Right - normally smoothly working, but Jump & Fire - 5 sec working, 3 sec freezing, 3 sec working - 3 sec freezing, 2 sec working - 5 sec freezing, etc (w/o any regularity).. Freezing - i mean no reactions on touching buttons..
What can be wrong with such simple example?..
PS device - Samsung Galaxy S23 Ultra
Thanks a lot for any thoughts!!

    • [deleted]

    • Best Answerset by mun001

    So I see a few errors. direction is a float value. You check if direction but that makes no sense. You may want to check if it is zero, but it may not be due to floating point error and also gamepads can have dead zones where a value is like 0.053 when you are not touching the analog pad. You should instead check if the absolute value is less than a small number, maybe if abs(direction) < 0.1:. The move_toward doesn't make much sense either. The last value is a delta, but you are only moving by speed anyway (unless you have acceleration) so you could just set velocity.x = 0 and that would stop the movement. Typically I would not use is_action_just_pressed. You can use is_action_pressed just fine, as you are checking if they are on the floor already, so that will stop double jumping. In fact, it is much better to do your input in the _input(event) function, as this happens exactly when the input happens, not necessarily every frame (checking every frame is wasteful and can also cause timing bugs). You should use your fire function also in _input(). It might make sense to check is_action_released rather than just pressed. The bullet object should be a onready var which preloads the asset, for example @onready var bullet = preload("my_bullet.tscn"). You are passing it around, which may be messing up the memory or making copies and is likely the issue. You can preload several assets at the top of the script if you need different art, but try with one to start with to see if that fixes it. bullet.instantiate() should be fine, but you can do a call_deferred on the add_child as the error message says. Here again, you are checking if direction is less than 0, which is an integer, you should check if direction < 0.0:. Doing the add_child last is probably a good idea, after you set the properties. Aside from that, it could be something else in your setup, as I don't see the rest of your code or the scene tree. But start with what I said and see if it helps.

Anything can be wrong. It's hard to say without seeing the code.

    cybereality Thanks for the answer!
    The code for moving of Hero (all inside _physics_process):

    	var direction = Input.get_axis("left", "right")
    	if direction:
    		velocity.x = direction * SPEED
    	else:
    		velocity.x = move_toward(velocity.x, 0, SPEED)
    
    	move_and_slide()

    The code for jumping:

    # Handle Jump.
    	if Input.is_action_just_pressed("jump") and is_on_floor():
    		velocity.y = JUMP_VELOCITY

    The code for firing (at Hero side, pfire is preloaded scene with Area2D -> bullet):

    	if Input.is_action_just_pressed("fire"):
    		Shoot.emit(pfire,dir,position)

    Shoot function emitted:

    func _on_hero_shoot(bullet, direction, location):
    	var bull = bullet.instantiate()
    	get_parent().add_child(bull)
    	var v2 = Vector2(location.x, location.y)
    	if direction<0:
    		v2.x-=50
    	else:
    		v2.x+=50
    	bull.position = v2
    	bull.velocity = Vector2(direction,0)

    And that's it.. Could you please advise maybe something? Well, say true, i expect from such simple scene is like WYSIWYG - mean how it works on PC, the same it will works on device, but seems to be i was wrong ;(

    Thanks a lot!

    If you can upload the project folder as a .zip, I'll see if I get the same results.

      DaveTheCoder thanks!! here it is.. really appreciate if you can help me...

      t3-godot.zip
      11MB

      I haven't tried exporting to Android yet. I'll need to change some of the Android settings to do that.

      I ran it in the editor on my desktop computer, and saw that there were ten warnings/errors, including a couple that might matter, and I might fix those first.

        DaveTheCoder yes, sorry, the same, but again - game is running & i can do what i expected finally.. Except at device.. Most of "errors" is because of "parameter is never used"

        The first of these should probably be fixed, and definitely the second one:

        W 0:00:00:0199 The local variable "dir" is shadowing an already-declared variable at line 13.
        <GDScript Error>SHADOWED_VARIABLE
        <GDScript Source>hero.gd:34

        E 0:00:00:0529 tucha.gd:38 @ do_pulki(): Parent node is busy setting up children, add_child() failed. Consider using add_child.call_deferred(child) instead.
        <C++ Error> Condition "data.blocked > 0" is true.
        <C++ Source> scene/main/node.cpp:1136 @ add_child()
        <Stack Trace> tucha.gd:38 @ do_pulki()
        tucha.gd:45 @ _on_timer_timeout()
        tucha.gd:17 @ _ready()

        That may not have any effect on the problem you've reported. But it's good practice to resolve reported errors (and usually warnings) before trying to fix other problems.

          DaveTheCoder Thank you, but.. how?.. if Game is working normally, how i can fix it? i mean from gaming pipeline..

          DaveTheCoder What do you think overall?.. May i (or somebody who will have a such issues) connect to developers of Godot Engine, so simple things are not working? ;(

            mun001 simple things are not working

            A desktop computer and a mobile device are different platforms, with different operating systems and different hardware. It's very common for an application to work differently on them.

            If it turns out that the problem is a bug in the Godot engine, then it should be reported on the github issue tracker so that the Godot engine developers can address it. But we don't know yet if it's an engine bug.

              DaveTheCoder hi! thanks! agree that this is diff platforms.. Fixed all errors - nothing happens, the same situation.. Can it be due to device itself?

              Saying true, the same things happening when i first did it & build apk on Unity. Strange, but abs the same situation where - left/right is working normally, but jump/ fire - mess. And after some weeks of discussing this situation in Unity forums, the verdict from support forum experts was like "Unity now is not enough good for mobile games with touch controls" 😉)))

              This was a reason why i wanted to switch from Unity to something else (Godot in current case, i thought Godot is more lighter & such problems with simple one scene game should not appears), but i got the same in this engine.. Will try to test it on old Android mobile of my son, no other ideas from my side ;(

              Or can it depends on Android SDK version for example? For building apk in Unity & Godot i used the same SDK (that comes with Unity)..