Download

Access problem with DataTable

Dear experts,

I am following this tutorial Legacy/C++ Inventory | UE4 Community Wiki
and when I am overlapping with an item to collect the engine crashes (the editor I mean).

I set a break point and it is telling me that my ItemDB is a nullptr, am I correct?

What am I doing wrong? I can see the ItemDB in my folder “…Content\Data”
The setup in the editor looks good to me too:

Any ideas on this?

Thank you, Peter

The error “this was nullptr” usually means that, when you are calling the GetItemDB function on your GameState variable, the GameState variable is set to nullptr.

Can you post the code that calls the GetItemDB function?

Hello,

I debugged it and the add Item method is called in the player controller and it looks like this:

I am not sure how to interpret the AGameState having <struct at NULL>

  • is there a problem with MyGameState? But how could I fix that?

Also in MyGameState.h I have ItemDB as “protected” but that should be
okay I think:


UCLASS()
class BANKOSMAZE_API AMyGameState : public AGameState
{
GENERATED_BODY()

public:
AMyGameState();

UDataTable* GetItemDB() const;

protected:
UPROPERTY(EditDefaultsOnly)
UDataTable* ItemDB;
};

Hi I figured it out. I had a problem GameState and GameModeBase.
So either “GameModeBase & GameStateBase” or “GameMode & GameState”.
Now I do not get the error anymore.
Best regards, Peter