Android performance hit on changing Button.Interactable

Using Unity 5.3.1f1, I’m noticing a weird UI performance hit on an Android device.

The game has a HUD button that’s made available/unavailable based on the current quantity of a particular power-up (which is found throughout the game). If the player has at least one such power-up in their possession, the button is available, otherwise it’s not. The button availability is controlled by setting its Interactable property.

When playing the game on an Android device, just as the first power-up is touched by the player, the game completely freezes for 0.5 - 1.0 seconds. Digging through the code, the culprit is this single line:

JetPackButton.interactable = _jetPackCounterText.enabled = count > 0;

Commenting out that line completely prevents the problem. And, the delay only happens the first time this line of code is executed. Beyond that, I never see the delay again.

Any thoughts on what’s so performance heavy about the above?

Also, the value of the Interactable property doesn’t cause (or not cause) a bunch of other code to execute. So, the rest of the execution path is the same either way.

When profiling on the Android device, the obvious spike on the offending frame is attributed almost entirely to “BehaviorUpdate | EventSystem.Update()”.

Any advice appreciated.

Jeff

**** Update #1 ****

A few other pieces of information that might be helpful:

  1. The offending button is enabled by default and is initially disabled by the same line of code mentioned above when the app sets the initial power-up count to 0. So, this isn’t even technically the “first” time the button state is toggled. It is, however, the first time the button state is enabled.

  2. The UI system has been already been interacted with at this point, as the User has had to navigate the Main Menu screen in order to start the game - which is where the first “enable” of this button causes a very painful lag.

**** Update #2 ****

As I haven’t yet found a solution for this issue, I thought I’d try to simply “toggle” the offending button once while the User is sitting in the Main menu. I really kind of expected that to fix the issue but, unfortunately, it did not. I’m running out of ideas and would appreciate some input.

To be honest I am not even especially sure what that line of code is actually doing. It seems a bit messy to have = _jetPackCounterText.enabled and = count > 0in one line.

Perhaps just using a simple if (count > 0) to enable it would be better?

    if (count >0)
    {
    JetPackButton.interactable = true;
    }
    else
    {
    JetPackButton.interactable = false;
    }

If not you could always fake the interactable element of the button by setting it active/inactive and having an identical image to the button with no interaction active/inactive inversely. If that makes sense.