Equipment Land of Confusion

I must’ve dreamed a thousand dreams of the inventory system course

Been haunted by a million screams of items not dropping into slots

But I can hear the marching feet of the hamster dynamo powering my brain

They’re moving into the street to cart me off to rehab

I’ll be honest here, I got stuck for several hours at this point. I continued my project from the previous (stackable) chapter, but there isn’t really enough guidance to follow along unless you’ve really deep dived into the system (and these are very deep waters!) I scrubbed back and forth through the videos to see how what components Sam had on his GameObjects, but the number of moving parts makes it tricky to find the issue. After adding print statements and stepping through with the debugger I finally tracked down the issue - and of course they were my entirely my mistakes.

It turned out to be something silly (as so often is the case) - I was using a prefab for the Equipment Slots and they were using InventorySlotUI rather than EquipmentSlotUI. And another bit of weirdness where the type was being reset to weapon (I had more than one EquipmentSlotUI component). Adding the debug statements (see code below) helped me get it over the line.

It might be worth recommending at the start of the Equipment chapter that everyone starts anew via either the 8 Equipment System.unitypackage (missing in the resources in this project) or the git branch. I’m a stubborn git so I wanted to see this through myself, but with the benefit of hindsight I’d have taken the easier option…

EquipmentSlotUI.cs extra debugging:

        public int MaxAcceptable(InventoryItem item)
        {
            EquipableItem equipableItem = item as EquipableItem;
            if (equipableItem == null)
            {
                print($"Item {equipableItem.name} is not an 'EquipableItem'");
                return 0;
            }

            var allowedLocation = equipableItem.GetAllowedEquipLocation();
            if (allowedLocation != equipLocation)
            {
                print($"Item requires a {allowedLocation} slot but dragged onto a {equipLocation} slot.");
                return 0;
            }
            var itemAlreadyInSlot = GetItem();

            if (itemAlreadyInSlot != null)
            {
                print($"There is already an {itemAlreadyInSlot.name} in this slot. Please remove it first.");
                return 0;
            }
            print($"Good to put {equipableItem.name} here..!");
            return 1;
        }
3 Likes

Yeah, i really wanted to follow along and code it myself but there’s just too much that he doesn’t even touch on or cover. My plan is to just basically rewrite everything in the integration section from scratch (and maybe simplify it (imo this seems slightly over-designed with a couple excessive scripts) so i can actually grasp what’s going on. There’s too many times where it’s just “don’t worry about what’s going on in the ultil folders” or glossing over why a line is written in a way and not explaining new syntax but like… uh, that’s why I’m here i wanna learn.

3 Likes

Privacy & Terms