Forum rules - please read before posting.

Inventory "Properties" Types

Hi
In the Manual there are some information about Types of Inventory properties, but only about Bool,Intgr,Strng,Float and Popup.
What a bout These Types? " Vector3" (locations?) Game Object , Unity Object?

At the moment i use a String to Get some descriptive Text about Inventory items in a UI menu.
I was looking for a way to Add an Image as property and get it in the UI Menu beside the String Label text.
My intention is To have a serries photo+Inofmation which the user can see on screen , when clicking or mouse over each Inventory Item....
No i have the Text as LAbel , the only thing i can not solve for me is how to get the image too?
I mean how i can assign an image to a Inventory Property? which type of Properties Can accept .Png sprite?

«1

Comments

  • edited June 2022

    See the Properties tab inside the Inventory Manager - properties of type Vector3, Game Object and Unity Object can be added.

    The Manual justs needs to be updated - thanks for the alert.

    A property type of "Unity Object" can be used to assign a Texture - but you will have to use custom scripting to display it in a UI menu. The best way is to hook into the OnMouseOverMenu custom event and extract the data its parameters:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class ImageItemPropertyUI : MonoBehaviour
    {
    
        public string imagePropertyName = "Image";
        public RawImage rawImage;
    
        private void OnEnable () { EventManager.OnMouseOverMenu += OnMouseOverMenu; }
        private void OnDisable () { EventManager.OnMouseOverMenu -= OnMouseOverMenu; }
    
        private void OnMouseOverMenu (Menu menu, MenuElement element, int slot)
        {
            if (element is MenuInventoryBox)
            {
                MenuInventoryBox inventoryBox = (MenuInventoryBox) element;
                InvInstance invInstance = inventoryBox.GetInstance (slot);
                if (InvInstance.IsValid (invInstance))
                {
                    Object imageOb = invInstance.GetProperty ("Image").UnityObjectValue;
                    if (imageOb)
                    {
                        Texture2D texture = (Texture2D) imageOb;
                        rawImage.texture = texture;
                        return;
                    }
                }
                rawImage.texture = null;
            }
        }
    
    }
    
  • wow! thanks i am going to use it .... <3

    Wish you find some time and will to start something like a MASTER CLASS for C# /Unity /AC coding so ppl like me can learn some Coding craft. I am thirsty to learn Coding but i can not find a right starting point.

  • I made not Unity UI canvas.
    I added a new Menu in AC Menu Manager.
    Where should i assign this Script?
    Sorry.

  • You don't necessarily need to create a Menu to house this script - but it does need to be attached to a UI Canvas that's in your scene.

    A Menu that's linked to Unity UI (tutorial) is the easiest way to ensure you have a Canvas prefab in your scene, however.

    The main thing is that your Canvas has a RawImage component in it's Hierarchy, and that this RawImage is assigned in the script's component Inspector. You'll also need to match your Unity Object property name to the component (by default, this is "Image").

    I also spotted a small typo in the script above - so be sure to copy/paste it again.

  • Thank you very much :)

  • Hi
    I made a InventoryItemDesctiption UI Prefab
    Assigned the Fields through Menu Manager.

    the Image field does not accept any images ....
    I could not get the data i want.
    If it is possible i made a screen video of whole thing. From inspector , to Menu manager and Inventory item.
    Will be thankful if you could take a look.
    no rush....
    I will wait till you find some free time and have a look
    https://rumble.com/v16xnyb-inventory-item-description.html

  • edited June 2022

    Maybe i missed these two :smile: !

    • You must use a RawImage component, not an Image component
    • The item graphics must be of the type Texture - not sprite
    • If you do create a Menu, don't create a Graphic Element that links to the RawImage - the script will handle its display instead
    • The script component should have a RawImage field in its Inspector - check that the code is properly copy/pasted and check the Console / restart Unity if it's not showing
  • edited June 2022

    That was RawImage but I changed the name to Image in Inspector.
    By Texture do you mean 2d Default? dont you?

    I could not understand this " If you do create a Menu, don't create a Graphic Element that links to the RawImage - the script will handle its display instead"
    I assume i must make a rawimage and assign it to related field in Inventory Property menu manager.

    When i Drag and Drop my UI Rawimage into the Linked Raw Image of Menu manager. It accepts it but in next time i check it , it says "Missing (Raw Image)

    And still Inside Inventory Item manager , When i want to drop a image into Image Box... it does not accept it and stay in : None (Object) state.

    I am taking too much time. i know. probabely my lack of coding knowledge and lack of experience with AC and unity is leading to take your energy more than boundries.

    by the way i uploaded another screen record from changes i have done ,maybe it can help me get to the point. if not. I am still thankful of your help.
    https://rumble.com/v16y05r-ui-test.html

  • I assume i must make a rawimage and assign it to related field in Inventory Property menu manager.

    Make a RawImage, yes, but don't link it to the Menu Manager. Such links are only necessary where you want AC to control a UI object. In this case, the RawImage is controlled by the custom script - you can delete the Graphic element.

    When i want to drop a image into Image Box... it does not accept it and stay in : None (Object) state.

    I've recreated this on my end. It's a bug - apologies, and thanks for the report.

    To fix it, open up AC's InvVar.cs script and search for the line 139:

    gameObjectVal = invVar.gameObjectVal;
    

    Immediately underneath it, copy/paste the following:

    objectVal = invVar.objectVal;
    

    That should fix the issue.

  • Thank you.
    from the Menu manager "Description" menu which i made . I have removed Graphic Element. So, Now i have Only Two Label Elements there. one for title one for Description text. They both work.

    In My UI prefab i did not change. I just assigned the Raw Image : Image(Raw Image) of my menu from Canvas i made.

    I did the Code edit you just gave me. and now it accepts textures or even Spirites.
    But inside Game, when i test nothing changed. i still see the White Rawimage beside Property string text as description. but my image does no apear there.

    Here Screen record Again :
    https://rumble.com/v172en1-menu-manager-tests.html

  • edited June 2022

    Your original post mentioned displaying the graphic when hovering over an item - so the above script will kick in when hovering over items.

    If you want to display the graphic for the item currently-selected, you can read the RuntimeInventory class's SelectedInstance variable:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class ImageItemPropertyUI : MonoBehaviour
    {
    
        public string imagePropertyName = "Image";
        public RawImage rawImage;
    
        private void Update ()
        {
            InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
            if (InvInstance.IsValid (selectedInstance))
            {
                Object imageOb = selectedInstance.GetProperty (imagePropertyName).UnityObjectValue;
                if (imageOb)
                {
                    Texture2D texture = (Texture2D) imageOb;
                    rawImage.texture = texture;
                    Debug.Log ("Selected item: " + selectedInstance.InvItem.label + ", Texture: " + texture);
                    return;
                }
                Debug.Log ("Selected item: " + selectedInstance.InvItem.label + ", No texture found");
            }
            rawImage.texture = null;
            Debug.Log ("No Selected item");
        }
    
    }
    
  • edited June 2022

    Yes, I need to get Inventory Item Information on hover.But at the moment since i did not made give and use interaction for items yet, I just let it be at click.
    I thought it is important in getting the main idea done yet . At the moment i just need to get that image from Property to run correctly. But unfotunately as you see in video, i could not get it done.
    :#
    I just changed both Label and Description to "Mouse Over Item" But nothing changed.
    Still i get Text and description but no image. Just the White frame.

  • I have updated the second script once more - does it work now?

  • Sorry But the answer is no. :(
    I removed the First Script and Added this new one ... then i again changed the Menu settings to" On item selected"
    Photos

  • My apologies once again - there is still an ongoing issue with the "Unity Object" property type for Inventory Items.

    Once more, open up the InvVar script and look for the following line around 108:

    popUpID = assetVar.popUpID;
    

    Immediately underneath, copy/paste the following:

    objectVal = assetVar.objectVal;
    

    Does that now cause it to work?

  • edited June 2022

    Hi
    NNNNNNNNNNNow works. <3
    it works exactly great ...
    Alittle bug is text comes faster and fades out sooner .. Image and menu come later.
    Maybe i can solve it myself.

    what i noticed just now is :smile:

    Now Drag and drop of inventory item does not work anymore.
    I am going to test it more now.

    thank you.

  • Does it work if you temporarily check Start game locked off? in your Description Menu's properties?

    Make sure that this Menu's UI boundary does not overlap your Inventory UI, and that Ignore cursor clicks? is checked in the Menu's properties. It might also be worth adding a Canvas Group component to its root and unchecking Interactable, to make sure the mouse can never react to it.

  • Hi
    When i check Start Game Turned Off , it does not work at all. first test section of video.
    When i check Ignore Input , Then drag and drop works but then on drag the 2d Texture goes away and a the RawImage Green Square shows up.

    Here is the video:
    https://rumble.com/v17lih9-test-ui.html

    I tested both ways and i got same result : with and without "Canvas Group" component to Root Canvas and unchecking Interactable.

    But i think i am taking your time too much .
    maybe it is better to stop this and try another method to give the User some information about Inventory items.
    I am ashamed that you are putting so much effort on this detail.

    If you think there is something i must do and we are near to get the result. ofcourse i will be more than happy to do it.
    I just do not want to consume your Time more than this.

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.