Forum rules - please read before posting.

Reusing a Button Prefab

edited September 2021 in Technical Q&A

Hey everybody,

I just started out using AC and I really love it! I'm using it to realize a project for a client and I just started out yesterday, so please excuse if my question has been answered somewhere else or can be figured out reading the manual, but my task is pretty time sensitive and I wasn't able to find an answer yet.

Most of the action in my project is happening in the UI. Imagine the player using a computer and simulating the screen, a Menu is activated that is linked to a Unity Canvas (in the scene). In this Canvas I have a lot of sub menus that have many Buttons, but it's actually just about three actions that are used over and over again.

How can I use multiple instances of the same Button Prefab without creating a Button in the Manager for all Buttons?

Thank you very much!

Cheers,
MB

Comments

  • I'm still interested if there is an "official" way (without custom scripts) of using one AC Button multiple times, but after some reading I'm aware of the possibility to simulate any menu button click by writing my own script.

  • Welcome to the community, @ManuBera.

    It's only necessary to link a UI Button component to an AC Button menu element if you want AC to handle the click for you.

    If you wanted these to bypass the Menu system and e.g. run an ActionList, then you can configure the click behaviour in the UI Button component. To trigger an ActionList, invoke its Interact function. (This goes for ActionList assets, too)

    What's the exact situation so far as intended click behaviour goes? Are you running exactly the same three Actions with each Button, or the same Action types with different field values? If the latter, you may want to rely on ActionList parameters.

  • Dear Chris,

    I appreciate your quick reply a lot and I think your commitment is amazing :)

    Thank you for the insights in how to bypass the Menu system e.g. to run an ActionList.

    The exact situation (at the moment) is as follows: I have two buttons that just trigger two ActionLists respectively: one to make the Player say "Yes, that is right", and one that says "No, that is wrong". Especially the negative response will be used a lot and therefore I have to duplicate this button multiple times. When I do this, just one of the duplicated buttons is working (the one that is linked to the menu element).

    Now I haven't linked any button to the menu elements I created and it complains about unlinked buttons in the Console. But for now I used the Simulate Click method and not the Interact function, so that might do the trick.

    Cheers!
    MB

  • one to make the Player say "Yes, that is right", and one that says "No, that is wrong".

    Is that the exact text that should show each time, or are these just stand-ins for correct/wrong responses? I'm not following the need to duplicate these buttons multiple times - is each "time" intended for a separate question thae Player is asked?

    The situation you're describing sounds like just a Conversation is necessary. A Conversation is essentially a way of presenting the Player with a list of buttons that each represent a different response. These buttons are repurposed for each Conversation, so that they can be re-used for different situations. By default, these buttons are displayed in AC's Conversation menu, which has both AC and Unity UI variants.

    Have a look through this tutorial and see if it suits the situation here.

  • Hey Chris,

    thank you again for the quick response!

    Imagine a fake desktop screen with icons and one icon (button) is the "right" answer and all other icons (buttons) are "wrong". I had the issue that all "wrong"-buttons didn't work, except for the one that was linked to an menu element.

    Since your last comment I realized how powerful this asset is and how easy it is to just reference an ActionList and use the Interact method. So I'm good at the moment :) Of course I'm curious on how this would be solved using only the menu system, but it's not important.

    Thank you!

  • Ah, I see - thanks for the explanation.

    Each Button element defined in the Menu Manager does need to be linked to a specific Button component in your Unity UI prefab, so yes: if you wanted to link each up to the Menu Manager, you'd have to create a separate element for each.

    In this situation, sticking with the method of invoking the ActionList's Interact function directly in the Button's OnClick event is probably the best way forward.

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.