x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

alt text

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

alt text

Product Version: UE 4.11
Tags:
untitled.png (26.1 kB)
untitled.png (133.7 kB)
more ▼

asked Jul 30 '16 at 01:49 AM in Blueprint Scripting

avatar image

GhostRavenstorm
106 33 37 41

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

alt text

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

All the best.

blueprint3.jpg (30.2 kB)
more ▼

answered Jul 30 '16 at 03:16 PM

avatar image

Diego_Visualma
606 14 10 34

avatar image GhostRavenstorm Jul 31 '16 at 12:01 PM

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.

avatar image Atheist91 Jul 31 '16 at 03:49 PM

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.

avatar image Diego_Visualma Jul 31 '16 at 10:02 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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: alt text

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.

bp call.png (62.4 kB)
more ▼

answered Jul 30 '16 at 04:53 AM

avatar image

cm_o
6 1 3

avatar image GhostRavenstorm Jul 31 '16 at 12:04 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question