Why does my game crash after running fine?
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:
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:
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...
asked Jul 20 '17 at 12:40 AM in C++ Programming
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.
answered Jul 20 '17 at 01:49 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here