Forum rules - please read before posting.

Change Button Background Texture onClick

Hello everyone,

I want to create a menu with a button that sets the next value of a Pop Up variable onClick. I also want the background texture of the button to change depending on the value.

Changing the variable works fine with Variable:Set Icrease By Value 1. If I set the variable as button text, I can see in the game how the values of my variables count up.

What does not work is changing the button texture. I use Menu: Update Content and assign a new texture and get an error message when I press the button: NullReferenceException: Object reference not set to an instance of an object

Am I understanding Menu: Update Content wrong? Or do I have a fundamentally wrong procedure here? As a workaround, the Text button would work, but I would prefer a visual symbol.

To easily show you my problem, I have created a test menu with a test button.
The button triggers an ActionList, which once executes Menu: Update Content.
For me, in this example the background texture of the button should theoretically change from “icon-look” to “icon-talk”, but it creates the mentioned error message.

Menu and Button: https://imgur.com/a/AVMcyVo
ActionList: https://imgur.com/a/a6wDXu4

Comments

  • What's your AC version, and what is the error message in full (stacktrace included)?

    If you're looking to loop through a fixed set of values, however, you can use a Cycle element instead of a Button. This will automatically increase an Integer variable's value each time it is clicked, and also has a Per-option textures? option that lets you assign a texture for each value within the Menu Manager.

  • AC version: 1.81.7

    NullReferenceException: Object reference not set to an instance of an object
    AC.ActionMenuSetInputBox.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionMenuSetInputBox.cs:268)
    AC.ActionList+d__47.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:470)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <50e5acd061cd4a73b7fc8eecbf07e915>:0)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:412)
    AC.RuntimeActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:181)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:283)
    AC.RuntimeActionList:DownloadActions(ActionListAsset, Conversation, Int32, Boolean, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:136)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Conversation, Int32, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:257)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Int32, Int32) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:178)
    AC.MenuButton:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuButton.cs:705)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2366)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1916)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2046)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2034)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:208)

    I initially wanted to use the Cycle element with the Pop Up variable, but the list has to stop when the last value is reached. With the Cycle element, the list of values ​​simply starts over from the beginning, and I haven't been able to change that.

  • Thanks for the details.

    This is a bug, and can be fixed by opening up AC's ActionMenuSetInputBox script and replacing line 268:

    else if (menuGraphic.ParentMenu && menuGraphic.ParentMenu.IsUnityUI ())
    

    with:

    else if (menuElement.ParentMenu && menuElement.ParentMenu.IsUnityUI ())
    
  • I quickly tried it in a test menu and it worked.

    Thank you for the fix.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.