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"

Blueprint overriden functions - default c++ behavior not working

Hi guys, I just started using UE4 a week or two ago and am trying to get a very basic project going to familiarize myself with the engine, tools and C++ API... I've defined a basic class that inherits from Actor and wanted to describe some default behaviour for a few events. I then wanted to be able to override this in Blueprint using custom events. My issue seems to be that the default behaviour I define in my C++ class doesn't seem to work so I'm wondering what I could be doing wrong...

My header file contains

 // On Overlap implementation
 UFUNCTION(BlueprintNativeEvent)
 void MyOnBeginOverlap(AActor* MyOverlappedActor, AActor* OtherActor);
 void MyOnBeginOverlap_Implementation(AActor* MyOverlappedActor, AActor* OtherActor);

 // On End Overlap implementation
 UFUNCTION(BlueprintNativeEvent)
 void MyOnEndOverlap(AActor* MyOverlappedActor, AActor* OtherActor);
 void MyOnEndOverlap_Implementation(AActor* MyOverlappedActor, AActor* OtherActor);

In my C++ class I define my two functions

 void AHybridSphere::MyOnBeginOverlap_Implementation(AActor* MyOverlappedActor, AActor* OtherActor)
 {
     FString outputString;
     outputString = "Hello From C++!";
     Text->SetText(FText::FromString(outputString));
 }

 void AHybridSphere::MyOnEndOverlap_Implementation(AActor* MyOverlappedActor, AActor* OtherActor)
 {
     Text->SetText(NSLOCTEXT("AnyNS", "Any", "Goodbye From C++"));
 }

And in my class constructor I've included

 OnActorBeginOverlap.AddDynamic(this, &AHybridSphere::MyOnBeginOverlap);
 OnActorEndOverlap.AddDynamic(this, &AHybridSphere::MyOnEndOverlap);

When I move my player to overlap with my actor the text component does not change it's text so I'm wondering what I'm doing wrong...

Cheers!

Product Version: UE 4.18
Tags:
more ▼

asked Mar 10 '18 at 12:21 PM in C++ Programming

avatar image

mkraven
1 1 1

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

1 answer: sort voted first

Fixed it by moving

 OnActorBeginOverlap.AddDynamic(this, &AHybridSphere::MyOnBeginOverlap);
  OnActorEndOverlap.AddDynamic(this, &AHybridSphere::MyOnEndOverlap);

from the constructor to the BeginPlay fuction... I'm not sure why but there you go. Hope it helps people having similar problems.

more ▼

answered Mar 10 '18 at 01:39 PM

avatar image

mkraven
1 1 1

avatar image Durrik1 Apr 24 '19 at 11:57 AM

Thank you! I must be doing the exact same tutorial (and boy does that book have typos!) and I was having the same problem. I think it might be some sort of interaction between BlueprintNativeEvent, constructors and BeginPlay. I don't know, but maybe what happens is that there's a special path for BlueprintNativeEvents. The constructor sets it up, then the engine does a clean up or something and overrides what was set in the constructor, and finally when BeginPlay executes everything gets set to what it should be.

(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