Ok, Im new to UE4 so lets put that out there ;o) I have been through all the code tutorials tho, and have been a programmer for many years.
Im using Visual Studio 2013 Express with UE4 4.2.1 on Windows 7 Professional.
I have created a ThirdPersonCode sample project.
I have created a UObject based controller class that I want to abstract some calculations that i dont want to do in a Blueprint. The idea is this contoller will be used inside the GameMode::Tick method to update a USTRUCT in my GameState class for use within Blueprints.
GameMode:
UCLASS(minimalapi)
class ASandboxGameMode : public AGameMode
{
GENERATED_UCLASS_BODY()
virtual void Tick(float deltaSeconds) OVERRIDE;
private:
/** */
UMyController* m_myController;
};
I define my GameStateClass and create one of these Controller objects in my GameMode constructor
GameStateClass = ASandboxGameState::StaticClass();
// Construct MyController for game
m_myController = NewObject<UMyController>();
Then I have my Tick method
void ASandboxGameMode::Tick(float deltaSeconds)
{
Super::Tick(deltaSeconds);
// Update Game State
ASandboxGameState* gameState = Cast<ASandboxGameState>(GameState);
if (NULL != gameState)
{
gameState->Data = m_myController->Data;
}
}
So far so good you might say … or not shrugs
Here are my issues that if you can help I would be very grateful
-
When I debug in the constructor I see
this(..."SandboxGameMode"_0)
but in Tick I seethis(..."BP_SkySphere_C")
as if there are two different instance of game mode calling different parts of the game mode methods? wierd … I never seem to see “SandboxGameMode”_0 in the Tick method or “BP_SkySphere_C” in the constructor. -
In the GameMode constructor my m_myController is constructed fine, in the Tick method it is undefined as in (Name=???, Number=???)? How can that be?
-
GameState is always NULL in the Tick method even tho my GameState constructor is called
-
In my GameState class the constuctor is called and properly executes, however even tho the GameState is always NULL in the Tick method, it steps into a GameState that is undefined (Name=??? …)
-
When I am debugging the
if (NULL != gameState)
line does not execute … the debugger just skips it
None of this makes any sense to me as far as standard C++ programming goes, but there may be some UE4 specifics that I am missing.
This also seems like simple basic stuff that should not have been a stumbling block for me for so long.
Hoping someone out there can point me in the right direction.
Thanks