Can you show me the code near that line in the header? If you are using c++ then i would suggest launching the editor with visual studio so that when it crashes it goes to line of the problem with more information instead of just giving the crash report screen.
Hi… Thanks for reply…
/*
Can you show me the code near that line in the header? If you are using c++ then I would suggest launching the editor with the visual studio so that when it crashes it goes to the line of the problem with more information instead of just giving the crash report screen.
so if I start the first visual studio and then ue4. will it show me error line?
thanks for the tip.
*/
here is the code
You can define them but you can’t set it to values that can’t be computed at construction time. That’s why i moved the setting of the values to BeginPlay().
Can you tell me why? or just give me the link to read some information about this issue, because in c++ its possible to use something like this I think.
I just gave you the reason GetOwner() and GetWorld() i believe only exist during runtime, so when you are still creating the objects they don’t exist yet. Not to mention it’s good practice to do safety checks to see if they valid and you can’t do that in the .h (unless it’s a function).
I edited my example code to include some simple safety checks. This is just a guideline, but it’s not protecting against everything, if there is no player controller it would crash on GetWorld()->GetFirstPlayerController().
So I have to check every time if I have the null pointer for safety. is there any better way to check that?
So what about the blueprint. Do I have to use "if"s in blueprints too (for safety)?
Yes if you want to make sure your code is mostly protected, but usually people find a balance between the areas you do the checks, so in certain areas where you are pretty sure it has a valid value then you don’t use it. Doing safety checks for everything consumes developer time and game performance aswell if you use them a lot, although obviously its better to be slow than to crash. In the prototype i’m doing, since it’s not going to be played by anyone other than my team i use the minimum amount of checks to not crash, but if it was for someone to play it i would probably add a bit more checks, but i would still not test everything.