Hi all, I created a Character class and use it for my game. For some reason I get the above error when building and it crashes unreal. I believe it has something to do with the line of code here: GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &ATutorialCharacter::OnBeginOverlap);
When I comment this out, compile build then put it back in it seems to work fine for some reason. I could keep doing that but I would like to know how to fix this. I also cant seem to get my settings to save but thats for a different post I think! lol
Maybe it has something to do with ATutorialCharacter::OnBeginOverlap signature.
Are you sure it’s right? It must correspond to delegate OnComponentBeginOverlap and look something like this:
Sure, here is the Begin play function which is where the code that is causing the error is.
void ATutorialCharacter::BeginPlay()
{
Super::BeginPlay();
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &ATutorialCharacter::OnBeginOverlap);
if (Player_Power_Widget_Class != nullptr) {
Player_Power_Widget = CreateWidget(GetWorld(), Player_Power_Widget_Class);
Player_Power_Widget->AddToViewport();
}
}
I do not see how they could be null, this error is fixed when I compile with
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &ATutorialCharacter::OnBeginOverlap);
commented out, and then uncomment it out and recompile with no changes to anything in the scene.
as for GetCapsuleComponent() I do not pass any parameters in it so there cannot be pointers. As for ATutorialCharacter::OnBeginOverlap() and ATutorialCharacter::OnBeginOverlap() I do not see how any of these could be null as I do not pass any parameters into these either. I think it is fulfilled by the engine but I’m a beginner so I am not sure of that. Even if one of these were null, how would that change after recompiling with it commented out?
I dont think that it is null because I call GetCapsuleComponent() in the constructor for the class here GetCapsuleComponent()->InitCapsuleSize(42.0f, 96.0f); which I believe gets called first.
If the problem is indeed that there is a pointer that is null, how could it be that the pointers are no longer null after compiling without that line of code in the .cpp file? Nothing is changed between then so the pointers should not be changer or am I missing something?
Unreal works in a very strange way…
I do not have all the answers.
But I do know one thing.
Exception Access Violation is the fault of null pointers.
And i will tell you more.
99% of problems in C++ are caused by pointers.
Thank you for this, how do you suggest I check for null pointers? I’m not exactly sure how to check if parameters/variables I did not create are null or not.
Pointers are always declared with an asterisk.
Pointers members are always accessed using an arrow →
Pointers of UObject are checked using IsValid() function
UObject pointers must be declared with UPROPERTY()
Delegate functions in unreal must be declared using UFUNTION()
raw pointers in C++ are checked with nullptr