**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:
I have been trying arround stuff for about 4 hours now, but cant get it to work. Please help.