Unreal Crashing when pressing Play

Hey,

After adding code the code that is in the video, I seem to have a problem with Unreal crashing when I press play.
It is worth noting that just before I added the code, I transferred a copy of the projects files (all of them), to a new computer where I had Unreal recreate the Visual Studio files, and rebuild the solution.

I’ve looked at the other discussions here and other forums, but none seem to work for me.
Anyone able to help me out?

EDIT: I made Unreal remake the visual studio project files, and tried debugging.
I get an exception thrown:

I’ve tried poking around, seeing if I can find my error or other people who stumble upon the same issue, but so far no luck.
For those curious, here is the exception in text:
Exception thrown at 0x00007FF913B11EEC (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000330

Access violation means you try to access something that doesn’t exist. I’m guessing PressurePlate is null.

You’ll get Access violation trying to access an address on a null. So you get that with pointer and array usually if there’s nothing where you try to access. Access violation means that you’re trying to access a location that the operation system hasn’t assign to your program. So you don’t have the permission to access it.

Tell me if you want more explication

Hope it helps!

Thanks for the explanation, it is understandable :slight_smile:
Although, PressurePlate has been defined in OpenDoor.h as:
OpenDoorh
I can even press “Go to definition” when right clicking PressurePlate.

I think I’ve followed all the videos accordingly, but is it possible I’m still missing something?
I also tried running Visual Studio as an admin, and opening the solution in VS (considering you wrote that I literally did not have access), but didn’t seem to help either.

I also checked the two others, (IsOverLappingActor and ActorThatOpens) and they both also have a definition.

Definition and Assignation are different. You’ve define the variable, but if you haven’t assigned a value to it, it’ll be null by default.

ATriggerVolume* PressurePlate; //Definition

PressurePlate = //Assignation

Cheers, although comparing my code to the code that takes place at the end of the video that is in question, there is no difference.

They do not either assign PressurePlate, they only define it.
Am I doing something wrong by even trying to play the game at this point?

It’s probably the case. Ben does that sometime, setting up everything over a couple of video and then making it playable. If he doesn’t play the game in the video, it’s probably because the code is not fully playable. As it stand anyway, unless you assign values to the PressurePlate, it won’t work. He’ll probably do it in a couple video!

Thanks for all the help! :slight_smile:
Can I ask what I should do now? I tried to retrace to the previous video and work myself from up there, but still at a loss.
Ben seems to be able to play at the end of this video actually, whilst I still get the crash and error.

Update!
I went to my “original” laptop and redid everything in this video.
I did nothing new, PressurePlate is still not defined, and yet it still works now somehow.

If anyone stumbles across this problem and unsure of what to do, I suggest rolling back to a previous version and redoing the code in this video.

1 Like

Hey guys!

Carl is correct - you are crashing because you are trying to call a method on a pointer to an object that doesn’t exist.

The first issue I spotted with the code is that ATriggerValue* PressurePlate needs to have the UPROPERTY(EditAnywhere) macro on the line above it. This allows you assign a reference to the object from the editor itself.

Next, you probably just need to set the reference to the pressure plate in your world from the Door_BP details panel. Ben covers this in lecture 72 around the 7:45 mark, but here’s what you need to set:
image

On a side note, generally something in the form of <type> VariableName is referred to as a declaration, and setting the variable to a value is an assignment. You could argue that something like int x = 0 is a declaration, a definition, and an assignment all in one statement (msdn has a pretty good explanation: https://msdn.microsoft.com/en-us/library/0e5kx78b.aspx). Also if you right-click the variable PressurePlate and select either “Go To Definition” or “Go To Declaration” it will take you to the same place. However, this is not the case with functions (try the same context menu options on a function to see what I mean).

Anyway, the statement ATriggerVolume* PressurePlate just declares a pointer to ATriggerVolume named PressurePlate, whereas a line like PressurePlate = new ATriggerVolume; actually creates a new instance of ATriggerVolume and assigns it to PressurePlate (C++11 people don’t shoot me, it’s just an example for simplicity sake ;)). However, in our case, we’ve already created an instance of the PressurePlate in our world, so we just need to assign it in the editor as shown above.

Lastly, it’s always good to check pointers for validity before calling a method on them i.e. if (PressurePlate != nullptr) { // Do stuff with PressurePlate... } which can be simplified to if (PressurePlate) { // ... }.

Hope that helps!

1 Like

So it does :slight_smile:
Well explained and thank you very much!

I’ll be sure to assign it as shown in the image, as well as give it an EditAnywhere UE property.

Again, thank you!

Privacy & Terms