Access blueprint variables from c++

Hi,

I’m still trying to create an “Inverse Bool”(bool = !bool) blueprint state. Ideally I would’ve wanted 1 input, which would get the variable by reference and change it. Now, when I do this :


void MyLibrary::InvertBool(bool& a)
{
	a = !a;
}

then all I get in the editor is an output. I don’t want both an input AND an output for such a small action, so I was wondering, how can I access blueprint variables directly from a script? I wasn’t able to find the Get/Set Variable function in the source.

Ideally, what I’d want would look like this (Pseudocode):



void MyLibrary::InvertBool(Fstring boolName)
{
	bool a;
        TryGetBlueprintBool([out,ref] a);
        a = !a;
} 

How can I make such a thing ? Any help would be appreciated.

Thanks,

Blueprint Function Library

If you make a Blueprint Function Library

you will be able to use any library functions you want as BP nodes in ANY blueprint

enjooooy!


**My Wiki Tutorial**

https://wiki.unrealengine.com/Blueprint_Function_Library,_Create_Your_Own_to_Share_With_Others!

**[BP Function Libraries](https://wiki.unrealengine.com/Blueprint_Function_Library,_Create_Your_Own_to_Share_With_Others!)**

I believe that node already exists, called ‘NOT Boolean’. It has a boolean input pin and boolean output pin. Generally that is the way you want to build functions exposed to Blueprints, rather than using in/out parameters.

thanks, yes that’s what I was looking for.
Just to clarify though, is there no way to pass a struct by reference? Ideally I would only want 1 input pin and no output pin, so the graph could look more tidy.

You can pass a struct by reference. By default Blueprints treat ‘const ref’ parameters as input and ‘ref’ parameters as outputs. However, you can use a UPARAM macro to tell it that a ref parameter is actually an input. Here is an example:


UFUNCTION(BlueprintCallable, Category="Math|Random")
static void SeedRandomStream(UPARAM(ref) FRandomStream& Stream);

thanks a lot, this will make things so much cleaner :slight_smile:

would be pretty cool to see things like this in the documentation as a comment^^