Answer the question
In order to leave comments, you need to log in
Why is nested array in UE c++ empty?
There is a structure:
#pragma once
#include "CoreMinimal.h"
#include "FColumnBoard.h"
#include "FRowBoard.generated.h"
USTRUCT(BlueprintType)
struct FRowBoard
{
GENERATED_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TArray<FColumnBoard> columns;
};
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FRowBoard.h"
#include "Board.generated.h"
UCLASS()
class CHESS_API ABoard : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABoard();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class UStaticMeshComponent* board;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TArray<FRowBoard> rows;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UClass* pawnWhite;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UClass* pawnBlack;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMesh* cube;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UMaterialInterface* color;
};
PrimaryActorTick.bCanEverTick = true;
this->board = this->CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BoardStaticMesh"));
this->SetRootComponent(this->board);
const int32 sizeColumn = 118.0f;
FVector boundsColumn = FVector(sizeColumn * 0.02f, sizeColumn * 0.02f, 0.01f);
for (int32 i = 0; i < 8; ++i) {
FRowBoard row;
FVector forwardVector = (FVector::ForwardVector * i - FVector::ForwardVector * 4) * sizeColumn * 2 + FVector::ForwardVector * sizeColumn;
for (int32 j = 0; j < 8; ++j) {
FColumnBoard column;
FVector rightOffset = (FVector::RightVector * j - FVector::RightVector * 4) * sizeColumn * 2 + FVector::RightVector * sizeColumn;
FString name = TEXT("col_");
name.AppendInt(i + 1);
name.AppendInt(j + 1);
auto col = this->CreateDefaultSubobject<UStaticMeshComponent>(FName(name));
col->SetupAttachment(this->board);
col->SetRelativeScale3D(boundsColumn);
col->SetStaticMesh(this->cube);
col->SetMaterial(0, this->color);
col->SetRelativeLocation(rightOffset + forwardVector);
col->SetVisibleFlag(false);
column.column = col;
column.location = rightOffset + forwardVector;
row.columns.Add(column);
}
this->rows.Add(row);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question