[Request] Blueprint: Multiple return nodes in a function

** problem**

If you have blueprint functions which return something (which you definitely will make if you have a little programming background and your graphs become too redundant) you will always want to return if it is false/invalid as soon as possible.

Right now this is not possible since there is only one return node allowed per blueprint function.

So you need to chain all checks which you want to have true and return for example a true boolean at end but then it will not return false if they are not all false (not sure what exactly happens there). So you need to hook up all false events to one single return node too which then becomes a mess.

Your next idea is probably to have a bool AND node which connects all your checks and is connected to return node. issue here is that all checks are always executed if those have execution pins (like other blueprint functions) which is slow especially for AI/behavior tree blueprints.

A workaround for that is to add both branches and a final AND node which connects all your checks which seems to somehow work but this is just really ugly and becomes a mess if it is more complex than a few simple checks. See image below.

** solution**

Just allow us to have multiple return nodes in a single function which we can use to break out of function and return a value as soon as possible. Just talk to any programmer and they can tell you why.

I agree with this.

An alternative way to tackle this, while we wait for improvements, is to use a variable for return value. It will be assigned where you would want extra return node would be. Then jump straight to return node at end.

Hey,

Is there a reason you couldn’t use multiple Outputs on one Return Node?

Hi,

well I can always add additional variables/outputs but this is not how it should work. Also in my example I only want one single answer which is if target in being seen in a sphere or not. Being forced to have only one end point is bad design. Pretty much every programming language I know of supports being able to return a function from any point and there is a good reason for that. You are able to jump into other functions at any point so why are you not allowed to exit them at any point too. This is especially problematic for validation code which was also my example. There are good online resources for why this is good practice: language agnostic - Should a function have only one return statement? - Stack Overflow . Allowing multiple returns per function would still allow users to use temp variables and a single return if they really want so but I doubt that anyone having some programming background would not prefer being able to return immediately.

Sounds reasonable to me! I’ll enter a feature request into our database for developers to consider. Thanks!

Yep, that really sucks. BTW: Having no local variables in functions sucks, too.

Functions do have local variables.

As long as you’re in a function window you have at bottom of your normal variable window a new one which shows you local variables. They are exactly like any normal variable with exception that they don’t have default values.

Just like in this picture:

17825-inputsaslocals.jpg

Is there any information about this?
This feature would be nice. I dont like they return node functionality too. Every programming language can have multiply returns.
It is hard to work with flow control without this support in blueprints.

It’s still being discussed internally. developers are weighing advantages and disadvantages in UE-7849. I’ll update this post when I see any progress.

Sorry but how hard can this possibly be? Nearly every programming language supports this without any problem. Instead of that I had to make dozents of cruelsome workarounds with temporary ‘output’-variables just because of that.

BTW: Parameter values should also be available as local variables, should make functions a lot more readable.

I absolutely agree with you. It should have been possible since 4.0.

Epic, for transparency, what are disadvantages? If you name disadvantages I would be able to understand why you don’t implement it…

Your notes have been added to request. As I said, developers are reviewing request for official implementation. If you feel you are able to make change yourself, please feel free to add a pull request for review.

I´m looking forward to this implementation, let´s if it comes to life

You’re right. Was just a GUI issue in my case. But what I really would like is all input parameter automatically made available as local variables (like in any other programming languages). Would reduce Spagetthi factor. :wink:

Hi ,

any news on this (and on mapping of parameters to local variables)?

No news yet, sorry. It’s currently been pushed to 4.9 for earliest consideration. I’ll send an email to devs to remind them and see if I can get some additional information on it.

Ok, thank you anyway, .

Would be convenient. It’d be also an increase in speed.

Would be cool if function arguments were automatically available as local variables. Now I always end up doing a bunch of set nodes like you are in order to avoid connection chaos.

Functions are very clunky in many ways currently.

  • Parameters aren’t available as local variables for some reason. Have to create them by hand and them set them each time
  • Then I have to create an additional variable for result and use a setter
  • I am not allowed to use timers, delays or do any asynchronous stuff
  • At other side, there are no local variables for events
  • No callbacks for functions
  • Since 4.8 I have to create an exit wire to single result node from every branch