How to change bp value with a blueprint function library function?

Hi everyone
I have this problem that confuses me: my functions in the blueprint function library cannot change the values passed in those function.
I have a blueprint function library class named “FileManager”, in this class i have a Test funciton which has 2 input: a FString, a Interger.And i try to change the two values in the function like this,

void UFileManager::Test(FString InString, int InInt)
{
        InString = "Has Changed";
        InInt = 100;
}

but it failed, when i call this function in the blueprint and pass values into it, it won’t change the value…
And in the header file:

UFUNCTION(BlueprintCallable)
        static void Test(FString InString, int InInt);

Any help would be appreciated!!
Let me know if you can’t get my problem.

Where’s the function called inside your blueprint? Anyway the FString and int should be a reference (FString& and int&), because otherwise you’re changing only a copy of them (at least in C++, I don’t know if blueprints do the same or they have something inside the reflection system to avoid this).

Thanks!
I think that’s the problem, I‘ll try it tomorrow and let you know how it goes!

Hi mate,I have just tried the (FString & , int & ) as input parameters .
I know the difference between FString Str and FString& Str (when they are params for a function), your advice will absolutely work in normal c++ code.
But when i tried it in the blue print function library function, it compiled well ,but in the bp this function would’t have any inputs, and all the params which should be inputs became outputs! That’s weird.
My c++ code is:

void UTextFileManager::TestFunc(FString & InString, int & InInt)
{
	InString = "Has changed";
}

When i called this function in the bp, the two inputs became outputs!

If you have some thoughts about this, that’d great.

But thanks for your help anyway!!!

BP doesn’t respect C++ variables passed as references in a lot of other places either, so that is always a gamble.

If you want to change those values in a BP function library, the best way to do it would be to pass the changed value to an output parameter:

void UTextFileManager::TestFunc(FString InString, int InInt, FString& OutString, int& OutInt)
{
	OutString = InString + "Has changed";
	OutInt = InInt * 9000;
}
1 Like

THANKS! That really helped a lot!
Wishes!!!

Yeah, that should work, I didn’t remembered that references are considered output parameters by default for BPs, but maybe the UPARAM(ref) method is more efficient. Check this wiki article: wiki.unrealengine.com

Yes.
I have got suggestion that: in most c++ cases(including Unreal), if a function is taking refs as input params, it will automatically take them as to-be-changed params, so the original values won’t matter(in most case).
It looks the same in the normal c++, when you call the function you still have to give the refs as inputs. But in the Unreal BPs , it won’t let you give input to the function ,but only gives output which the funtion would change in itself.
So using UPARAM(ref) in the function’s declaration should work on my case…