How to pass by a variable by reference in a function and set it in blueprints?

I’m not too new to the concepts in C++, I understand pointers, how they work, and I want to try to use something similar in blueprints if the system would let me.

I have a series of buttons that toggle their own bool when pressed and released. I recently discovered that my design is flawed because the Makey Makey I have buttons wired to only has an N-key rollover of 6. I’m redesigning my button scheme to instead of being held down to set a true and release to set as false, I’m going to tie them to a timer that sets their value to false after a few seconds. Given how the Set Timer by Function Name method works, I was going to write a method for the timer in my input class that uses the button’s bool as a parameter and toggle it off. However, I seem unable to set the what the parameter variable is. This is where in C++ I would pass a pointer and set what its pointing to in the method. How is this accomplished in blueprints?

Is there a better way to do a wait timer for what I want? I feel like I’m using this timer method incorrectly.

You can specify the function within the UMG widget BP which contains the button and boolean variable. So instead of drawing from the input boolean to set boolean to false, just create a new Set Boolean from the execution call.

In BP the main execution could look something like this:

Assuming you’re using a UMG 2D UI layout, you can store the UI within a variable in your player character class. Then pass the value of the UI by reference after casting from your player character class. After you have obtained the UI value, you can pretty much access any function within the UI class that you have defined.

Edit: Forgot to add, there is nothing wrong with your set timer function. It should work fine.

Hello, GhostRavenstorm,

If what you want is to pass the bool by reference to the timer so it can change the state of the inputted variable without the need to return the value and set it again outside of the function, you can do exactly that.

Go inside the function that is called by your timer, and on the inputs tab, extend the properties of your boolean input. There should be a Pass-by-Reference checkbox that you can tick.


Then you can just set your boolean from inside the function to whatever you need.

All the best.

1 Like

Oh wow, how did I not see that. Thanks! This only solves part of my problem though. How do I pass in a parameter to that timer method if it calls the clear method via string? Even with event delegates I can’t seem to pass in a parameter to make use of the reference I want to change.

I’m not sure why I would want to off set my input variables to a widget when I already have a class for input variables. The button in question is actually a mechanical button that sends a key code. So I want to hold that boolean true for a few seconds after its pressed.

Events/functions called by timer cannot take any parameters. Workaround for this (an ugly one) would be to setup a variable that can be accessed from the called event/function and use data from there.

True. Another workaround and maybe a nicer one depending on what Ghost is looking for is to use “Set Timer by Event” instead of by function.

The timer would call a custom event that in turn fires the button clear function. That way, he can pass a variable to the function like he would normally do.

It wouldn’t make a lot of sense to allow the timer to take parameters because it is fire and forget, it will keep doing the same think over and over and you wouldn’t be changing its functionality on the fly.