Hi
I’am creating a rpg game where i create a array with 9 slots, for that i use a TArray<FVector> Here is the code
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Misc)
TArray<FVector> aLocationGrid;
ABattleArena::ABattleArena()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
ConstructorHelpers::FObjectFinder<UBlueprint> itemBlueprint(TEXT("/Game/Blueprints/BattleGrid_BP"));
if (itemBlueprint.Object)
{
uBattleGridBP = (UClass*)itemBlueprint.Object->GeneratedClass;
}
aLocationGrid.Add(FVector(GetActorLocation().X + 820.0f, GetActorLocation().Y - 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X + 820.0f, GetActorLocation().Y, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X + 820.0f, GetActorLocation().Y + 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X, GetActorLocation().Y - 830.0f, GetActorLocation().Z));
aLocationGrid.Add(GetActorLocation());
aLocationGrid.Add(FVector(GetActorLocation().X, GetActorLocation().Y + 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X - 820.0f, GetActorLocation().Y - 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X - 820.0f, GetActorLocation().Y, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X - 820.0f, GetActorLocation().Y + 830.0f, GetActorLocation().Z));
}
void ABattleArena::BeginPlay()
{
Super::BeginPlay();
UWorld* const world = GetWorld();
aLocationGrid.Add(FVector(GetActorLocation().X + 820.0f, GetActorLocation().Y - 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X + 820.0f, GetActorLocation().Y, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X + 820.0f, GetActorLocation().Y + 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X, GetActorLocation().Y - 830.0f, GetActorLocation().Z));
aLocationGrid.Add(GetActorLocation());
aLocationGrid.Add(FVector(GetActorLocation().X, GetActorLocation().Y + 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X - 820.0f, GetActorLocation().Y - 830.0f, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X - 820.0f, GetActorLocation().Y, GetActorLocation().Z));
aLocationGrid.Add(FVector(GetActorLocation().X - 820.0f, GetActorLocation().Y + 830.0f, GetActorLocation().Z));
if (world)
{
for (int i = 0; i < aLocationGrid.Num(); ++i)
{
ABattleGrid* temp = Cast<ABattleGrid>(world->SpawnActor<ABattleGrid>(uBattleGridBP, aLocationGrid*, GetActorRotation()));
temp->iIdGrid = i;
temp->eGridElement = EElement::VE_Fire;
aBattleGrids.Add(temp);
}
}
}
//Set 7 for debug
FVector ABattleArena::GetGridLocation(int32 id)
{
return aLocationGrid[7];
}
You may wonder why I initialize 2 two times the aLocationGrid. This is where i got an issue. If I only initialize aLocationGrid array in ABattleArena constructor the BeginPlay can’t create the arena event there is value in this array the UE_LOG shows the value in log, but I try to put this value one by one , the programs crash !
If I only initialize in BeginPlay, the function GetGridLocation crashs (calls from Blueprint) because it’s can return any value of the aLocation event the programs prints the array got value in it (9)…
More stange, this class ABattleArena is use from a gameMode class. Every time I open Unreal Engine, the game crashs, but I modify the name of variable for Battle Arena in GameMode class. Build and launch, it’s now work without crashing. I have to do this process every time …
Can someone help me?
Thanks !
Update : I watch the log and it’s seems like we can’t generate actor on collision with other actor
[2016.05.08-13.02.34:070] 94]LogSpawn:Warning: SpawnActor failed because of collision at the spawn location [X=-820.000 Y=830.000 Z=117.500] for [GameRPGCharacter_BP_C]
[2016.05.08-13.02.34:071] 94]LogSpawn:Warning: SpawnActor failed because the spawned actor /Game/Maps/UEDPIE_0_BattleMap.BattleMap:PersistentLevel.GameRPGCharacter_BP_C_13 IsPendingKill