can change all item definitions from item category to another item category?

Dahrona

Member
can change all item definitions from item category to another item category? i want to change all items which have item category "Upgrade Item" to "material". so I can change items that were originally one stack to multi-stack in different inventory. or maybe there is another way?
 

Attachments

  • multistack.png
    multistack.png
    11.1 KB · Views: 8
  • onestack.png
    onestack.png
    22.2 KB · Views: 7
Unfortunatly not through the UI interface, you'll have to do it one by one.
Dependng on the use case what you could do is rename your UpgradeItem to material and then create a new UpgradeItem.

If you really have a lot of items then you can look at making an editor script for it. You'll find the function you need to switch itemCategories within the ItemCategoryEditorUtility and ItemDefinitionEditorUtility classes, they all have static functions for manipulating those objects.
If you go that route you'll also need to make sure to initialize the database first before making any manipulations.
Make sure to keep a back up in case you make a mistake so that you can revert back.
 
Unfortunatly not through the UI interface, you'll have to do it one by one.
Dependng on the use case what you could do is rename your UpgradeItem to material and then create a new UpgradeItem.

If you really have a lot of items then you can look at making an editor script for it. You'll find the function you need to switch itemCategories within the ItemCategoryEditorUtility and ItemDefinitionEditorUtility classes, they all have static functions for manipulating those objects.
If you go that route you'll also need to make sure to initialize the database first before making any manipulations.
Make sure to keep a back up in case you make a mistake so that you can revert back.
i got a problem here, the script can running successfull but in editor, when I build my project it got an error because of editor.utility namespace, what should I do??
 

Attachments

  • ChangeItemDefinitionCategory.cs
    2.3 KB · Views: 3
Yes, it is an editor only script. You cannot add this in your build.

To avoid this you have two choices.
1) Put that script in a folder called "Editor" (can be nested). Unity automatically detects that and will not add tha script in the building process
2) Use Assembly definitions and have an Assembly for the Editor scripts:
 
Yes, it is an editor only script. You cannot add this in your build.

To avoid this you have two choices.
1) Put that script in a folder called "Editor" (can be nested). Unity automatically detects that and will not add tha script in the building process
2) Use Assembly definitions and have an Assembly for the Editor scripts:
so, is it possible to change category item after build? because the script only run in editor.
 
No you cannot change the category of an item at runtime. That would cause a lot of problems and inconsistancies.

Why do you want to change the item category at runtime?
You'll need to find an alternative.
Instead make a clever use of Attributes or save your items in groups (lists or dictionaries) and reorganize them yourself to be able to differentiate them.
 
i try
No you cannot change the category of an item at runtime. That would cause a lot of problems and inconsistancies.

Why do you want to change the item category at runtime?
You'll need to find an alternative.
Instead make a clever use of Attributes or save your items in groups (lists or dictionaries) and reorganize them yourself to be able to differentiate them.
okay, i tried to find an alternative like adding a new item based on items in itemcollection like the script that I had attached. but it only gives 0 in allItemInfos, even though there is an item in the inventory.
 

Attachments

  • ChangeItemDefinitionCategory.cs
    4.5 KB · Views: 3
The AllItemInfos getter will give you all the items in the Inventory except those that are ignored. Like ItemCollections with the Purpose "loadout".

In the switch you say this:
Code:
// Add an item to the item collection
InventorySystemManager.CreateItem("Oak ");

That is incorrect. Creating an Item does not add it to the itemCollection.
You have to add the item to the ItemCollection after you created it.
You'll find some examples here:

I think you might be confusing Inventory, ItemCollection and the InventorySystemManager.
Read this page to get a better idea of what those are:
 
Top