Ok. So I know this title is a little weird, but let me explain. So I tried using a casting method to cast from Character to a derivative of Character. I kept getting a crash due to failed casting, so I removed it, and still getting the same crash. So I need to know how to “update” my project to fix this, because I tried compiling it and it still thinks theres an issue.
void AMyDoor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
AMyPlayerCharacter* Character = NewObject<AMyPlayerCharacter>(this);
UGameplayStatics::GetPlayerPawn(Character, 0);
FVector ThisPosition = GetActorLocation();
FVector PlayerPosition = Character->GetActorLocation();
float Dist = FVector::Dist(PlayerPosition, ThisPosition);
if (Dist <= BuyDistance)
{
Character->bIsNearDoor = true;
}
else
{
Character->bIsNearDoor = false;
}
}
Hi AWPlays49,
I’d love to help, but I’m not yet clear on what exactly the problem is. The trick with crashes is that they usually include a stack trace that helps locate the problem. Without that, I suspect we’ll be able to provide only limited assistance. Can you reproduce the problem and post the stack trace that appears in the crash window?
As for your casting problem, I’m guessing that the object you’re trying to cast isn’t the one you mean. Specifically, I suspect you may be trying to cast an object that isn’t derived from ACharacter. Can you post the code you were using before so that I can try to see what might have been going wrong?
Also, since this problem is occurring in your AMyDoor class, can you give a little more information about that class? In particular, I’d like to know what class(es) it derives from as it descends from the Unreal classes.
Lastly, looking at the function you’ve posted, it looks like you’ll be spawning a new instance of the AMyPlayerCharacter class every time a AMyDoor ticks. I don’t know your tick settings, but I suspect this could create a rather large number of AMyPlayerCharacters when you don’t really need to. (It may also be destroying them again when they are no longer referenced.) This could certainly cause performance issues down the road and might even cause other problems too. Can you explain a little about what you’re trying to do in that function?
Thanks!