Download

Problem with UBoxComponent

This is called in constructor:

Root = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerVolume"));
if (!ensure(Root != nullptr)) return;
SetRootComponent(Root);

Root->OnComponentBeginOverlap.AddDynamic(this, &AGunBase::OnOverlapBegin);
Root->OnComponentEndOverlap.AddDynamic(this, &AGunBase::OnOverlapEnd);

As you can see, I tried here to add some events. They sadly don’t work. Code in OnOverlapBegin() is not called.

In Blueprint Collision preset is Overlap All.

Please help me solve this problem.

Try binding your delegates on BeginPlay or similar instead of the ctor.

Editor crashes when game starts.

I can’t debug anything without a log. Could you link your log?

Here:

    LoginId:c8c4c26c4c47ee2c95ae449f8d0bdf10
        EpicAccountId:e40fd9dc9b5b4cc18fed88e6c8a9c757

        Assertion failed: DelegateOwner->IsValidLowLevelFast(false) [File:C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\CoreUObject\Public\UObject/SparseDelegate.h] [Line: 196]

        UE4Editor_Core
        UE4Editor_Core
        UE4Editor_NoszKurna_8536!AGunBase::BeginPlay() [C:\Users\rawsk\Documents\Unreal Projects\NoszKurna\Source\NoszKurna\GunBase.cpp:30]
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_NoszKurna_8536!ACharacterMain::BeginPlay() [C:\Users\rawsk\Documents\Unreal Projects\NoszKurna\Source\NoszKurna\CharacterMain.cpp:22]
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_Engine
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor_UnrealEd
        UE4Editor
        UE4Editor
        UE4Editor
        UE4Editor
        UE4Editor
        kernel32
        ntdll

I’ve had a problem with binding delegates in a constructor before (which you shouldn’t do) where even if I removed that code the delegates were still somehow messed up for the rest of the time.

Try recreating the class, and like the person said before, put them in begin play

Recreating means make new one, copy its code and delete previous?

Yes you can copy it’s code, perhaps even name it something slightly different

I did it but it still crashes.

Code:

void ABaseGun::BeginPlay()
{
	Root->OnComponentBeginOverlap.AddDynamic(this, &ABaseGun::OnOverlapBegin);
	Root->OnComponentEndOverlap.AddDynamic(this, &ABaseGun::OnOverlapEnd);

	Super::BeginPlay();



	FireMode = DefaultFireMode;
}

Nothing changes when I move Super::BeginPlay(); above delegates.