Edit : I haven’t found the solution to the problem, but I just made a work around by having the soldier class figure out the level block he is on with a raycast on his beginplay. It seem like the pointer generated by GetAllActorsOfClass seem to provoke this bug, I do not know why.
Feel free to delete this post. Thank you for your help eblade.
I am trying to set the value of an actor that is get in the begin play of a game mode script. The game mode parse through all the level block and find the one that is tag as the starting position. Then it spawn the player character on it. That portion work. What doesn’t work is I want to also set properties on the level block that was found and the value of the object always come back to it default value of null and false (the variable UnitOnBlock and test).
Nowhere in my code do these value should be reset the next frame. It is true I could set the value a bit later, but I find it weird that I need to do such work around in the first place.
Here is the code sample:
void ATBTacticalGameMode::BeginPlay()
{
Super::BeginPlay();
//Setup TilePathFinder
TilePathFinder = NewObject<UTilePathFinder>(GetTransientPackage(), UTilePathFinder::StaticClass());
TArray<AActor*> AllActors;
const UWorld* WorldPtr = GEditor->GetEditorWorldContext().World();
UGameplayStatics::GetAllActorsOfClass(WorldPtr,AActor::StaticClass(),AllActors);
if (WorldPtr && AllActors.Num() > 0)
{
UKismetSystemLibrary::FlushPersistentDebugLines(AllActors[0]);
for (int i=0; i<AllActors.Num(); i++)
{
if (ALevelBlock* LevelBlockPtr = Cast<ALevelBlock>(AllActors[i]))
{
if (LevelBlockPtr->bIsStartingPosition)
{
TArray<UNodePath*> AllNodePaths;
LevelBlockPtr->GetComponents<UNodePath>(AllNodePaths);
UNodePath* StartingNodePtr = AllNodePaths[LevelBlockPtr->NodePathIndex];
if (SoldierClass)
{
ASoldier* SoldierPtr = GetWorld()->SpawnActor<ASoldier>(SoldierClass, StartingNodePtr->GetComponentLocation() + FVector(0.0f,0.0f,88.0f), FRotator(0.0f, 90.0f, 0.0f));
SoldierPtr->TileMovementComponent->LocatedNodePath = StartingNodePtr;
LevelBlockPtr->UnitOnBlock = SoldierPtr; //get unnasign the next frame
LevelBlockPtr->test = true; //get unnasign the next frame
}
}
}
}
}
bInitialized = true;
}