Download

Why Has Unreal Continued to Crash for Years?

Funny story, a couple years ago, I tried to follow that ue4 course on udemy. Everything was going fine, until I got to the actual UE4 part of it. About probably halfway through the first unreal project in this course, my game crashed when I tried to compile. I don’t really remember much of what happened, but basically, I quit for some time.
So, a few months ago, I decided to try again. I used a new laptop, and decided to do this course again. Surely it won’t fail a second time, right? But it happened. Again. And I checked over my code thoroughly: it was fine. I installed the ue4 error pack thing, and it showed errors with the base ue4 code (none of my code was bringing up errors, it was from code I had never touched). Again, I quit for a while.
So today, I decided to try things again with my home computer (a third, separate computer). I was thinking, “there is no way this error would happen three times on three separate computers.” What do you know. It happened again. I can’t show my error message yet as I am currently downloading that package with my current computer, but once that gets installed I’ll post it up here. Again, nothing is wrong with my code (that I can see). I’ll put up my code here:


What is this? Does UE4 hate me? I mean, it’s the same thing since, like, three years ago. And obviously this isn’t happening to everybody. But why me? It’s not my computer, since I’ve used three different computers. The only similarity between the three times I’ve tried it is that I’ve tried it, me. I am convinced that Unreal Engine wants me to fail. I don’t know what I have done to deserve this fate. If anyone here can help, please do. I am in desperate need of assistance.

Code is trying to access 2 null things in its constructor.
Both GetOwner() and GetWorld() would return a null pointers, as neither of them would be assigned at this time.

If you move both to BeginPlay(), the component should have its owner assigned and GetWorld() should return an actual value.

Yeah, putting those in the UOpenDoor constructor are not recommended at all, which was the course at Udemy teaching that?

Also even if in the correct place, always test the return of a method which returns a pointer before moving ahead in code.



if (Owner = this->GetOwner())
{
   DefaultRotation = Owner->GetActorRotation();

   if (GetWorld())
   {
      if (GetWorld()->GetFirstPlayerController())
      {
          if (TriggeringObject = GetWorld()->GetFirstPlayerController()->GetPawn())
          {
          ... // do more stuff
          }
      }
   }
}


Once you have tested a piece of code you can place an else for each if () with a print message to see if ever you encounter a situation where the pointers are returning null_ptr and only after a lot of tests you can remove the ifs, since you know already that code will always run in a situation where the objects pre-exist. I would recommend leaving the tests thou, the number of instructions used are not a performance issue and the compiler will likely optimize this under the hood.

Oh, wow, that seemed to work. I want to refuse to believe that I made the same mistake each time I attempted this, but knowing me I probably did. Well, thanks, you guys saved me. And I’m relieved to know that UE4 doesn’t hate my guts (as far as I know).