How call blueprint event from cpp void without crash?

I want call bluerint event in actor from custom c++ void in cpp file
i use this APhysX4Scene().OnContModCallback(); method
but i have crash when Play in Editor(Actor placed in world).

Maybe other calling methods?

//header

UCLASS()
class PHYSX4_API APhysX4Scene : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	APhysX4Scene();
    

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	
	UFUNCTION(BlueprintImplementableEvent)
		void OnContModCallback();

};



//cpp

#include "PhysX4Scene.h"



void CMC(){APhysX4Scene().OnContModCallback();}//no errors when compile but give crash when run




// Sets default values
APhysX4Scene::APhysX4Scene()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
    
}


// Called when the game starts or when spawned
void APhysX4Scene::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void APhysX4Scene::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}
APhysX4Scene().OnContModCallback();

Looks like you are constructing an actor without going through the engine pipeline.
This is not supported.
You need to spawn your actor in the engine/world, by first accessing a world somehow (either through an other actor, or via GEngine->GetWorldContexts), then call World->SpawnActor(APhysX4Scene::StaticClass())

1 Like