Do you need both variables? If so then create a new LOCAL variable with a different name but of the same type. Then at the start of the function SET the local variable to the GET of the global variable.
If you need the variable to exist outside the function then you must leave it as global and setting another variable locally is just a waste of time as you have full access to the global variable anyway.
If its only needed locally and not globally then just create the variable inside the function and delete the original global. Though have you tried copy and paste? It does give you an option to paste as local or global but that maybe limited to between functions/classes copy rather than within the same blueprint.
It’s not that I don’t understand what local and global variables are.
It’s just that sometimes at the start I’m not sure wheither I should setup a function and I make a blueprint with just global variables.
Then refactoring I collapse part of the blueprint to function to make it more readable.
Then to keep it clean I want to make local all global variables that were used only in this function and it seems there is no simple way to do it - I need to create local duplicate for each variable and then go manually through each occurence and replace global variable with local
You don’t need to do the set and get manually, after creating the local variable, click on the global variable in the function and you will see an option called “Replace…” you have to go one by one, Maybe you cannot chage all always, but at least it saves a lot of work.
Not it actually makes a lot of sense if you have a ton of class-wide variables and you want to convert them to be local variables if they’re only being used in one function. It’s very sensible and really annoying when you’re talking upwards of 10 variables. Super unhelpful response.
Do you know what a local variable is?
By definition it is a variable declared inside a function.
Exactly. So if you have a ton of class-wide variables that are only being used in one function, it would make sense to convert them to be local variables then. Because as you say, by definition they would only be relevant to the function they’re being used in.
Guys. Original Poster made a variable, then realized that he should have made it a local variable. That’s why he says he is trying to drag it down to the local variable section. He knows what local variables are. He just made a mistake and wants to easily fix it.
Answer for original poster: no, you cannot just drag the variable down to local and change it. I see no way to easily do this. You have to make a new local variable and then replace the old one everywhere with the new local one. Then delete the old one.
The global variables you deleted now appear grey in the function
Hover over it and use the context menu to press “create local variable” and magically all the variables become active again and the local variable is created.
Found a downside of this method - it’s just referring to the variables by their names, so when variables will be recreated as locals they will lose all their metadata (e.g. description, default value, value ranges, etc). Which is probably okay in the most cases since local variable by definition won’t be exposed to the UI and most of this metadata won’t be needed.