[Solved] New to jme3, and experiencing weird behavior

Hello all,
I am quite new to jme3, although I read all the beginner tutorials and some advanced ones.
I started making a new game, (Github Link) but I ran into some problems:
I wanted to implement saving and loading right at the start, and use the loading method without loading the save file to re-init the game when I go back to the menu and into the game again. But then the camera acts very weird (turning sideways) and if I’m coming from the main menu, I can’t move my character. Not that when I do a fresh start and go into the game, everything works as expected.
Please tell me if you can’t understand what I’m saying, I will try to explain it a little better then.

Robbi Blechdose

You’re basically just reporting an anecdote, how is anybody supposed to help you based on this post? :chimpanzee_smile:


If I load a game or go from the first game init from the menu and back to the game (method loadGame in GameState), the camera turns sideways.
Also, I can’t control my player.

Robbi Blechdose

How you are “loading” your game ?
And, what do you mean with the “camera acts very weird” ?
If you think its hard to explain, try to post some videos, people will not download your entire game code compile and find your bugs for you, you will need to explain what you want and what you do think its wrong.
Also, an tip for you, this kind of problems from new jmonken devs are normally related with the knowledge on how game states works, try to read a bit more about game states and do some debugs, I have a felling you will found out what is wrong doing this.
Obs: @normen, I laugh a lot on your comment :slight_smile: .

Thank you for your answer. :grinning:
I will read a bit on game states. :smile:
The camera shoudl just move up/down and turn left/right. However, it also turns around the view axis.
EDIT: Strange, I can’t get the bug ATM… But then there’s another one: The first-person cam, which should be locked on the player position, now always uses the viewing position of the 3rd-person cam as new position…
EDIT²: It seems that the bug only appears when loading the game…

Robbi Blechdose

I’m holding a piece of string. Can you tell me how long it is?

(ie: we can’t debug code we can’t see and none of us have ever experienced your problems. Boil things down to a simple test case that exhibits the issue and post that code.)

You can see the code, I linked to my github repo…
EDIT: Right, seems like I’m dumb. I didn’t even try to replicate the conditions for loading the game with those for re-initializing it from the menu. Now it’s the same state, but the player is locked in position,
and I get a nullpointer for line 220 on my FirstPersonCam. :rage:
The firstPersonCam is a copy of the FlyByCam, and nullpointer is on rotateCamera(value, cam.getLeft());.
EDIT: Here is the changed code for the loading method:

public void loadGame()

        startChunk = new Chunk(getAssetManager(), rootNode, camera, bulletAppState, null);
        if(player == null)
        player = new Player();
        player = (Player) SaveGame.loadGame("Steam/Saves/", "Player.sav");
        if(player == null)
        player.init(camera, getAssetManager(), bulletAppState);

Robbi Blechdose

You know that when you create an empty project it assign default behavior for the camera and keys right ?
So you need to disable it in order to make your custom behavior to work…

I am using a FirstPersonCamera and ThirdPersonCamera which are basically copies of FlyByCam and ChaseCam. But what I described is the default behaviour, isn’t it?
Also, I changed some code (should be on git any minute now) and now the problem only occurs when loading a second time…
Also, it doesn’t apply the player position after load, although it saves and loads correctly.
EDIT: This is so strange. Now the camera problem appears when I come from the menu as well as when I load.
And if I come from the menu, the player is locked in position. I just don’t get what’s wrong. :sob:

Robbi Blechdose

Note: if you are not using the default flyByCam (ie: you never set enabled to true) then it’s way better just to remove it or not include it in the first place. Search the forum for “remove FlyCamAppState”

Found a thread.
I added this line to the init method of my GenericGameState:
stateManager.detach(stateManager.getState(FlyCamAppState.class) ) );
But the problem still persits…

Robbi Blechdose

It’s very hard for some of us to go through someone’s entire project to find a problem. It’s way better if you can reduce your issue down to a simple test case. The added benefit is that 99% of the time you find the problem yourself when doing that.

I don’t know how to reduce it to a simple test case because there’s practically nothing in the game. :stuck_out_tongue:

Robbi Blechdose

Well, if you have it reduced down to a simple one class test that exhibits the issue then go ahead and paste it directly into a code block here. If you don’t have it reduced down that far then try building one up from a simple one class test case.

…then when that works (or not) you’ll have something to go on.

The thing is,
I can’t make my own copies of Cameras with just one class,
and I generally wouldn’t know how to do that. Sorry.
But I found out something: I think the problem has to do with the flyByCam.

Robbi Blechdose

But if you removed the FlyCamAppState like I told you then the flyByCam is essentially doing nothing.

Is that necessary for making the bug happen? Sounds like you don’t even know.

I removed the flyByCam now,
I had the line in the wrong place. :smile:
What would cause the bug if it also happened with just flyByCam? Because it did, in a small test phase.

Robbi Blechdose

That would depend on what that code looks like.

I just replaced the firstPersonCam in my code with a FlyByCam.
But because I needed the changed controls, I reverted that change.

Robbi Blechdose

SHOW ME THE CODE. Maybe I was hinting too much.