#Script to update Camera2D's position via input stops working AFTER changing scenes.

25 messages · Page 1 of 1 (latest)

elder dawn
#

Hey I'm having a weird issue I can't solve after looking through the 2D Camera documentation and trying many different things to get it working. When I first load my game and enter my "Talent Menu" scene I have inputs to change the camera's position up and down which work as intended. I can return to the main menu scene and then go back into the talent menu scene and it will still work. However as soon as I enter my "Game World" scene and then return to the menu and go into the Talent scene again, the inputs work but the camera's position doesn't change anymore.

The camera is enabled, running print(camera.is_current()) returns true, the input is working, I'm not getting any errors, just the position of the camera won't move. I've attempted moving the camera into a Node2D and moving the parent but that had no effect either. I tried removing my camera limits and that didn't help. I'm not really sure where to go from here, I can't seem to find anything similar to my problem after a couple days of searching. Any help or advice on what to search would be greatly appreicated!

dire fjord
#

Did you check the Remote scene tree while the game is running to see if there are any other cameras in the scene or some values on the camera not set?

elder dawn
#

I have, there's just the single camera in the scene that works prior to switching to the main game scene. All the values are the same in remote when it is working on and not working, the position just won't change.

dire fjord
#

And you say the keys still work? So if you set a breakpoint on line 21 for example it will still trigger?

elder dawn
#

The breakpoint is hit both without going into the main game and after going into the main game scene and then the talents.

tiny flicker
#

@elder dawn
I'm not sure what it is, but cameras doesn't move like that anymore.... might be a bug, but this is the only way I've been able to move it with input instead of being attached to a node.

func _process(delta):
    if playerDead:
        return
    $Camera2D.position = lerp($Camera2D.position, $Player.position, 1*delta)
#

You can change the speed of the camera by adjusting the 1

elder dawn
#

My line of code works initially (pre-loading the main game world) and I have another camera inside the game world (independent of the one that is breaking) that uses the same line that has no issues, it's just bizarre that it stops working after reloading. When I'm home later I'll see if your method works for me

#

Using camera movement in my screenshot

tiny flicker
#

I wonder then if you have two, one that isn't working doesn't print or does?

elder dawn
#

This is the in-game camera to pan around the map, the one that is failing (after loading the scene in the video) is inside a menu, it being the only camera in the scene

tiny flicker
#

So when you switch to the menu, the old camera is no longer available?

elder dawn
#

Correct, I return to the main menu which exits the scene in the video and then when I click on my talent button it enters the new menu scene with the camera that isn't moving

tiny flicker
#

Hmmm, so I wonder then how your menu is setup. It could be that you may want to kind of separate it, for instance, if it's in a canvas layer, there maybe something with that bugging it out and stopping the input. Did you say that it prints off there?

elder dawn
#

Heres a video of the issue with the debug log open

tiny flicker
#

Ah, I see....

#

Looks great by the way... When you're loading back in, do you have things that may get missed from the new changeout.

elder dawn
#

Regarding the cameras?

tiny flicker
#

Yeah

elder dawn
#

Everything seems to be in working order, print(camera.is_current()) returns true both before and after, the camera is enabled and the position is set correctly (looks messy in the video because I'm in the middle of a work around for this).
I tried setting all those values in the ready function as well and that had no effect

tiny flicker
#

Maybe even pause maybe

elder dawn
#

Ohhh

#

My timescale might be on 0 when I exit I just didnt notice, one second

#

Yup. It was 100% pausing, setting Engine.time_scale = 1 in the talent script fixed it

#

I figured it was going to be something little that I was overlooking I just couldn't figure out what it was after several days - thank you very much 😅