Tip: rather than copying item ID strings around, I'd recommend a Constants class

public static class Constants
{
    public static class Identifiers {
        public const string LeatherArmour = "4c0827ba-3416-445f-8999-b1791290a0d0";
    }

    public static class Layers
    {
        public const int Interactable = 3;
        public const int Player = 9;
        public const int ActivePickups = 12;
        public const int InactiveProjectiles = 13;
        public const int InactivePickups = 14;
        public const int DeadThings = 17;
    }
}

And reference them like:

var tooltipInstance = Instantiate(tooltipPrefab, transform);
tooltipInstance.Setup(InventoryItem.GetFromID(Constants.Identifiers.LeatherArmour));

A good tip, though ultimately you won’t be using this approach to populating inventory… it’s just for testing. Once we get to integration, in most places the inventory item itself will be held in a serialized field or simply passed around as the parameter in the first place.

1 Like

Cheers. Yes, I mostly created the constants class for the Layers as I was repeating myself endlessly and eventually decided enough was enough. :slight_smile:

No doubt, and I’m not suggesting you drop that part of the constants class at all. Magic strings and numbers are an ever present woe for Unity developers, and a Constants class can really help reduce or eliminate these issues.

1 Like

Privacy & Terms