m_Inventory simple question.

So I have been working on my game for 2.5 years and Im trying to bring this inventory system in. I have ground clothing objects that the player can pick up, I want to attach the code to my code so the player picks up the item and does my custom code AND will add the item to the inventory. Reading the instructions and watching some videos Im getting a very basic understanding of this sytem now. My question is how do I make this line of code work?

Code:
m_Inventory.AddItem("BlackNightie", 1);

The m_Inventory is missing what it needs. What is the code to match up with this add item to inventory code? Thanks
 
Anyone? Ive spent alot of time trying to find a reference to this and I see an inventorybase script some others use but I dont see that in my project. I was hoping to get this fixed today but its now heading to end of day for me.
 
I still get this error when trying to use the above code mentioned. I have tried quite a few declarations from older posts on like InventoryBase that I cant seem to attached to a game object like it used to 4 years ago. Any help here would be great.

Assets\Scripts\DRClothingTransitions.cs(2180,25): error CS0103: The name 'm_Inventory' does not exist in the current context
 
Hi @Fearinhell

we use the "m_" prefix to refer to members (a.k.a fields or class variables) of the class. This has no bearing on the logic it's just how we decided to name our variables to keep things organized

as the name suggests "m_Inventory" is an Inventory.

so you need a reference to your Inventory component. how you get a reference to your Inventory is up to you.

You can set a serialized field to set it in the Inspector:
Code:
[SerializedField] private Inventory m_Inventory;

Or you can grab the Inventory dynamically when initializing via a InventoryIdentifier (You will need to add an InventoryIdentifier component next your you players/main Inventory component)
Code:
private Inventory m_Inventory;

private Start(){
    // Get an Inventory Identifier by ID (a component which sits next to an Inventory)
    var id = 1; // Make sure the id matches the one you've set on the player Inventory Identifier component.
    var inventoryIdentifier = InventorySystemManager.GetInventoryIdentifier(id);
    var inventory = inventoryIdentifier.Inventory;

    m_Inventory = inventory;
}


Note the if you can't get a reference to the Inventory class in your code. It's most likely due to not having setup a reference to the Opsive Ultimate Inventory System Assembly Definition. Learn more about assembly definition here:
There are many youtube videos on the subject, this one is my favorite:

I hope that helps you to fix the issue you are having :)
 
Thanks for response. That helps me get a little farther. I was trying to use a public m_Inventory and couldnt get it to work. Im checking out the video now but having an issue now with a couple of errors trying to use your second method for a solution. Here is my Start Function.
Code:
void Start()
{      
    mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
    Invoke("ClothesTransition", .5f);
    Invoke("UpdateAlliDelay", .4f);  //Give delay for load times to find the right size.

    // Get an Inventory Identifier by ID (a component which sits next to an Inventory)
    var id = 1; // Make sure the id matches the one you've set on the player Inventory Identifier component.
    var inventoryIdentifier = InventorySystemManager.GetInventoryIdentifier(id);
    var inventory = inventoryIdentifier.Inventory;

    m_Inventory = inventory;
}
I have two errors I figured it was just a typo but Im not seeing it? So must be something else Im not understanding here. I already had the inventory and the other scripts you mentioned above added to my char prefab and it has an ID of 1. Here are my two errors,

Error CS1503 Argument 1: cannot convert from 'int' to 'uint' Assembly-CSharp D:\Diminishing Returns V045\Assets\Scripts\DRClothingTransitions.cs 205 Active

Error CS0029 Cannot implicitly convert type 'Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory' to 'Opsive.UltimateCharacterController.Inventory.Inventory' Assembly-CSharp D:\Diminishing Returns V045\Assets\Scripts\DRClothingTransitions.cs 208 Active

Attempting the first fix now and I still get the same error,

Error CS1061 'Inventory' does not contain a definition for 'AddItem' and no accessible extension method 'AddItem' accepting a first argument of type 'Inventory' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp D:\Diminishing Returns V045\Assets\Scripts\DRClothingTransitions.cs 2181 Active

Code:
[SerializeField] private Inventory m_Inventory;


m_Inventory.AddItem("BlackNightie", 1); //Giving the error here on AddItem.
 
Last edited:
Sorry that's my fault.
I wrote this without testing.

write uint instead of var
Code:
uint id = 1;

The second error
Error CS0029 Cannot implicitly convert type 'Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory' to 'Opsive.UltimateCharacterController.Inventory.Inventory' Assembly-CSharp D:\Diminishing Returns V045\Assets\Scripts\DRClothingTransitions.cs 208 Active
Says that you have two or more scripts with the name "Inventory". And it doesn't know which one you are trying to refer to.
When you have issues like this your IDE should be able to help you select the script you want to use.

I'm using Rider so my short cut is Alt+Enter. If you are using Visual Studio the short cut might be something else.

In any case you can fix this manually by setting an alias with a using statement at the top of your file. Something like this:
using Inventory = Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory;
 
Thank you! That removed the errors, now to test if it works. I had using Opsive.UltimateCharacterController.Inventory; as my library at the top. I had tried alot of others as well as I was going through other peoples scripts on the forum and I guess I just missed over the UCC one vs the actual Inventory one.
 
Yes! It works, thanks alot. So for the actual solution I ended up with for anyone else reading or for me to look back up if I forget something.

Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Opsive.Shared.Events;
using Opsive.Shared.StateSystem;
using PixelCrushers.DialogueSystem;
using Inventory = Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory;
using Opsive.UltimateInventorySystem.Core;


void Start()
{       
    mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
    Invoke("ClothesTransition", .5f);
    Invoke("UpdateAlliDelay", .4f);  //Give delay for load times to find the right size.

    // Get an Inventory Identifier by ID (a component which sits next to an Inventory)
    uint id = 1; // Make sure the id matches the one you've set on the player Inventory Identifier component.
    var inventoryIdentifier = InventorySystemManager.GetInventoryIdentifier(id);
    var inventory = inventoryIdentifier.Inventory;

    m_Inventory = inventory;
}
//Code Below is in my raycast hit function
if (hit.collider.gameObject.name == "BlackNightieHANG")
{                       
    m_Inventory.AddItem("BlackNightie", 1);                       
    DialogueLua.SetVariable("InventoryBlackNightie", true);  //Found item first time;
    RemoveOutfit();
    BlackNightieHANG.SetActive(false);
    StartCoroutine(WearAfterDelay("BlackNightie"));
    return;
}
Thank you again for the help and the video above I have watched and will have to start tearing into and adding assemblies like that into my system. Will take time. My whole assets folder for this game has hit 500 gb and my custom code main file alone is 20k lines. Will take time but will be worth it!
 
Top