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"

How BlueprintNativeEvent specifier works?

Hey guys! I'm learning to programming in UE4 using C++. I followed the 'BatteryCollector' tutorial from Unreal Engine but there is something I don't get. How the BlueprintNativeEvent works? Why Lauren used that specifier? Is there any overall documentation about this? I searched the whole Internet about this but I didn't find anything but this: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Functions/Specifiers/BlueprintNativeEvent/

I still don't understand when MyFunction() gets called and when MyFunction_Implementation() gets called. In the tutorial Lauren called WasCollected() but it wasn't even declared so I guess WasCollected_Implementation() was called, but why?

Many thanks! :)

Product Version: UE 4.12
Tags:
more ▼

asked Jun 12 '16 at 03:35 PM in C++ Programming

avatar image

RadinQue
7 3 2 4

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

1 answer: sort voted first

Direct Answer To the Question:

So the BlueprintNativeEvent property is used to tell the Blueprint that a given function is optional to create within the Blueprint editor. If the given Blueprint function named, "function()" was called and it had no implementation, then the Blueprint would use the C++ class implementation named, "function_Implementation()" instead.

I think that BlueprintNativeEvents are a way of allowing Blueprints to override their C++ class implementation. For example, if you wanted to have two Blueprints based on the same C++ class there function named, "function()" could have two completely different blueprint implementations, but if you choose not to give them unique implementations then they could fallback to using the C++ class implementation.

Overall, I hope this makes BlueprintNativeEvents more clear . Although if you would like to see a more fleshed out example I would recommend checking out this link at https://docs.unrealengine.com/latest/INT/Gameplay/ClassCreation/CodeAndBlueprints/ . The given link provides a complete example of transferring pure c++ code to becoming a Blueprint ready class.

Why Blueprint Native Event Are Useful (Extended Answer):

Firstly, I want to say that the question of, “Where can I use it?” or “When is this useful?” is often a long and complicated answer. Although I will do my best below to answer your reply to my original answer, but if the subject is still unclear after reading this extended answer I would recommend creating another question on this forum and I can answer you there if you link the new question as a reply to this answer. Without further ado here is my extended answer:

As a game programmer, one wants to give their game designers the most control possible over the design of the game while still having a solidly programmed system.

So for this example, let’s say a game making team was making a tile based game. The design of the game demands that when these tiles are stepped on by the player they all do something, but the game programmer only wants to have to call one function named, “OnOverlapBegin ()” (for the purpose of this example).To expand the example, let’s say that one tile will light up when its stepped on, another will teleport the player, and the last one will only do the base functionality (which for this example will be activating the sound that the player makes when stepping on the tile).

Now all this functionality could very easily be made into several unrelated classes. Although it would be much nicer if all of it was based on one C++ class and a couple of blueprints. In the base C++ class one could create a tile class. This tile could contain the following code in the tile.h file:

UFUNCTION(BlueprintNativeEvent, Category="Tile Functions") void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

void OnOverlapBegin_Implementation(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

The OnOverlapBegin() function would have no implementation created and that would be left to the designers to create in the Blueprints. In the OnOverlapBegin_Implementation() function the programmer would create the base functionally described above to activate the sound of the player walking on the tile.

Later when a Blueprint is created from the tile class the designer could create a “LightUpTile_Blueprint”. The designer or programmer could create the functionality to light up the tile by adding functionality to the OnOverlapBegin() function within the Bluprint Event Graph. Additionally, the designer or the programmer could also create a “TeleportTile_Blueprint” the same way. Lastly, if the team wanted to create a simple “GrassTile_Blueprint” that made a grass sound when it was walked on by the player. All the team would have to do would be to create the Blueprint and add the assets. This is because the C++ functionality for the OnOverlapBegin() function would be triggered instead (which was programmed to activate the given sound file of the tile when it was walked on).

Overall, this makes the process of adding new functionally easier while still adhering to inheritance and good object oriented programming practices.

more ▼

answered Jun 16 '16 at 01:10 AM

avatar image

Jackkell
96 3 5 11

avatar image RadinQue Jun 17 '16 at 04:47 PM

Thank you for this explanation. That was really helpful. I didn't know that link before and that was helpful too. Thank you again!

avatar image RadinQue Jun 17 '16 at 05:40 PM

Just one other question. Where can I use it? When is this useful?

avatar image Jackkell Jun 17 '16 at 10:15 PM

I have extended my answer based on your reply. I would have simply replied to you here in the comment section, but my new extended answer exceed the character limit of the comment section. So I hope my new extended answer is helpful to you.

avatar image RadinQue Jun 17 '16 at 11:20 PM

Thank you very much for your really useful explanation. I didn't know that this is so complicated but overall it's truly useful in some cases. I really appreciate all your time which spent by writing this answer. I think I'll just try to recreate your example so I can see it in practice too. :) Again, thanks for your time, and the good explains.

avatar image Jackkell Jun 18 '16 at 01:11 AM

No problem, I like to help. Happy developing.

avatar image Grelen Jun 26 '16 at 02:53 AM

Thank you for the details, Jakkell. I've been struggling for several hours with implementing UFUNCTION(BlueprintNativeEvent) in 4.12 and your explanation helped tremendously!

avatar image Nachtmahr Jul 07 '16 at 01:24 AM

Id like to add something to your Extended Explanation (unless I did not fully understand your Example). In your case you Execute the C++ Implementation or the BP Implementation but there is also the Option to do both. Lets say your Designer wants also use the Sound Logic that was implemented in the C++ Logic and some BP logic before or after. In that case you could Implement the Event in BP as usual. Once the node is in Place you can Rightclick it and choose "Add Call to Parent Function" that will create a new Node that will execute the C++ implementation. It would look like this.

https://gyazo.com/1e76387d39711096b99878602c7c387b

Happy Coding everyone =)

avatar image AvaLanch.E Apr 08 '19 at 01:18 PM

Thanks for helping.I have been entangled in this problem for a long time but couldn't find a answer in my own native language until i saw your answer.

(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