Getting player instances

If you were to test this now, you would see that a value gets created in our pause menu, but the value is 0. This is not correct because our character is supposed to start with 100 HP according to the character's current stats:

Getting player instances

The problem occurs because the Field Player that accesses the pause menu never assigns any of our character data to Character Target. We can easily set the proper character target in Blueprint, but we won't be able to assign any of the character data without exposing our added party members to Blueprint. So, we must first head into RPGGameInstance.h and allow the exposure of our current game data to a Game Data category of Blueprint in the UProperty parameters:

UPROPERTY( EditDefaultsOnly, BlueprintReadOnly, Category = "Game Data" )

Your RPGGameInstance.h file should now look like this:

#pragma once

#include "Engine/GameInstance.h"
#include "GameCharacter.h"

#include "RPGGameInstance.generated.h"

/**
 * 
 */
UCLASS()
class RPG_API URPGGameInstance : public UGameInstance
{
  GENERATED_BODY()

  URPGGameInstance( const class FObjectInitializer& ObjectInitializer );

public:
  UPROPERTY( EditDefaultsOnly, BlueprintReadOnly, Category = "Game Data" )
  TArray<UGameCharacter*> PartyMembers;

protected:
  bool isInitialized;

public:
  void Init();
  void PrepareReset();
};

Once you have saved and compiled your code, you should be able to properly call any created and added party members in Blueprint, and so we should have read access via the Field Player Blueprint.

Now, you can navigate back to the Field Player Blueprint and have it get RPGGameInstance by creating the Get Game Instance function node located under Game:

Getting player instances

Have the Return Value of Get Game Instance cast to RPGGameInstance, which is located under Utilities | Casting | RPGGameInstance. Now that you've got an instance of the RPGGameInstance class, you can have the instance refer to the TArray of Party Members, which holds all your party members, by navigating to the category that you have created for it in GameData under Variables:

Getting player instances

Here, we will need to point to the element of the array that holds our soldier character's stats, which is our first element or 0 index of the array, by linking the Party Members array to a GET function, which can be found by going to Utilities | Array:

Getting player instances

Note

For additional characters, you will need to link another GET function to Party Members and have the GET function point to the element of the array that will point to any other characters (for instance, if you had a healer that is in index 1, your second GET function would simply list its index as 1 instead of 0 to pull from the healer's stats). For now, we are just going to focus on the soldier's stats, but you will want to get stats for every character in your party.

Lastly, once we have finished casting RPGGameInstance, we will need to set the Character Target, which we created in the pause menu, to our Party Members. To do this, right-click on your Event Graph to create a new action, but uncheck Context Sensitive because we are looking for variables that have been declared in a different class (Pause_Main). If you navigate to Class | Pause Main, you will find Set Character Target:

Getting player instances

Here, simply link Character Target to the out pin of your GET function:

Getting player instances

Then, set Character Target so that it is triggered after RPGGameInstance is cast:

Getting player instances
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.71.21