Forum rules - please read before posting.

Inventory, Shop and Crafting

Dear Chris and all the AC followers.
After ENCODYA I'm now working on a new adventure game. This time with many RPG elements and the challenge to use Raw Textures to display my inventory items in 3D.
However, I'm encountering some issues that I'd like to point out, asking for help.

Unity 2021.1.3f1
AC 1.73.3

First of all, CRAFTING.
Now, I'm not sure why (but I guess because the Crafting Class works different than Inventory Box one), but I can't manage to "empty" the slot (disable object), while I can handle that in Inventory Box.
Basically my grid is made of a Sprite of an empty slot, that has a RawImage has a child. That RawImage is what is linked to AC Menu Inventory Box (and also CraftingIngredients and CraftingOutput). I've set the "Disable Object" (when slot is empty) and that works nicely for InventoryBox (i.e. the rawimage is disabled when there's no item, and I can see the sprite of the empty slot), but not for Crafting: on my empty slots I've a white square (i.e. my rawimage empty). Like the object for some reason is not deactivated or not understood as empty. (this happens both for CraftingOuput and CraftingIngredients).

Still about CRAFTING, I've set the "Result is automatic" as true because I'd like to show the resulting item as soon as I've put the ingredients in place. However, I'd like to click my "CREATE" button to get that item in my inventory (basically the same kind of result that now I get if I click on the resulting item). How can I achieve that? (i.e. result is automatic, clicking on the resulting item does nothing, clicking on "create" will transfer the new item to my inventory, removing the ingredients).

Now... SHOP!
I've downloaded the SHOP package, tested and understood. Now I'm trying to do it my own, but I've some issues. First of all, I'd like to display both Buy and Sell at the same time, so basically my UI has on the left side the Player Inventory, on the right side the Shop Owner Inventory, and in the middle two smaller windows with in one the "Items to Buy" (with a buy button) and in one the "Items to Sell" (with a sell button). Then I've attached both scripts "Shop Buy" and "Shop Sell" to my UI parent and assigned each window/name to the correct field. However, for some reasons, it doesn't work.
1: I cannot drag items from the inventories to the "transfers" containers.
2 Most weird: The "Shop Owner Inventory" is showing my player inventory, despite I've opened that Menu with a Container Open action list which pick a gameobject with container, choose the inventorybox (ShopItems) name and overall "Shop" menu and then open it. How's that possible? Why the Shop Inventory is not correctly populated? Is there something I need to change in the settings?
3 I would love to display the Shop Name using the same UI (so: I use the same Menu UI prefab to display all the shops I encounter in the game). How can I achieve that? Shall I extend the container class to have also a string for Name and call it when launching the Action List "Container Open"? Not so clear how to achieve it though...

Thanks a lot and sorry for the lot of questions!

«1

Comments

  • on my empty slots I've a white square (i.e. my rawimage empty)

    Disable Object should cause the object with the linked Button component to be disabled - not necessarily the RawImage.

    Can you share screens of your Menu, Crafting properties, and UI hierarchy so that I can attempt a recreation?

    I'd like to click my "CREATE" button to get that item in my inventory

    To prevent any behaviour when clicking the "Output" element, set the When click on result field in the Recipe's properties to Run Action List, leaving the ActionList when click field empty.

    To have a separate button that moves the item to the inventory, you'll need a custom script that accesses the active Recipe showing in the Output element. This is not currently possible, but I shall look into it.

    I cannot drag items from the inventories to the "transfers" containers

    The Shop Example isn't designed to be used like this. If you're repurposing it to have a combined sell/buy system, you'll most likely want to create a single custom script that handles both at the same time.

    The "Shop Owner Inventory" is showing my player inventory

    If the Player's inventory is showing, then it's not being overridden by the shop owner's inventory. The Container must be active in the Hierarchy for this to work. You can try placing Debug.Log statements in the ActionContainerOpen script's Run function to see where it's failing.

    I would love to display the Shop Name using the same UI

    No need to extend the Container class - just create a PopUp or String Global variable and use Variable: Set Action to set it to the shop's name before showing the menu.

    In that menu, use a Label with a variable token, i.e. [var:X] to display that variable's value.

  • Thanks a lot Chris for your help.

    So, regarding CRAFTING:

    1: This is my crafting Menu and hierarchy. As you can see both the "crafting materials" and "crafting components" are made the same way, both link "RawImage" to the AC Menu slots buttons. The only difference is that one goes to an "Inventory Box" the others to "Crafting_:Ingredients" and "Crafting_Result". So I wonder if maybe for some reasons the classes are updated in a different way... Also, please note that my Crafting is a sub-menu (which is together with Inventory, Summary, etc.) which is however enabled at start and disabled when the player opens it (and re-enabled when clicking the CRAFTING button). Might this be the issue? But then why the Inventory Box is showed properly and not the Crafting ones?

    2: I understood that to do nothing on the output item I've to just leave a blank action on the recipe "when click on result". While for moving the created item into the inventory and empty the ingredients I basically need to write a custom script that does the "Just Move to Inventory" (maybe I can copy that from somewhere?)

    Regarding SHOP

    1 Ok, I'll try to write my own script which include both Buy/Sell at the same time. Just FYI, here is how the SHOP UI looks like at the moment (with the error of not showing the shop owner container, but player one on the right side).

    2: I will try to put the Debug.Log in every step... But, when you say "If the Player's inventory is showing, then it's not being overriden", means that it's impossible to show both player inventory and shop owner inventory at the same time? (i.e. Container Game Object is active in the hierarchy, as well as the Inventory Box on the Shop, in this case all is active from beginning and never disabled).

    3: Right, for the name a simple String Variable "Shop Name" is the easiest way, then changing that var when launching the "Open Container". Super easy, thanks. Didn't thought about it.

  • (Just a thought... maybe the solution for renaming the shop that way is not the best for future localization?)

  • This is my crafting Menu and hierarchy.

    Please share screens of:

    • Your InventoryBox element's properties
    • Your Crafting element's properties
    • The btnSlot, RawImage and lblCount Inspectors for one of your Crafting slots

    I basically need to write a custom script that does the "Just Move to Inventory" (maybe I can copy that from somewhere?)

    I will provide such a script once the next update is out.

    (Just a thought... maybe the solution for renaming the shop that way is not the best for future localization?)

    String and PopUp variables can both be included in translations.

  • All right, so... regarding the crafting issue, here the screenshots you asked me:

    The btnSlots are identical between Crafting Ingredients and Crafting Inventory Box (materials).
    Everything else is also identical, but what I just noticed is that the Crafting Ingredients has the "Disable Object" on "when invisible", while the Inventory Box has the "Disable Object" on "when slot is empty"... Is that just the way you wrote it? Or the two classes handle that differently?

    Good for all the rest. But I'm not sure I understood the SHOP part regarding showing both... can I achieve that with my own script? Or I cannot open container when player inventory is shown?

    Thanks.
    Nicola

  • Thank you, I have recreated the RawImage issue and will issue a fix in the next release.

    Or I cannot open container when player inventory is shown?

    You can - the default Container menu does this. What I was saying was that if a specific Container element is not overridden, it will show its default items.

    Even with its default items, though, it shouldn't be showing the Player's inventory. Is the element's "Inventory Box type" set to "Container"?

  • All right, thanks!

    Regarding the Shop Items Container, you were right... The shop owner inventory box was set to Default and I solved setting it to Container. However, I notice some RawImage issues in there as well, so I guess I'll wait the next update to start writing my shop script (or I can start anyway, having those white squares!).

  • To fix the white square issue, open up UISlot.cs, and find the line:

    uiRawImage.texture = _texture;
    

    Immediately above it, paste:

    if (_texture == null) _texture = EmptySprite.texture;
    
  • edited September 2021

    Thanks! Will try soon!
    One thing... Is it possible that the Shop on AC download has troubles if an Item quantity selection is set to "Stack" or shouldn't that be an issue? I'm trying to write my own shop script based on that one, but I'm having some troubles (see the UI I sent a couple of weeks ago to understand what I'm trying to achieve).

    UPDATE:
    The RawImage now works good, hurray!
    BUT, the thing you suggested me a couple of days ago to avoid the crafting result to end in inventory when clicked, meaning setting for "When Click on Result" to run an ActionList and leave it blank, is actually not working (i.e. is still transferring the item to my inventory even if it's supposed to run an action list... [and it happens either if I don't put any action list in there, or if I put an action list that has nothing in it]).

  • Is it possible that the Shop on AC download has troubles if an Item quantity selection is set to "Stack" or shouldn't that be an issue?

    Share steps on how to recreate the issue with the base Shop package.

    setting for "When Click on Result" to run an ActionList and leave it blank, is actually not working

    I shall look into it.

  • All right... so... I can't reproduce the issue with the ShopExample.
    So I'm sending my scripts and maybe you can help...

    The thing is: everything works great if I'm handling only single items (buy/selling one item at a time that is not in multiple number). The things get messy if either Player Inventory or Shop Inventory contain stack of something.
    Example1 - I click on a 10 units item in PlayerInventory: 1 item goes to the SellTransfer container, 1 item gets selected (i.e. my cursor looks like the item), 8 stays in the slot.
    Example 2 - I click on a 10 units item in ShopInventory: 1 item goes to the BuyTransfer container, 9 units go to the PlayerInventory (like magically teleported for free!) no units stay in the ShopInventory.

    What the...?!?!

    Here a screenshot that shows my Shop UI:

    And here the two scripts:
    https://paste.ofcode.org/CicxFR9kPcC9B9wzwS7gai

    https://paste.ofcode.org/kicFrKm6FEgfbPVvxLz2Ng

    Any help will be very welcome...
    Thanks!

  • edited September 2021

    The shop system relies on custom scripting to handle the behaviour when any item slot is clicked. You need to make sure that AC's built-in click behaviour is disabled. If items are being moved/selected inadvertently, it sounds like the default click behaviour is still enabled.

    For each of your Container elements in your Menu, make sure that Click behaviour fields is set to Custom Script, and that Prevent interactions? and Prevent selection? are checked.

  • That was it! Thanks!

  • With v1.74.2 now out, it's possible to move a Recipe's Output to the Inventory via a separate button:

    using UnityEngine;
    using AC;
    
    public class MoveCraftingOutput : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnMenuElementClick += OnMenuElementClick; }
        private void OnDisable () { EventManager.OnMenuElementClick -= OnMenuElementClick; }
    
        private void OnMenuElementClick (Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            if (menu.title == "Crafting" && element.title == "CreateButton")
            {
                MenuCrafting menuCrafting = menu.GetElementWithName ("Crafting") as MenuCrafting;
                Recipe activeRecipe = menuCrafting.ActiveRecipe;
                if (activeRecipe != null)
                {
                    KickStarter.runtimeInventory.PerformCrafting (activeRecipe, false);
                }
            }
        }
    
    }
    
  • Awesome! Will try now!

  • Oh, I noticed the ThirdPerson Camera also changed... this looks more advanced!
    However, I wrote a custom script to create a cinematic zoom-in (my view is bird-view), but now paramenters changed... How can I get them to work with the new camera? Can't find a way (also, before I set 10 as a starting distance, so the player could have zoomed in or zoomed out, but now the starting position is the "max distance" position).

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class ThirdPersonCameraZoom : MonoBehaviour
    {
        public int RegularMaxDistance = 20;
        public int CinematicMaxDistance = 100;
        public int RegularDistance = 10;
        public int CinematicDistance = 100;
        public float ZoomTime = 8f;
    
        public void ZoomIn()
        {
            GameCameraThirdPerson camera = FindObjectOfType<GameCameraThirdPerson>();
            camera.maxDistance = CinematicMaxDistance;
            camera.distance = CinematicDistance;
    
            StartCoroutine(SmoothZoomIn(camera));
        }
    
        IEnumerator SmoothZoomIn(GameCameraThirdPerson camera)
        {
            while (camera.distance > RegularDistance)
            {
                camera.distance -= CinematicDistance * Time.deltaTime / ZoomTime;
    
                yield return null;
            }
    
            camera.distance = RegularDistance;
            camera.maxDistance = RegularMaxDistance;
        }
    }
    
  • Update: Crafting now works as intended! THANK YOU!

  • The third-person camera now separates top/middle/bottom regions with their own height/distance fields, so it's not so easy to set the camera's "distance" as a single value. You're best off creating a separate camera with the same settings but lower distances, and switching to it instead.

  • I see.... is it possible then to fade between two cameras, similar as what the CineMachine does? In that way I can use the Third-Person Camera by default and do a smooth transition to another camera when doing some cinematic (so, not a jump cut, but simulate the movement, faking that it's the same camera zooming in or out).

  • You can assign a transition time when calling the SetGameCamera function:

    using UnityEngine;
    using AC;
    
    public class CameraTransitionExample : MonoBehaviour
    {
    
        public _Camera newCamera;
        public float transitionTime = 2f;
    
        public void DoTransition ()
        {
            KickStarter.mainCamera.SetGameCamera (newCamera, transitionTime);
        }
    
    }
    

    AC is compatible with Cinemachine as well - see the Manual's "Working with Cinemachine" chapter for details.

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.