Storage

So I thought it’d be relatively easy to make a storage container with what we have in the RPG course (I am on the last one in the abilities section). I figured it’d be a fun and easy challenge.

However, I am stumped. The Inventory.cs is too player-specific and trying to basically copy that entire file and tweaking a few things as Storage.cs and doing the same thing for a StorageUI.cs then starts running into problems when it comes to how InventorySlotUI.cs works. I thought about just inheriting for Storage.cs but like I said it is too specific to the Player itself and wouldn’t quite work throwing it on a world object and adding a IRaycastable to it.

Any idea where I should start here? I very much underestimated this. It SEEMS like it should be relatively straightforward. The hardest part should be letting the items drag between the player inventory UI window and the storage UI window. I am not even sure the IDragContainer can handle that without significant changes… But I didn’t even get that far.

This is one of those humbling things that makes me lose hope for when I get started in full my next project… Despite having a few successful prototypes from scratch. My next project will be more complex.

I think this topic might help you along the right direction:

1 Like

Thanks Brian. I should have searched to see if you covered this. I’ll be back later to shame myself further after I see how easily you solved the issues I came across.

The further I get along with the courses the more I am appreciating the systems we are making. They may not have a lot of bells and whistles, but they are pretty solid. I think for my project the inventory system should work just fine. And the more I think about it, the dialogue and quest systems should be sufficient. I own assets for both those systems thst are far more full featured, but overkill. These systems we have made all play nice together so they will probably serve me honorably.

I have some of those third party systems as well… generally swept up in a Humble Bundle or other deal that I was aiming for something else…

In all fairness, There are posts in random spots over a period of three years. I’ve been trying to tag them with something a bit more searchable…
BriansTipsAndTricks

Pretty simple and elegant as expected. I did have to make the ShowHideUI a serialized field on my storage chest, though. Was going nuts with Unassigned reference until I did so. It also popped up the Quest window when I clicked the chest for some reason. But once I serialized and threw it in there (and obviously changed the FindObject call to the variable instead it seems to work like a charm. Although it still is throwing Unassigned reference over the otherInventoryContainer.SetActive in Start on ShowHide. It is definitely set in the inspector.

Ah… Quest UI has a show/hide on it, too… It wants the other inventory info there too.

Hey Brian… Any idea how to set where a scroll view defaults to? When I have my storage set to a big bulky 100 spots it defaults the view scrolled half way down which is not helpful. I don’t see anything in the UI settings that would alleviate that I don’t think.

After MUCH trial and error I got it. There are a lot of Scroll types. Scroller, Scrollview, ScrollRect… But good ol Scrollbar will serialize (the others do not like and do not count as GameObjects for finding either).

Serialize the Vertical Scrollbar… then set the value to 1 at the end of Redraw. Which… I need to fix because that just made me realize that it will set to the top after every inventory move. So I just need to do it once after it is initialized.

Edit: Yay… Where I originally had planned to put it and then got sidetracked with all the UI elements not working has worked. In setup right after Redraw() and before returning true. Seems to be working so far. It’s so bizarre it was acting that way anyway. (Also weird to me that 1 is the value rather than 0. 0 puts it at the bottom).

public class InventoryUI : MonoBehaviour
{
    // CONFIG DATA
    [SerializeField] InventorySlotUI InventoryItemPrefab = null;
    [SerializeField] bool isPlayerInventory = true;
    [SerializeField] TextMeshProUGUI Title;
    [SerializeField] Scrollbar scrollBar;

  ///Other stuff

    public bool Setup(GameObject user)
    {
        if (user.TryGetComponent(out selectedInventory))
        {
            selectedInventory.inventoryUpdated += Redraw;
            Title.text = selectedInventory.displayName; //perhaps add a field to Inventory for a displayname
            Redraw();
            scrollBar.value = 1;
            return true;
        }
        return false;
    }
1 Like

I was about to suggest scrollBar.value, with exactly that caveat. It needs to be set when the InventoryUI wakes up, and not touched after that.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms