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"

Event execution for BP derived from C++

It appears that if you have BeginPlay event in BP parented from C++ class then BP's BeginPlay executes first and then BeginPlay defined in C++ class. This happens even if you haven't done "add parent function call" to add parent node. Even if you do add parent node for BeginPlay it has no effect on above behavior. In other words, BP's BeginPlay event always gets called first and the BeginPlay event in C++ next - no matter what you do.

Repro Steps:

  1. Create blank Unreal C++ project

  2. Add C++ Pawn class called MyPawn

  3. Right click on C++ class to create Blueprint from C++ class, name it BP_Mypawn

  4. Add BeginPlay event in C++ as well as BP, print some debug string from both

  5. Drag and drop BP_MyPawn in the scene

  6. Hit play. Observe both debug string gets printed, one from BP first.

Is this correct behavior? My assumption from the current documentation was that BeginPlay in C++ would not get executed if I'd BeginPlay in BP child class - unless I added a node for parent call.

Product Version: UE 4.14
Tags:
more ▼

asked Jan 31 '17 at 12:47 PM in C++ Programming

avatar image

sytelus
274 17 32 50

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

2 answers: sort voted first

Hey sytelus-

The code implementation of BeginPlay will always trigger, whether BeginPlay is used in the blueprint or not. The blueprint's call to Being Play is determined by where the call to Super::BeginPlay(); is in code. If your call to Super is before the debug message in code, then you'll see the blueprint message print to the screen first. But if your code debug message is before the call to Super, you'll see the code message print first.

Cheers

Doug Wilson

more ▼

answered Jan 31 '17 at 07:48 PM

avatar image sytelus Jan 31 '17 at 09:30 PM

Thank you. This clears up a lot. I'm still bit confused because I thought Super is alias for base class not derived class. So when I call Super::xxx() it should invoke code in base class. My assumption here is that Blueprint is derived class of C++ code class. So your explanation for Super seems counter intuitive.

Also how does parent call node in blueprint effect all these? It seems to have no effect on the order of BeginPlay between Blueprint and C++.

avatar image sytelus Jan 31 '17 at 09:54 PM

I see how this works... I'll add another answer below. However if you can explain why parent call node in BP has no effect, that would be great.

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

To add on to @Doug's answer, here's how this work:

The Super::BeginPlay() call does call the base class of C++ code class. In the base class however there is line of call RecieveBeginPlay() which redirects the call to Blueprint's the BeginPlay(). Thus C++ code controls exactly when (and if ) Blueprint's event gets called.

more ▼

answered Jan 31 '17 at 09:57 PM

avatar image

sytelus
274 17 32 50

avatar image karti047 Jul 11 '19 at 06:31 AM

Hey , Can you explain a bit more on this please? Because what i've tried is that i commented out Super::Beginplay() in my pawn class (C++ ).therefore i'm not executing the bp begin play. What i want to know is that if u set your derived bp class as default in game mode, then why base class( C++ version gets called) begin play executes? An explaination would be very helpful. Thank you..

(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