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/functions, what's the main difference between them?

They are similar in:

  1. I double-click function, it tells me what's it gonna do; I double-click event, it also tells me what's it gonna do.

  2. function can be used outside, events can be used outside.

What's the main difference between them? When should we use events, and when should we use functions?

Product Version: UE 4.10
Tags:
more ▼

asked Mar 20 '16 at 04:22 AM in Blueprint Scripting

avatar image

FuTou
57 6 6 9

avatar image FuTou Mar 25 '16 at 01:05 AM

Is there anything which events can do while functions cannot?

avatar image Kontur Mar 25 '16 at 01:08 AM

They can have latent nodes such and Delay, Timeline etc. while functions cannot, and in general, they are for different things.

avatar image FuTou Mar 25 '16 at 02:19 PM

Got it! Why u'd say they are for different things?

avatar image Kontur Mar 25 '16 at 02:46 PM

As their name suggest, Events are for handling different events in your game. As an example, let's say you walk into an area that hurts you, and you define that area with a volume. Then you can set up an Overlap event, and when the Player walks into that volume the event will fire, allowing you to respond. You most likely want to call some functions to reduce the health of the player and maybe update his HUD, up to you. Basically you want to your events to check for certain things in your game and when that condition met they will execute all the nodes behind them (most likely you want to execute different functions)

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

2 answers: sort voted first

Hi,

I am not a programmer, but here is my uderstanding of it. Events are allowing you to respond to certain, well, events in your game, like your player hit an enemy, you pressed W on your keyboard, so on. You can set up for example an event "W Pressed" and any nodes (including functions) will be executed after that event node when the player presses W, allowing you to decide what should happen in the game when a certain thing (event) happens.

A common example I hear a lot is to think of functions as car factories. If you want to make one or two cars, you don't build a factory, it doesn't worth it. But if your are planning to make a lot, it might be a good investment. Same for functions, if you want to add A+B in your game only once in your entire code (quite unlikely tho :P) you wouldn't make a function, it is easier to just add them with the ADD node. But imagine if you want to make a calculation more complex and you want to use it all over your game, then you should use functions. You can set input values and output values for functions, meaning you can execute the same code inside them but with different values (A+B example: your function would have an 'A' and a 'B' input and an 'A+B' output and in your function you'd add A to B). This would allow you to get the result of A+B any time, no matter what actually A and B means, the function will run with your desired values. As mentioned above, functions don't allow latent nodes, because they have to return a value immadiately.

I hope it clears up at least a little bit, but take everything I say with considerations, because again, I am not a programmer :)

more ▼

answered Mar 21 '16 at 12:10 PM

avatar image

Kontur
191 6 12 16

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

Functions have output nodes.

"Functions are guaranteed to execute and return immediately by limiting what kinds of nodes can be placed in a function (latent actions, timelines, etc… are all prohibited)."

Taken from here.

"...events like its name are a starting point of any independent tasks in a task queue system, that's why it was given Red color(most easily spotted even zoom out of graph). And call event node will have no return values, which means you can't and not allowed to depend on this event call's result, you fire it and it will do it's thing, just wait and profit."

Taken from here.

more ▼

answered Mar 20 '16 at 10:39 AM

avatar image

iKeepBelieving
208 6 11 20

avatar image FuTou Mar 21 '16 at 11:35 AM

Thanks man! But if so, what's the point of using events? Looks like functions can do anything, while events have limitations.

avatar image Pelangi Sep 02 '16 at 01:40 PM

This is an interesting topic and I hope UE staff can give the perfect answer. The answer in this thread is not really helpful.

It isn't distinctive if you use it in Blueprint. But from a programming standpoint, events are executed in a separate thread (subprocess), while functions are executed in the same thread.

So in computer, every execution flow is considered to be 1 thread. A collection of threads, is called a process. And a collection of process is called an application (it's called a program during the DOS age).

So if you call a function, then the same thread that you use to call it, will execute the instructions inside that function. But if you call a custom event, then UE will generate another thread to execute the instructions inside that event. So you'll have 2 executing thread that runs in parallel at the time you call an event. That's why, you are not allowed to depend on the result of an event execution.

UE staff, please CMIIW about this.

avatar image FuTou Oct 11 '16 at 03:42 AM

This is the greatest anwer ever! Thank you , Pelangi!

avatar image JohnDoe0 Jul 20 '19 at 02:26 AM

You should consider picking it as "Accepted" so it goes on top

avatar image Haikun Nov 29 '17 at 05:48 PM

This is what a great answer I have ever seen. Clearly.

avatar image Nerdballer Games May 08 '18 at 10:10 PM

That was the greatest answer. You are the greatest human. Thank you, human.

(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