I have been working on this FNAF fan game for a couple of months now, and Im about to hit the 3rd stage of development. However, when making the last character and its AI, I ran into a bug.
An int32 Variable called “Stage” is causing problems and crashing the game every restart.
int32 Stage;
It is used in this BTTask:
void UBTTask_FoxyCountdown::TimerCompleted(UBehaviorTreeComponent& OwnerComp) const
{
Foxy->IncreaseStage();
if (Foxy->GetStage() >= 5)
{
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
}
FinishLatentTask(OwnerComp, EBTNodeResult::InProgress);
}
In PiratesCove:
if (Foxy && Mesh2)
{
if (Foxy->GetStage() >= 2)
And in the class itself: `
void AFoxy::IncreaseStage()
{
Stage++;
UE_LOG(LogTemp, Log, TEXT("Increased Foxy's stage to: %d"), Stage);
if (Stage < 5)
{
TeleportTo(Positions[Stage], Rotations[Stage]);
}
}
void AFoxy::ResetStage()
{
Stage = 0;
SetActorLocation(FVector{0, 0, -100});
}
int32 AFoxy::GetStage() const
{
return Stage;
}
Somewhere here, is crashing the game, and after some debugging(UE_LOGS that told me the number, and removing stage related code and it no longer crashing), it’s Stage Being Used. This is strange because I have never seen an int32 get a usual pointer crash. One thing I noticed is that Stage somehow gets set to this specific number after a while: 1983924. And it is this number Every time without fail. Here is the level restart code:
UNightInstance* Instance = Cast<UNightInstance>(GetGameInstance());
if (Instance)
{
Instance->IncreaseNight();
UE_LOG(LogTemp, Log, TEXT("NightNumber increased to: %d"), Instance->NightNumber);
if (Instance->NightNumber >= 6)
{
Instance->ResetNightNumber();
UE_LOG(LogTemp, Log, TEXT("NightNumber reset to: %d"), Instance->NightNumber);
}
UGameplayStatics::OpenLevel(GetWorld(), DecidingLevel);
When it opens the level to decide if you want to go to the next map, apparently Foxy’s Behavior Tree is still being used, and because its not in the world, its causing crashes??????? Why is it activating if ONLY THE PLAYER is in the world.
I’ve tried everything, and this is extremely demoralizing. Here is some answers to questions I have tried.
Please help, I’ve been stuck for so long
I tried:
1: I initialized the stage to 0 at begin play.
2: I check if everything is valid 3: I have a delay after the level so everything can load in.
3: Went to another level, waiting a while, and went to it.
No crashes after level restart.
Crash Log:
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000069 UnrealEditor_Fnaftsor_1905!AFoxy::IncreaseStage() [C:UsersAskariDocumentsUnreal ProjectsFnaf-TOSRSourceFnaftsorAnimatronicFoxy.cpp:26] UnrealEditor_Fnaftsor_1905!TBaseFunctorDelegateInstance<void __cdecl(void),FNotThreadSafeNotCheckedDelegateUserPolicy,<lambda_7b55c7ba8662fcfaf661ffc30e516b98> >::Execute() [C:Program FilesEpic GamesUE_5.3EngineSourceRuntimeCorePublicDelegatesDelegateInstancesImpl.h:862]
The Line In particular: Stage++
I also get the same error message from time to time, but instead of Stage++ its TeleportTo
I think it has to do with stage because when I remove code related to decreasing or increasing it(Or just getting it), the crashes stop.
Shady Shade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.