Forum rules - please read before posting.

Creating a custom interactive inventory bar: laying inventory eggs

Hello there!

I want to create a custom inventory bar and inventory interaction, where the player, a chicken, can lay the inventory as eggs.
You click on an inventory (it is now highlighted and selected), and then when an inventory is selected you click the 'Lay as egg' button on the left.

Now the chicken will lay an egg. Usually the egg will crack and the item appears. There will be a few other events in some situations, where laying a specific object, or a specific object in a specific place, will trigger special events and animations.

Now I'm fairly new to Adventure Creator and Unity so I do not have a clue on how to create this, and how to implement any of the steps outlined below.
If someone could give me a layout on what the most efficient way is to create this, I'd greatly appreciate it.
Knowing how to create this will also help me how to plan and set up the animations and graphics in advance and save me tons of time.
Are there any resources that I can read and learn more on the subject?

Here are the different steps to integrate for this interactive inventory bar in detail:
1) an inventory item cannot be used by dragging it's icon into the environment, or clicking it and then clicking on the environment.
2) however an inventory item can be clicked and dragged unto another inventory item inside the inventory bar, to combine two inventory items, if the combination is possible. Alternatively, you can click an inventory item, and then click on another inventory item to combine them if possible.
3) An inventory item can be selected by clicking on it. When selected, the graphic of the item icon changes, or a VFX is added to the graphic (brighter color, and outline), so that the icon is now highlighted, and clearly selected.
4) The selected inventory item gets unselected whenever you click anywhere in the real world outside of the inventory bar, or when you select another inventory item, or click on an empty space in the inventory bar.
5) If an inventory item is selected in this way, and you click on "Lay as egg", the chicken will lay an egg, which contains the selected item. This will remove the item from inventory, add it as an object in the real world, while triggering the following animations:

  • The chicken lays egg animation
  • As soon as the animation of the chicken with the egg reached a specific frame, the object appears with it's custom appear animation behind the cracking egg part of the chicken animation, to make it look like it appears from inside the egg.
  • The chicken-egg and the object animation should be perfectly adjusted, so that each frame fits perfectly with one another, and the object needs to be placed correctly. I would have to know how play two separate animations in perfect unison, while starting the second one on a specific frame of the first one, and also how to create reference points for two separate images, so that the inventory object is perfectly placed behind the egg, the way I animated it, so that it looks like it comes from inside the egg.

6) In some cases, after these animations are played, and the item is removed from the inventory and added as an object in the scene, there might be additional events: the object interacts with other objects, the object moves, more animations play, etc.

Comments

  • A fair bit to unpack here - and some of the latter is a little more advanced than standard inventory usage. If you're just getting started with AC, I'd recommend taking a look at this tutorial, as well as the Manual's "Inventory interactions" chapter to get an overview of how Inventory items can be used on other objects.

    an inventory item cannot be used by dragging it's icon into the environment, or clicking it and then clicking on the environment.

    Inventory items are used in the scene by creating an "Inventory interaction" for them in a Hotspot's Inspector. To prevent usage in the scene directly, you can just avoid defining any Interactions.

    however an inventory item can be clicked and dragged unto another inventory item inside the inventory bar, to combine two inventory items, if the combination is possible. Alternatively, you can click an inventory item, and then click on another inventory item to combine them if possible.

    Inventory items can be combined by defining "Combine" interactions at the bottom of their properies panels. For each interaction, you must assign an ActionList asset that runs, as well as the associated item it will run for.

    By default, a combine interaction is one-way - using Item A on Item B will run the Combine interaction on Item B. You can have the reverse work automatically, though, by checking Combine interactions work in reverse? in the Settings Manager.

    An inventory item can be selected by clicking on it. When selected, the graphic of the item icon changes, or a VFX is added to the graphic (brighter color, and outline), so that the icon is now highlighted, and clearly selected.

    If an Inventory item has an "Active graphic" assigned, it can be used when the item is selected - both as the cursor, and as it appears in the Menu.

    The selected inventory item gets unselected whenever you click anywhere in the real world outside of the inventory bar, or when you select another inventory item, or click on an empty space in the inventory bar.

    Check Left-click deselects active Item? in the Settings Manager's "Inventory settings" panel for this behaviour.

    If an inventory item is selected in this way, and you click on "Lay as egg", the chicken will lay an egg, which contains the selected item. This will remove the item from inventory, add it as an object in the real world, while triggering the following animations:

    I'd recommend looking into animations later, and just getting the behaviour of the item appearing in the scene working first.

    For the "Lay as egg" button - there's a couple of ways you could go about it.

    1. Have it be a regular Button element, and have the ActionList that runs when clicked use the Inventory: Check selected Action to check which item you've selected, and then run different Actions based on that. This is easy to set up, but your ActionList will get more complex with each item you want it to react to.
    2. Have "Lay as egg" be its own Inventory item, so that you can make use of the "Combine interactions" feature mentioned above - with each Item used on it be its own ActionList asset.

    To do this, define a pair of Categories in the Inventory Manager - Normal and Lay - and then place your regular items in the "Normal" category, and a new "Lay as egg" item in the "Lay" category.

    Then, in your regular InventoryBox menu element, check Limit by category? to have it only show items in "Normal" category.

    Finally, replace your "Lay as egg" button in your Menu with a new InventoryBox element that similarly limts its display to items in the "Lay" category.

    To spawn an item in the scene, you can use the Object: Add or remove Action.

    To play an animation where different elements need to sync up, you can use Unity's Timeline feature and the Engine: Control Timeline Action. When dealing with dynamic objects, i.e. those that are spawned into the scene at runtime, you'll need to use the Action to remap the Timeline's bindings - a tutorial on this can be found here.

    However, the link between Inventory items in a Menu, and their representation in the scene as proper GameObjects will be given attention as part of the next AC update, v1.78. This update will make it much easier to handle the spawning of Inventory items in the scene, and use further Actions to affect them afterwards. You're welcome to PM me your invoice # if you'd like to be involved in testing.

    In some cases, after these animations are played, and the item is removed from the inventory and added as an object in the scene, there might be additional events: the object interacts with other objects, the object moves, more animations play, etc.

    An object spawned in the scene with Object: Add or remove can have a Hotspot attached to make it interactive - but again, the next update will make this workflow easier.

  • Hello @ChrisIceBox,

    Thank you very much for all the detailed descriptions on how to set it up!

    I was able to set up the 'Lay egg' button as both a traditional button and as an inventory item.

    Creating it as a button will be an actual scripting nightmare later on, as you mentioned, because in the final game you will be able to lay every single object as an egg.

    So I would like to use your inventory "button" solution, with the combine action.
    I forgot to mention one aspect: When clicking on the lay egg "button", without any inventory item selected, the Chicken will lay a simple egg, containing no object. I hope this will still be possible using this solution?

    So far I have 3 issues while implementing the inventory button solution:
    1) Even though I have no events set up for using any item in scene, it displays "Use [selected item] on [object name]" when hovering over objects in the scene. I don't want that, but I would like it to display when hovering over other inventory items.

    2) The Egg Lay button acts as an inventory: When I activate the inventory box setting 'Prevent Selection', I am still able to select the 'Lay Egg' inventory item and it acts as an inventory ('Prevent interaction' doesn't let me use other items on it which is also not what I want). How can I turn the behavior and visuals to that of a button (with a separate Hover and click visual)?

    3) Since it acts as inventory, it entails 2 more issues:

    • When hovering a regular inventory item over the 'Lay Egg' inventory, it displays the "Use 'item' on Lay Egg" syntax. I don't want to override each inventory item's 'Use' syntax, because it will be a manual hustle, and I still want it to display "Use [selected item] on [item 2]" among regular inventory items. Is there a way to over-ride the syntax only when hovering any item over the "Lay Egg" inventory to display "Lay [selected item] as egg"?
    • Also I'm using "Combine interactions work in reverse" (I want to keep it that way), so right now I can use the "Lay egg" inventory on the other items, which I do not want.

    GameObjects will be given attention as part of the next AC update, v1.78.

    That's awesome!
    I will wait then before implementing the object appearance and animations until the new release. Is there a time frame I could expect for the new release? Days? Weeks? Months?

    You're welcome to PM me your invoice # if you'd like to be involved in testing.

    Yes, I would love to do beta-testing on it! Will send you the invoice.

  • When clicking on the lay egg "button", without any inventory item selected, the Chicken will lay a simple egg, containing no object. I hope this will still be possible using this solution?

    Yes - you can assign a "Standard Use" interaction to the "Lay egg" Inventory item, which will run when clicked without any other item selected.

    Even though I have no events set up for using any item in scene, it displays "Use [selected item] on [object name]" when hovering over objects in the scene.

    If the Interaction system is disabled, Hotspots will not be responsive. Through scripting, you could try auto-disabling the Interaction system whenever an Inventory item is selected. This script should do it:

    public class AutoDisableHotspots : UnityEngine.MonoBehaviour
    {
    
        void Update ()
        {
            bool isItemSelected = AC.KickStarter.runtimeInventory.SelectedItem != null;
            AC.KickStarter.stateHandler.SetInteractionSystem (!isItemSelected);
        }
    
    }
    

    When I activate the inventory box setting 'Prevent Selection', I am still able to select the 'Lay Egg' inventory item and it acts as an inventory ('Prevent interaction' doesn't let me use other items on it which is also not what I want). How can I turn the behavior and visuals to that of a button (with a separate Hover and click visual)?

    The 'Prevent selection' behaviour may be a bug - I'll look into it, thanks for raising the issue.

    Given the visuals and other behaviour you're looking for though, it sounds like it'd be best to go for a hybrid approach - where you use a Button menu element after all, but store the Interactions inside a "Lay egg" Inventory item that's never shown. Through script, you can have a Button click run the correct Interaction from the "Lay egg" item:

    using AC;
    public class LayEggInteractions : UnityEngine.MonoBehaviour
    {
    
        public string inventoryMenuName = "Inventory";
        public string layEggButtonName = "LayEggButton";
        public string layEggItemName = "LayEgg";
    
        private void OnEnable () { EventManager.OnMenuElementClick += OnMenuElementClick; }
        private void OnDisable () { EventManager.OnMenuElementClick -= OnMenuElementClick; }
    
        void OnMenuElementClick (Menu _menu, MenuElement _element, int _slot, int buttonPressed)
        {
            if (_menu.title == inventoryMenuName && _element.title == layEggButtonName)
            {
                if (KickStarter.runtimeInventory.SelectedItem != null)
                {
                    InvInstance layEggInstance = new InvInstance (layEggItemName);
                    layEggInstance.Combine (KickStarter.runtimeInventory.SelectedInstance);
                }
            }
        }
    
    }
    
  • Through scripting, you could try auto-disabling the Interaction system

    Thank you for the script, it works. I realized I can also tick the option "Auto-disable items with no interactions for selected item?" instead. Right now it displays "Use [selected item] on" when hovering on the scene, and "Use [selected item] on [inventory item]" when hovering over other inventory items.
    How can I have the text display disappear when not hovering over an interactive inventory item?

    Through script, you can have a Button click run the correct Interaction

    Thank you for the code. How can I run the mono behavior from the action list?

    I tried to run it this way but it did not work:

    I set it to "Runtime only", inserted the monoscript asset object "Lay Object Egg.cs" and added the Monoscript.name string "Lay Object Egg" (I also tried "Lay Object Egg.cs" and the behavior name "LayObjectEgg" instead).
    I made sure all the script names correspond ("Inventory", "LayEggButton", "LayEgg").
    Console didn't display anything.
    It didn't work.

  • How can I have the text display disappear when not hovering over an interactive inventory item?

    Disabling the Interaction system - which the script does - should handle that.

    Thank you for the code. How can I run the mono behavior from the action list?

    The script uses AC's event system to run itself automatically - you don't need to trigger it through Actions, just keep it placed in the scene.

    Events are a way of automating blocks of code when AC performs common tasks - in this case, whenever the Menu is clicked on. A tutorial on their usage can be found here.

  • Disabling the Interaction system - which the script does - should handle that.

    But no, it still displays the text.

    The script uses AC's event system to run itself automatically..., just keep it placed in the scene

    Thank you, it works perfectly!

  • But no, it still displays the text.

    Odd, it does on my end.

    As the Inventory menu only appears when the mouse is over it, however, you could try a custom script to lock the Hotspot menu whenever the Inventory menu is off, and an Item is selected:

    public class AutoLockHotspotMenu : UnityEngine.MonoBehaviour
    {
    
        void Update ()
        {
            bool lockMenu = AC.PlayerMenus.GetMenuWithName ("Inventory").IsOff () && AC.KickStarter.runtimeInventory.SelectedItem != null;
            AC.PlayerMenus.GetMenuWithName ("Hotspot").isLocked = lockMenu;
            if (lockMenu) AC.PlayerMenus.GetMenuWithName ("Hotspot").TurnOff (false);
        }
    
    }
    
  • however, you could try a custom script!

    Adding the additional script doesn't resolve it either.

    Just to avoid any confusion, I am talking about the text "Use [item] on" when selecting the inventory.

    I would like the text to only display when hovering over another inventory item:

    My inventory settings are the following:


    And I might add that when adding the first auto disabling script, this one:

    public class AutoDisableHotspots : UnityEngine.MonoBehaviour
    {
    
        void Update ()
        {
            bool isItemSelected = AC.KickStarter.runtimeInventory.SelectedItem != null;
            AC.KickStarter.stateHandler.SetInteractionSystem (!isItemSelected);
        }
    
    }
    

    then it does not deselect the inventory item when clicking anywhere empty anymore. Which is another reason why I prefer to use the setting "Auto-disable hot spots with no interactions for selected item?" instead.

  • I would like the text to only display when hovering over another inventory item

    What are your Cursor Manager's "Inventory cursor" panel settings? Try checking the Only show label when over Hotspots and Inventory? option.

    it does not deselect the inventory item when clicking anywhere empty anymore.

    The script can be updated with that functionality. Try this:

    using UnityEngine;
    using AC;
    public class AutoDisableHotspots : MonoBehaviour
    {
    
        void Update ()
        {
            bool isItemSelected = KickStarter.runtimeInventory.SelectedItem != null;
            KickStarter.stateHandler.SetInteractionSystem (!isItemSelected);
            if (isItemSelected && KickStarter.playerInput.GetMouseState () == MouseState.SingleClick && !KickStarter.playerMenus.IsMouseOverMenu ())
                KickStarter.runtimeInventory.SetNull ();
        }
    
    }
    
  • What are your Cursor Manager's "Inventory cursor" panel settings? Try checking the Only show label when over Hotspots and Inventory? option.

    Yes that was it!

    The script can be updated with that functionality. Try this:

    Yes, that works, too, just had to add in the script 'AC.' in front of for example 'Kickstarter'.

    Thank you for your help, solutions and ressources.

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.