In order to get equipment to change stats, do I need to spawn in a game object with an item object script?

Farcaster

New member
Seeing how my last question has gone unanswered, I decided it might be too broad. So instead, I would like ask if it is required to spawn in a game object with the "Item Object" script in order for an equipment item to change stats. The game I am working on does not change the character model with equipment, only the stats. As of such, I would prefer if there was a way to equip items, have the player's stats change while not having to spawn in a game object.
 
Hi Farcaster, in general we answer questions once or twice a day during week days. If your question isn't answered for a more than 4-5 days you can send us a reminder in case we missed it, but we do answer all questions normally.

Since you don't want to spawn equipment assets on the character you wouldn't be using the Equipper or ItemObjects.
So to compute stats you'd simply sum all the same attributes of your equipped items (I refer to items within a ItemSlotCollection) together in a custom script you would make.

To speed things up you can open the Equipper script source code and copy paste the functions used to sum attributes toghether. All the source code is commented so it should be easy to go through and understand. But if you have any questions do not hesitate to ask.
 
Thank you, I've created my own equipper script based off of the original equipment script. That being said, despite me copying pasting the code exactly, my new code does not have the data base slot that the old equipper has.
1635374519840.png
It also doesn't update the Item Object Slots automatically when the Item Slot Set is changed. But I think that might have to do with the new equipper not having a database variable so I'm going trying to get that fixed first before working on the Item Slot Set.

I removed the main root node myself along with all other skeleton references. From what I understand, there's no point in having it since I won't be spawning in meshes.
 
Our Equipper script uses a custom inspector. That's why the database field appears, it ins't used in game, only in the editor to show the correct item/category icons and update the Item Object Slot Set.

You shouldn't need to make a custom inspector for your equipper, except if you want to.

In your case you do not need ItemObjectSlotSet since you aren't equipping items visually (spawning items in a specific location for each slot).

All you need is the event listening to items being added to the Equipment Item Collection to know when to recompute your stats. The rest is unecessary
 
Thank you for your quick response. However, from what I can see, the stats of items are stored in the item objects themselves. For example in "GetEquipmentStatFloat"
public virtual float GetEquipmentStatFloat(string attributeName)
{
var stat = 0f;
for (int i = 0; i < m_Slots.Length; i++)
{
if (m_Slots.ItemObject == null) { continue; }
var item = m_Slots.ItemObject.Item;

if (item.TryGetAttributeValue<int>(attributeName, out var intAttributeValue))
{
stat += intAttributeValue;
}
if (item.TryGetAttributeValue<float>(attributeName, out var floatAttributeValue))
{
stat += floatAttributeValue;
}
}

return stat;
}

All stat attributes are being accessed through the Slots.ItemObject and the for loop is also iterating using Slots.Length. What should I replace ItemObjectSlot[] m_Slots with in order to get my inventory UI to display stats correctly? Should I create an array of Items instead of an array of ItemObjectSlots?
 
The objects that contains your "stat" are the items. As you can see in that loop we are looping over the slots item objects only to get access to the item within that slot.

In your case instead of using the item objects slots you can simply loop over the items in the equipment item collection.

You can find an exampe on how to get an ItemCollection by name from the Inventory component on this page:

There is an example of looping over the items of an item collection at the bottom of this page:

I hope that helps
 
Top