Hello guys. I am new to coding under unreal engine. I’m writing logic for the hexagonal grid. Split functions into different classes: HexManager inherited from UObject, contains functions that transfer coordinates from one coordinate system to another, HexLevel contains a level with information about cells, and so on. In HexBoard, all logic is connected with pointers and it looks like this:
UCLASS()
class FIRSTDUNGEON_API AHexBoard : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AHexBoard();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Hex property")
EMapKind MapKind;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hex property")
UHexManager* HexManager;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Hex property")
UHexLevelManager* HexLevelManager;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HexBoard")
int32 width=3;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HexBoard")
int32 height=3;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HexBoard")
TArray<FRowEncapsulate> HexField;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float HexSize=103.f;
UFUNCTION(BlueprintCallable)
void SetFieldSize();
UFUNCTION(BlueprintCallable, BlueprintPure)
TArray<FVector> GetHexPositions() const;
UFUNCTION(BlueprintCallable, BlueprintPure)
FVector GetHexPosition(int32 Q, int32 R) const;
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
Initialization is as follows:
AHexBoard::AHexBoard()
{
PrimaryActorTick.bCanEverTick = true;
MapKind=EMapKind::Reactangle;
HexManager = NewObject<UHexManager>();
UE_LOG(LogTemp, Error, TEXT("%s is hexmanager name"), *HexManager->GetName());
HexLevelManager = NewObject<UHexLevelManager>();
}
I get a pointer to HexBoard as follows, and even find something.
But when I try to use HexManager, I get Accessed None trying to read. Also, you can see on the screen that for some reason nothing is contained in the index on HexManager.
What am I doing wrong and, if in the unreal engine so is not accepted, how best to proceed with the preservation of common logic?