GameStates and ThirdPersonView

I have three GameStates active: HudState, RenderState (which created the level, players etc.) and the InputState (which handles user input).



First I had a FirstPersonHandler in the InputState, which worked fine. Now I want to change this to a ThirdPersonHandler, but this needs an object to follow. This object is player, but the player is only defined in the RenderState.



How would I go about attaching the player to the ThirdPersonHandler? E.g. how do I transfer a reference to the player object from the RenderState to the InputState?



Thanks a lot for helping out!

I like duenez's solution best. In the future, the player object may also be referenced in the HudState or any other State that I'm going to create.



Yet, what would be the best place to initialize the player model and keep it? I have a Start class that initializes the GameStates and a Game class that manages the standardGame itself.

I usually make the player a public field of the GameState and use the GameStateManager to access those fields-

something like:

GameStateManager.getInstance().getChild("RenderGameState").getPlayer();



But it doesn't seem very nice i think :confused:

One problem with this is, that the GameStates need to be created in the correct order, or the player will be null.


Another option is to keep your players references outside of any Gamestates, and just attach them where they need to be attached, and that's it.