BlueprintNativeEvent not Called on UObject

**EDIT: ** I think this might be a bug. I have made some simple tests, where I have a minimal BP, that overrides a NativeEvent from a class (which directly extends UObject) and then is instanciated inside a test actor: The Fallback _Implementation keeps getting called. Native Events directly on Actors seem to work just fine, even thoufh hot reload does not update the events with no return value.

Hello,

I am cuzrrently trying to make a simple Pickup System, with Items, that contain so called “Weapon Mutators”. Each Item can contain multiple mutators, and each time an item is picked up, it will add the mutators to the list of mutators in the weapon component. The mutators, have a BlueprintNativeEvent, that shall be called each time a shot is fired. However, the Event is not triggered and instead, the fallback _Implementation is called instead. Here are the important parts of my Source:

Mutator.h

UCLASS(Blueprintable)
class GEO_API UWeaponMutator : public UObject
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintNativeEvent, Category = "Weapon Mutator")
	int32 MutateProjectileCount(int32 projectileCount);

	virtual int32 MutateProjectileCount_Implementation(int32 projectileCount);
	
};

Mutator.cpp

int32 UWeaponMutator::MutateProjectileCount_Implementation(int32 projectileCount)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("This is an on screen message!"));
	return projectileCount;
}

Pickup.h

USphereComponent* collisionSphere;
	
	UFUNCTION()
	void OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

	UPROPERTY(EditAnywhere, Category = "Pickup | Mutators")
	TArray<TSubclassOf<UWeaponMutator>> mutators;

Pickup.cpp

void AGEOPickup::OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	UGEOWeaponComponent* weaponComp = Cast<UGEOWeaponComponent>(OtherActor->GetComponentByClass(UGEOWeaponComponent::StaticClass()));
	if (weaponComp != NULL) {
		for (TSubclassOf<UWeaponMutator> mutatorClass : mutators) {
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, mutatorClass->GetFName().ToString());
			weaponComp->AddMutator(NewObject<UWeaponMutator>(mutatorClass->StaticClass()));
		}
	}

	Destroy();
}

WaeponComponent.cpp

void UGEOWeaponComponent::Fire()
{
	
		FVector offset = FVector(85.0f, 0.0f, 0.0f);
	
		FVector newLoc	= GetOwner()->GetActorLocation();
		FRotator newRot = GetOwner()->GetActorRotation();
		float arc = 45;

		int32 projectileCount = 3;

		for (UWeaponMutator* mutator : weaponMutators) {
			projectileCount = mutator->MutateProjectileCount(projectileCount);
		}

		if (projectileCount > 1)
			newRot.Yaw -= arc / 2;

		FActorSpawnParameters projectileSpawnParams = FActorSpawnParameters();
		projectileSpawnParams.bNoCollisionFail = true;
		for (int32 i = 0; i < projectileCount; i++) {
			newLoc = GetOwner()->GetActorLocation() + newRot.RotateVector(offset);
			
			GetWorld()->SpawnActor(projectileClass, &newLoc, &newRot, projectileSpawnParams);
			if (projectileCount > 1) {
				newRot.Yaw += arc / (projectileCount - 1);
			}
			
			
		}
		
}

void UGEOWeaponComponent::AddMutator(UWeaponMutator* m)
{
	weaponMutators.Add(m);
}

Images of both the pickup and the mutator BP can be found here:

Imgur

I have been trying arround stuff for about 4 hours now, but cant get it to work. Please help.

Your event function should be void if not you can not override in Blueprint, and your event function should look like this in blueprint (should be without the Custom Event text, i make a quick one for example)

35425-capture.png

That’s not correct. If tested it with functions that have a return value and got it working in a test case on a simple actor.

Hey -

I’m slightly confused on the steps to reproduce your issue. You have a C++ class based on Object with a function that is labeled as BlueprintNativeEvent in the UFUNCTION macro, however the blueprint implementation is not being called, is that correct? Are you able to reproduce the bug in a new project with no additional content? If so can you explain the steps you took?

Cheers

Yes,

you are correct and yes I reproduced it. I will attach the Source Folder and the 2 BP assets of that test project to this comment, so you can try it out. It was based on FirstPerson c++ project. Im not attaching the whole project, since it is too big.

Blueprints
Source Folder

Hey -

Could you clarify how you edited the implementation of the Object class function in your blueprint? I created the Object class and an Actor class with the code you provided. I then created a blueprint based on the Actor class however I can’t create a blueprint of the Object nor can I access the Object class functions from the Actor blueprint.

I created a BP based on the Class with the native events.
To override the event without a return value, I just added it as an event to the event graph of the BP. It should show up as an event like Begin Play etc. For the one with the return value, you have to override a function in the BP. To do this, you need to go to the functions of the BP to the left, where it should say “overridable” and click override and select the event.

Events tend to not show up in the BP, after you build it using Hot Reload. You might have to make a clean build from VS, to get them working. (which seems like a bug for me aswell)

Hey -

The following code and blueprint show how I was able to use an actor blueprint in my level to call the blueprint override function of an object blueprint. Let me know if this is not the result you are looking for.

I first created two classes (ClassA as an actor and ClassB as an object):

ClassA Header:

ClassA Source:

ClassB Header:

ClassB Source:

ClassA Blueprint:

Something to note about ClassB is the “NewObjectFromBlueprint” function. This function is what creates the “CREATE” node in the blueprint. More information on this node and it’s code can be found at (A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums). With this setup you can override the MyNativeEventFunc in a ClassB blueprint and have it print out as long as an instance of ClassA blueprint is placed in the level.

Cheers