Animated Buttons not working?

Hi there,

First post on the forums! First off, I'm absolutely loving UIS - it took me less than a day to get it set up and working in my game. I even connected it (ever so slightly) to PixelCrushers Dialogue System (looking forward to your integration of that). I'm sure I'm going to have a million questions as I continue to implement this in my game, but here is the first. And apologies if this is something super basic I'm just not understanding.

I have created an animated button that works on Pressed. I created a blank canvas in my scene, threw it on there, and it works fine. I took the exact same button and copied it into the Crafting Panel prefab, and it doesn't animate. I played around with trying to set it up with your Action Button script as well, but to no avail.

Suggestions?

Attached images are of the button animated on press in my main scene Canvas, and one of the button not working in the Crafting Panel.
 

Attachments

  • Screen Shot 2020-09-07 at 6.01.46 PM (2).jpg
    Screen Shot 2020-09-07 at 6.01.46 PM (2).jpg
    291 KB · Views: 13
  • Screen Shot 2020-09-07 at 6.01.15 PM (2).jpg
    Screen Shot 2020-09-07 at 6.01.15 PM (2).jpg
    306.3 KB · Views: 13
I'm glad you are enjoying UIS, it is very nice to see screenshots of your game, can't wait to see more.

Good catch on the button animation I didn't notice this before.

The reason this happens is that the system pauses the game by setting Time.scale = 0 and therefore the animation never steps out of its current frame. Simply set the animation update time to unscaled:

1599555403955.png
Or if you do not want to set time.scale to zero when a menu is openend uncheck this toggle (On the Canvas game object):
1599555496080.png

Then you can choose to pause your game differently by subscribing to the menu open/close event event:
C#:
//Listen to an event
EventHandler.RegisterEvent<DisplayMenuPanel, bool>(m_PanelOwner, EventNames.c_GameObject_OnOpen_UIMenuPanel_Bool, MenuWasOpened);


The events in EventNames have a littel description:

//The panel was opened or closed. The target game object is the panel owner assigned in the PanelManager.
public const string c_GameObject_OnOpen_UIPanel_Bool = "GameObject_OnOpen_UIPanel_Bool";
//The menu panel was opened or closed. The target game object is the panel owner assigned in the PanelManager.
public const string c_GameObject_OnOpen_UIMenuPanel_Bool = "GameObject_OnOpen_UIMenuPanel_Bool";

If you do so make sure to set your PanelOwner in the DisplayPanelManager.

I'm looking forward to seeing what you'll do with UIS!
 
Thank you for the reply! Setting the Update Mode to "Unscaled Time" did the trick.

I've hit a road block with what I'm attempting to do next and thought I'd check if it's even possible:

  1. Set an item attribute (float) in the database for TimeToCraft. [Done]
  2. Set the animation length of the button to TimeToCraft. (Basically it would fill up that neat little graphic in my first post when you press and hold the Confirm Button in the Quantity Picker parent. [Not done yet, but I think I could figure this out.]
  3. Execute the Submit of the button only when the animation completes. [This is where I'm stuck. I was playing around with a ton of different options/ideas for this, but I've come up short.]
  4. If the player stops half way through the animation, store the state of the animation and resume when they try to craft it again. [Need to complete #3 before getting here. But should I even be using UIS for this?]
I realize this may be outside of the scope of your support, but if you have any ideas to point me in the right direction, I'd appreciate it.

Thanks!
 
When implementing non-classical buttons you'll find that the Unity Button component is actually quite limited.

To make those types of custom buttons I would highly recommend coding your own taking advantage of the unity UI interfaces (IPointerEnter, IPointerDown, IPointerUp, etc...)

On pointer down you can start the timer, on pointer up you can pause, when it reaches the item craft time you can call the Craft function on the crafting processor.
Note that may mean we'll need to create your own CraftingMenu. I'd suggest copy pasting the scripts related to that menu and then edit the parts you want to change.

If you need help with any of this let me know.
 
Thanks - that definitely set me in the right direction and I have a rudimentary version working with some custom button code!

I was digging through the documentation and code, and for the life of me cannot figure out how to do something that I know is super simple, so apologies again for a simple question.

I figured out how to access the TimeToCraft Item Definition Attribute (which I think I'm doing right):
Code:
itemName = "Sleep Potion";
var myItemDefinition = InventorySystemManager.GetItemDefinition(itemName);
var notused = myItemDefinition.TryGetAttributeValue("TimeToCraft", out requiredHoldTime, true);
But I'm not sure how to access the selected recipe so I can pull the TimeToCraft attribute value from it. Basically I need to be able to get the current selected recipe item and put it into itemName.
 
I'm not quite sure what you are trying to achieve.

Are you trying to define the crating time on the output item of the recipe?

If so you can get your crafting output from the recipe like so.

C#:
// Get the first item in the outupt list.
var itemAmount = recipe.DefaultOutput.ItemAmounts[0];
// Get the attribute from it.
var timeToCraft = itemAmount.Item.GetAttribute<Attribute<float>>("TimeToCraft").GetValue();

This code assumes you have an item in the first output of your recipe and have a time to craft float attribute on your item(defintion/category).
 
Sorry for any confusion. I'm trying to send the TimeToCraft float attribute from my item definition from the currently selected recipe -> my button, which has my custom script attached to it. It looks like your code above may do that, but how would I go about accessing "recipe"?

Screen Shot 2020-09-10 at 9.30.08 AM.png
 
The item you circled in red is the output of the selected recipe.

Note that the crafting UI is made out of demo scripts so feel free to copy them and edit.
The script you'll be interested in is RecipePanel.cs or CraftingMenu.cs (or both)

In craftingMenu you could edit the RecipeSelected function
In RecipePanel you could edit the SetRecipe function

In either of those functions you can use the selected recipe to get the TimeToCraft attribute using the code I wrote in the previous reply.

And then you can use that information to change your button.
 
Top