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 "event begin play" called before C++ parent's "event begin play"?

  1. Create a custom game mode class in C++ (derive from AGameMode)

  2. Implement Begin Play for this class and print a test string

  3. Create a blueprint subclassing the C++, set this as the default game mode for your map.

  4. In the blueprint implement the 'begin play' node and right click, 'add call to parent' to add a 'parent:begin play' node.

  5. Hook the 'parent:begin play' node to a print string node printing a dummy string

When you play the level you'll find that the print string of the blueprint's "event begin play" gets called before the print string in the parent C++ class's "begin play" which seems wrong.

Is this a bug or expected behavior? Does Parent:Begin Play in a blueprint only work if the parent is also a blueprint?

Product Version: Not Selected
Tags:
more ▼

asked Dec 17 '14 at 09:11 PM in Bug Reports

avatar image

VSZ
944 24 29 55

avatar image Tim C ♦♦ STAFF Jan 13 '15 at 08:24 PM

Hi VSZ,

I tried to reproduce this issue, and the results I saw were different from what you described. Let me tell you what I did, and if you can point out where you are doing things differently, that would help.

  • Create a new code project using the First Person template.

  • Build the project in Visual Studio.

  • Open the project in the Editor.

  • Add a new code class to the project derived from GameMode.

  • Close the Editor.

  • Override BeginPlay() in the new code class with the following code:

    if (GEngine) { GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Code Begin Play")); }

  • Open the project in the Editor.

  • Create a Blueprint from my custom GameMode class.

  • In the Blueprint Event Graph, set an Event Begin Play node and connect it to a Print String node.

  • Set the new Blueprint as the project's GameMode.

  • Start PIE.

What I was seeing is that the message from the code class is displayed, but the Event Begin Play node in the Event Graph was apparently not being triggered.

If you could also answer a few additional questions, that would be helpful.

  • What version of the Engine are you using?

  • Are you using the binary version installed by the Launcher, or did you build the Engine from source code?

  • Does this happen in a brand new project as well, or only in your own project?

Tim

avatar image VSZ Jan 13 '15 at 08:50 PM
  • I'm currently using 4.5.1 although I think I tried it on 4.6 preview as well, it's been a while so I don't recollect to be honest

  • I was using the binary version

  • I haven't tried reproducing it in a brand new project yet. Don't think I have the time to test in the next few days but I'll try to get back with a repro in the coming week or so.

Not sure if you see different results when you right click and add the call to parent: begin play?

avatar image Tim C ♦♦ STAFF Jan 20 '15 at 11:32 PM

I just took another look at this issue using the binary 4.5.1 Editor (I had previously been using 4.6.1), and I ended up seeing the same results that I was seeing previously. When you get a chance, would you be able to provide the code you are using in the BeginPlay function of your base class and a screenshot of how you have your GameMode Blueprint set up?

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

3 answers: sort voted first

Hey Guys,

The blueprint implementation of BeginPlay (AActor::ReceiveBeginPlay) is called from native code in AActor::BeginPlay().

If you want to call Blueprint implementation after the custom native code:

 void AQATestActor::BeginPlay()
 {
     TestNumber = 3.f;
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::SanitizeFloat(TestNumber));
 
     Super::BeginPlay();
 }

Cheers,
M

more ▼

answered Feb 21 '15 at 11:06 PM

avatar image hiili Feb 22 '15 at 07:29 AM

Thanks for this answer! Perfect timing, as I am just about to start implementing something that this issue would have affected. :)

So the "Parent: Begin Play" blueprint node is actually a no-op in this case?

To me it seems that this behavior is a bit counter-intuitive and feels like going against what is standard in object-oriented programming (execution starts from the child's overriding implementation, which is then responsible for calling the parent's implementation). Of course, this is how it has to be in this case, but I think it would be good to document this behavior somewhere? Maybe here:

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/TechnicalGuide/ExtendingBlueprints/index.html#executableandoverridablefunctions -> BlueprintNativeEvent

avatar image Plosnita May 20 '16 at 03:30 PM

"Parent: Begin Play" blueprint node calls the Super if the parent blueprint. It has to do only with blueprints

https://answers.unrealengine.com/questions/77597/child-tick-event-cancels-parent-tick-event.html

avatar image Tim C ♦♦ STAFF May 20 '16 at 07:27 PM

Hi Plosnita,

You are correct. The Parent: Begin Play node calls the Begin Play event of a parent Blueprint. The Begin Play function for a code class parent is always called.

Tim

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

Hey Guys,

The blueprint implementation of BeginPlay (AActor::ReceiveBeginPlay) is called from native code in AActor::BeginPlay().

If you want to call Blueprint implementation after the custom native code:

 void AQATestActor::BeginPlay()
 {
     TestNumber = 3.f;
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::SanitizeFloat(TestNumber));
 
     Super::BeginPlay();
 }

Cheers,
M

more ▼

answered Feb 21 '15 at 11:09 PM

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

Hi Tim, my project has changed quite a bit since I posted this bug and I don't think I have an exact copy of the code I used to reproduce this earlier. I will try setting up the same behavior again and post back my results. Apologies for the late reply, I've been swamped with some other work lately.

more ▼

answered Jan 25 '15 at 11:20 AM

avatar image

VSZ
944 24 29 55

avatar image Tim C ♦♦ STAFF Feb 11 '15 at 11:00 PM

Hi VSZ,

I completely understand about being swamped. If you happen to run into this issue again, or are able to narrow it down further, please let us know about any additional information you may come across. I will be marking this issue as resolved for tracking purposes, but please feel free to re-open it at any time.

Tim

avatar image Timbo Feb 18 '15 at 03:16 PM

Hi Tim,

I have the same problem. The Blueprint BeginPlay function is called before its C++ parent.

alt text alt text alt text

avatar image Timbo Feb 18 '15 at 03:17 PM

I am using 4.7 Preview 8.

Timbo

avatar image Tim C ♦♦ STAFF Feb 19 '15 at 07:54 PM

Hi Timbo,

Thank you for the additional information you provided. With your assistance, I was able to reproduce this issue. I submitted a report about this to have it investigated further (UE-10138).

Tim

avatar image Timbo Feb 20 '15 at 09:48 AM

Thanks Tim

(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