Im very confused.
I have different types of batallions. Each batallion has its own specific type. Spearmen, swordsmen etc…
Spearmen has different attack than swordsmen.
In blueprints this is very easy to do. I get the Row using the node in the image. And quickly get all the values i need.
But in C++ im very confused on how to do this, even though i watched a bunch of tutorials.
For example this one, which is very good. But super confusing and too complicated.
Eventually things start falling a part and im unable to make it work.
Is there a step by step tutorial on how to do this?
What i need to do is:
1- Create a C++ struct UnitData with all the properties needed, Attack, defense etc…
2- When the game starts assign a unit type to my Actor, on spawn (if it is being spawned). For example, spearmen.
3- Need to get all the variables of the UnitData struct, row “spearmen” out of it, and into my struct inside my actor.
4- Need to be able to access these specific variables inside each struct in each actor. So that when im fighting i know what my attack and defense is.
Issue 1: I dont understand when and how should my struct array or TMap be initialized. When do i create the list of different unit types and their data? At begin play?
Issue 2: I asked chatgpt and it tells me that i can simply create a struct and that i dont need datatables. So according to chatgpt, i can make an array at the start that initializes every type of unit, with its own defense/attack variables etc… But must be done only once, and store them in a TMap<FString, Struct> where the FString is the name of the unit type, and the struct is the corresponding initialized struct of the unit type.
2.1 Where do i do this so that it only happens once? Chat gpt made it in all spawned units, with one if statement to check if its already initialized. Which it doesnt look right.
2.2 After having initialized them how do i store them in each corresponding struct in each unit? Should i do this when ? At begin play?
I created the struct, down below. How can i create a list of them for each specific unit type? Then store them in each corresponding unit?
#pragma once
#include "CoreMinimal.h"
#include "UnitDataStruct.generated.h"
USTRUCT(BlueprintType)
struct K2K_TEST_CPP_API FUnitDataStruct
{
public:
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int Health;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int Attack;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int Defense;
FUnitDataStruct();
~FUnitDataStruct();
};