Hey everyone. Right now I’m trying to build a simple game of bowling and I’ve been running into this issue which I will explain now. So I have some box collisions to detect if a pin has been knocked over (class is APinDetector) within a TArray. Each PinDetector has a variable called PinKnocked which stores the knocked over pin as an Actor. The issue arises when I’m looping through each PinDetector within the TArray, and calling PinKnocked->IsA(AActor::StaticClass) which then crashes UE4 for me. So I wouldn’t mind a quick run down of how and when to use IsA() which could help me solve my issue. Thanks!
You getting crash most likely because PinKnocked is null or object it was pointing to was destroyed and pointer is invalid (pointing to unaccessable memory address), if you call on nulll or invalid pointer you gonna have a crash, so do 2 things. Where ever you use that IsA check do check if PinKnocked is not null. Don’t worry if first condition fails the 2nd won’t be checked so you wont have a crash
PinKnocked && PinKnocked->IsA(AActor::StaticClass)
But this won’t prerevent crash for invalid as pointer points somewhere so it’s not null, nativly there is no way to check if pointer is valid, so pointers need to be tracked and UE4 has such menanisms. In case of UObject is very easy, all you need to do is add UPROPERTY() before varable, it adds varable to reflection system which keep track of it, if object that is pointing to is destroyed, reflection systems nulls all properties that it was pointing to. Keep in mind this works only on UObjects (which means also on actors).
Please post your output log at time of crash.
Just tested it and it seems to have solved the issue. Thanks!