Funky behavior between OnKeyDown, Rebinding an Axis Mapping(C++), inside a widget BP

Alrighty, here’s an excerpt from my Log

LogBlueprintUserMessages: F::The Found Key
LogTemp: ReMapKey, successful? ::R
LogBlueprintUserMessages: D::myKeyValue

Pretty much, the function(OnKeyDown) that prints the third log message is called before the functions that print logs messages 1 and 2.

So even though the functions that print the first two log messages are executed after the execution of OnKeyDown, they still print and resolve before the OnKeyDown which was called first. *Note, OnKeyDown is called in a different context outside of this widget blueprint, but it still affects the value of a variable that initiates the sequence that calls the other nodes. See picture.


Print String TheFoundKey is inbetween C++ functions FindKey, and ReMapKey.

the UE_LOG(…) that resolves to ReMapKey, successful? :: %S is inside the function ReMapKey.

OnKeyDown changes the value of a string variable in this blueprint widget, that allows the Branch at the very beginning of the script to execute the sequence that finds the previous binding, removes, then adds a new binding.

OnKeyDown is overridden to do two things. Set the value of a string, and set the value of an FKey variable.
Even though setting the value of the FKey variable happens before the setting of the String variable in the node sequence. In the context of my widget blueprint, the string variable’s value changes and tells the Branch to proceed to call the other nodes. !But the value of last_key_FKey is still set to the default and does not take the value that it was set to in the context of the OnKeyDown function. In Fact, it does not take on this value until after the nodes resolve in the widget BP.

So is this a bug or a feature?

Hi shgs_sls,

Sorry for the delay in responding to your post. I am going to start looking into this issue, but I wanted to make sure I understand what is happening first. It sounds like you have three custom code functions exposed to Blueprints. Each of these functions prints output to the log, but the messages that appear in the log are in the reverse order to the order in which the functions are called. Is that accurate? Or is it only the first function that prints to the log last, and the order of the other two is correct?

Hey,

build 4.5.1

There’s the EventGraph in a widget. It’s got an (OnClicked) event for a button. When this event triggers, it first sets a String myString to “none” then it leads to a Branch that feeds into itself after executing a Delay(0.2seconds) while the branch evaluates true.

The expression for the branch is pretty much (myString == “none”) where myString is a string with the value of the last key pressed down.

The overridden function OnKeyDown() isn’t explicitly called anywhere in the widget. Instead when a key is pressed down on the keyboard, the function is called.

So the user, clicks the button. This starts the branch that feeds into itself. Then the user presses a button.

The overridden onKeyDown() function will first set the value of an FKey struct to the value of the key that was pressed down. Then it will set the value of myString to the string representation of the FKey struct instance.

The FKey struct and myString are both variables of the widget. When onKeyDown() happens, the value of myString is nolonger “none” so the Branch stops looping and executes a series of functions that rebinds a specific key mapping to this FKey Struct.

The series of functions, 1) a function that finds the previous key mapping. (Prints to log what key is currently mapped)
2) a function that remaps that mapping with the FKey struct, then prints a message whether it is successful or not.

The third log message is from OnKeyDown() which begins execution after the buttonClicked event, but it should resolve before the Branch jumps to the series of functions to remap the key. It does not do this, by error or some sort of priority feature.

When the series of functions run, the string myString has the value of the String representation of the FKey struct, but the FKey struct itself holds onto its default value until AFTER the (OnClicked) even resolves.

I’m about to hit the character limit, I’ll try and clarify anything when I get back in the office

thanks

Hi shgs_sls,

I apologize, I completely lost track of this post. I created a setup in version 4.5.1 to simulate what you described:

  • A UMG button that, when clicked, sets a string variable to “none” and starts a loop through a Branch node using a 0.2 second delay.
  • Overrode OnKeyDown() to store the FKey value that was pressed and output a string indicating what key was pressed, then setting the value of the string controlling the above loop.
  • When the loop exits, call a second function to find the string value of the current value of the key.
  • Print this string value out.
  • Call a third function to set the new value of the key that was pressed and output a message indicating success.

I did not do anything complex with this setup, but when I ran the project in PIE, the three messages were produced in the order I expected to see them.

Are you still having trouble with this issue? Are you still using 4.5.1? If you get a , would you be able to reproduce this issue in a small test project and upload it?

Hi shgs_sls,

We have not heard back from you for a few days. Are you still having trouble with this issue? I will be marking this issue as resolved for internal tracking purposes, but please feel free to re-open it with a comment at any time if you still need help.