How to move a Blueprint function to another Blueprint?

I have a function in a Blueprint. Now I want to move it to a BlueprintFunctionLibrary. Is it possible to move it with all its local vars and the graph?

I wish there was an easy way. I was hoping it could be achieved via the new blueprint merge tool… But it crashes on me…

Did you try 4.7.1 hot-fix? According to the notes, it contains “Using the Merge Blueprints feature crashes the editor”. So it’s worth trying…

No. I will have to try that. Does the hotfix get pushed into GitHub (release branch)? i assume it does but wanted to be sure.

Yes, it’s in the repo https://github.com/EpicGames/UnrealEngine/releases/tag/4.7.1-release

I think of blueprints as visual c++ files. If I’m working with a c++ class and I want to move methods from one class to another I would have to make sure any class variable would come along with it. Now, in my specific case I really just want to copy functions around that don’t even rely on any outside “global” variable…

Out of curiosity, if something like this were implemented how would you expect references to variables that are not local, and are present in the original class but not in the new class to be transitioned? I was looking into implementing something along these lines recently, but zeroing out those references that couldn’t be moved along and pointed to the new equivalents would sort of eliminate most of the time saved, compared to simply copying and pasting the method body and setting up the function parameters and variables in the MyBlueprint panel again, I think.

So you would duplicate the variables, if the source class had some other code that wasn’t being moved that referred to the variables too?
Just foreseeing that things could be complex, iterating through to find the referenced variables, then having to iterate over all the other graphs in the object to find references to those variables, setting them to safe values, or else duplicating them regardless which could make BPs rather messy with unused variables.
I hear you that your particular use case wouldn’t involve global variables, but thinking that any implementation would probably have to handle them in order to be generally useful enough to make it in-engine…

In my case, the function I want to move has no references to the original blueprint class variables (only local variables), so in theory I can safely move that function to somewhere.

P.S. Just built 4.7.1, going to try Merge Tool.

Just create the same local and otherwise variable in the new blueprint and copy all the nodes of that function from the old one. I do it all the time. Or alternatively create a blueprint function library for all blueprints to freely use.

This is the way I do it presently, but I wonder is there another way.

I have some difficulties with Merge Tool. Opened a question https://answers.unrealengine.com/questions/182845/471-merge-tool-buttons-dont-show-up.html

Ok, I didn’t have a chance to try Merge Tool, because I experience troubles with its UI, so at the moment the best solution I found is shown in the following steps:

  1. Copy the entire graph of the original function.
  2. Paste it in the destination function.
  3. Find “gray” nodes referencing local vars which are not created yet.
  4. Right-click on them and select "Create local variable “MyVariable”, or “Replace variable “MyVariable” with…”
  5. Repeat step 4 until all the nodes are fixed.

The previous approach is good if you have many local vars and not so many nodes in the graph referencing them. Otherwise, its better to:

  1. In the new function, create all the local vars you have in the original function.
  2. Copy the entire graph of the original function.
  3. Paste it in the destination function. Be careful, because when you paste the graph, the nodes automatically link matching vars and after this moment you can’t change the type of the vars.

By the way, blueprint function libraries don’t seem to support debugging. I found this out the hard way after hand-moving many functions into one. So I don’t think those are a good solution for anything.

If you copy a function call in the original blueprint and paste it in the new blueprint (or in the code of another blueprint library function) you can right on the function call and “create matching fucntion” that way a function with the same input/output is created, so when you copy contents inside you only have to rewire connections.