x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

http://imgur.com/KNqTAqW,aHOkzHO

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

Product Version: Not Selected
Tags:
more ▼

asked Mar 22 '15 at 05:58 PM in Bug Reports

avatar image

Brainshack
103 20 26 48

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hey Brainshack-

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: alt text ClassA Source: alt text ClassB Header: alt text ClassB Source: alt text ClassA Blueprint: alt text

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 (https://wiki.unrealengine.com/Blueprint_Node:_Create_Object_from_Blueprint). 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

Doug Wilson

classaheader.png (31.4 kB)
classasource.png (34.8 kB)
classbheader.png (21.6 kB)
classbsource.png (15.0 kB)
blueprintacall.png (69.7 kB)
more ▼

answered Mar 27 '15 at 02:32 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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)

alt text

capture.png (19.8 kB)
more ▼

answered Mar 23 '15 at 06:26 AM

avatar image

Duncan Dam
3.1k 121 50 164

avatar image Brainshack Mar 23 '15 at 07:17 AM

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.

avatar image Doug E ♦♦ STAFF Mar 23 '15 at 07:54 PM

Hey Brainshack-

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

Doug Wilson

avatar image Brainshack Mar 23 '15 at 08:16 PM

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

content.zip (16.3 kB)
source.zip (13.4 kB)
avatar image Doug E ♦♦ STAFF Mar 24 '15 at 06:14 PM

Hey Brainshack-

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.

avatar image Brainshack Mar 24 '15 at 06:48 PM

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)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question