Why does my game crash after running fine?

ForceInit does something with FMemory, which I am not familiar with. My guess is that it loads something into memory (the FHitResult struct) and sets the initial time variable in the FHitResult struct to 1. As far as I know, you can technically use it without ForceInit, but that’s pretty much all I know about it.

Anyway, as for your problem, if the rayfather variable is a scenecomponent and it happens to crash on that line, my guess is that it is NULL at the point you are calling it. I know you mention that it isn’t being destroyed anywhere, but it could very well be that the variable is not being initialized properly. Perhaps you should put a NULL test in there. Also, where are you finding DropDepth? I have looked through the classes, but I cannot find that variable anywhere in the sourcecode, let alone in scenecomponent or any of the classes it’s based on.

It seems you have the null test there, so I am confused as well. Would it be possible to share the involved classes somewhere so I can have a better look? If you don’t want to share it here, you can also send it to my gmail (right there in my account).

So I’m adding a teleport mechanic to the Shooter game in Unreal Engine.

When I play the game, I can teleport correctly and it seems to be running fine. But after maybe two minutes, all of a sudden it crashes when I try to teleport. Keep in mind, this is after teleporting all over just fine. The call stack from the crash points me to either a FHitResult or a line with the expression: rayFather->fDropDepth

Right now I have the following:

FHitResult newHitHolder(ForceInit);

FVector vecLowestDropDir;

vecLowestDropDir = FVector(ForceInit);

vecLowestDropDir = FVector(0, 0, -rayFather->fDropDepth); /*This is the line that crashed it most recently!*/

FVector vecPointEnd = vecOrigin + (vecLowestDropDir * rayFather->fDropDepth);

I should also mention that I have no idea what ForceInit does or is and can’t find any information on in anywhere but I see it being used all over in other people’s code so I gave it a try. Those first four lines used to just read:

FHitResult newHitHolder;

FVector vecLowestDropDir = FVector(0, 0, -rayFather->fDropDepth);

I’ve used other FHitResults in places without any ForceInit and it works fine! And I use FVectors all over without ForceInit with no problems! Other things that might be helpful:
-The code given runs several times in a for loop whenever a teleport is being aimed.
-The code provided runs from a UDataAsset.
-The data assets are basically two different nodes that work as a head and a tail to find the most desirable teleport spots along a ray. They are managed by an USceneComponent that attaches to the player controller.
-rayFather refers to the scene component. The data assets refer to the scene component to get the desired drop depth. So rayFather->fDropDepth should retrieve the scene component’s fDropDepth. And it does! Because teleporting works! Until it doesn’t.
-The scene component and data assets are created and linked at the start of the game and neither of them are ever being destroyed.

Any ideas? I’ve been battling this for a good amount of time now and I’m completely out of ideas. I feel like knowing what ForceInit actually does might help but something tells me the problem is more involved than that…

I do a null test right before that section:

    print("rayFather is null!"); // This is a macro that uses on-screen debug messages

That IS a correct null test is it not?

Also, I should have been clearer in the original post. fDropDepth is my own variable. It is a member of rayFather. It’s public and non-const as well. In the BeginPlay method fDropDepth is set to MyParentalCharacter’s fTeleportRange / 2.

I also had it log the value of rayFather->fDropDepth to the screen. It logged as 2000.0f each time it was referenced. Until it crashes.

The exact message it gives me is:

Access violation - code c0000005 (first/second chance not available)

From everything I can see online, this is supposedly a null pointer error. But I test it for null… And it’s not… Unless I’m testing it wrong? Is there a way to make the game pause and step through the code as it runs it? That would be so much better than crashing the whole thing each time. I’ve tried debugging with break points but I’m not sure how that interfaces with Unreal and can’t seem to get it to do anything. Does visual studio have to be in a certain configuration?

Would be nice if you can share a bit more Code around it, would be nice to know where you Pull the Obj from and if you Cast it correctly. Aswell as the full Stacktrace. You can do a if(rayFather) around your whole block of Code.