Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

S-Inventory: Equipment, Crafting, Skill Bar, Item Groups, Containers & Merchant (C# & JS)

Discussion in 'Assets and Asset Store' started by OussamaB, Jul 29, 2013.

Thread Status:
Not open for further replies.
  1. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Now that's awesome! Thanks a lot for making this, It was on my to-do list but you saved me a lot of time. I will add this to the main post and asset page. Does this mean that your integration package could integrate Realistic FPS Prefab and S-Inventory alone or is your Dialogue System needed in order to make them work?
     
  2. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    The tip I could give you if you want to modify it yourself is to search for the button name/texture name (you can get it from the inspector) in the inventory UI script and modify the rect to you what suits you best.
     
  3. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    cool beans. I'll give it a hack. thanks.
     
  4. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    1) Alright.

    2) Sure.

    3) I'll add a variable for the item script that decides if the item is instantly used and removed from the inventory when equipped and OnItemUsed message for that event.

    4) THAT! I had that in my to-do list for updates for so long but I keep forgetting to add it.

    Thanks for these awesome suggestions.
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    The package requires the Dialogue System to compile as-is, but you can just remove all the Dialogue System-related stuff and it should work fine without it. You may need to replace a few methods with non-Dialogue System code.

    Great! Thanks!
     
  6. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
    Hi Tony i own all three of the packs so i started a new project and downloaded your s-inventory package from your post everything works but i have an error in the SInventoryItemGroupTrigger script and SInventoryVendorTrigger script the error is
    error CS0117: `PixelCrushers.DialogueSystem.Tools' does not contain a definition for `SetCursorActive'

    i have properly missed something as if i comment it out it works but no cursor is shown

    This is a great combination btw :)
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @shaunmckay12 - If you update the Dialogue System to v1.3.9, you should be good to go. If there's still an issue after upgrading, please feel free to post on the Dialogue System forum thread, PM me, or email me directly at tony (at) pixelcrushers.com.
     
  8. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
    Yep that worked out fine :)
     
  9. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Here are the next update changes for the skill bar menu:

    - You can assign a key for each skill bar slot to use the item within that slot.
    - You can choose whether you want the used item in the skill bar to be removed or not after use for each slot.
    - You can choose a cool down for each skill bar item use. All these options can be changed from the inspector.


    More information about the next update to come!
     
    TonyLi, twobob and thenamesace like this.
  10. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Hi, this looks like a very neat project, so I hope you don't mind two quick questions about S-Inventory's functionality:

    First off, I already have a lot of infrastructure in place, and the big thing I'm looking for is the ability to create, retain, and move items in code: if I wanted to make my own GUI system in NGUI or Unity's new framework, would it be reasonably simple to adapt your code to work with it, or is the GUI an integral and difficult to separate component of your implementation?

    Second, I see that the demo uses single item slots, do you either support, or know if it would be easy to implement, size-based inventory management like Diablo, in which a large item requires a 2x2 or 1x4 (or any other combination) block of slots to store?

    Thank you for your time :)
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    I hope you don't mind another request. In addition to adding an OnPlayerUseItem() event, would you consider making it possible to use items directly in the inventory? For example, right-click and use a health potion instead of equipping it into the skill bar. The really important request, though, is OnPlayerUseItem(), so I can tie it into actions on the Realistic FPS side. Thanks!
     
  12. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    The current version might not be simple to adapt it to what you need because of the use of the old GUI system but with the upcoming uGUI update, it will be much easier. The update is under development right now.
    This will be supported in the one of the future updates but right now I'm fully focused on converting S-Inventory UI to the new unity GUI.
     
  13. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Yes sure, you have already requested this. I'm currently working on the new UI update and hope I can finish ASAP so that's a priority right now since Unity 4.6 has been officially released.
     
    TonyLi likes this.
  14. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Awesome, thank you very much for the quick reply! Looking forward to the uGUI update :)
     
  15. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    It might take some time. I haven't used the uGUI a lot when it was in beta stage so it's all still a bit new to me but I'm making good progress. Thank you for your patience.
     
  16. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Item.cs

    for on-the-fly run-through pick-up add:

    Code (csharp):
    1.  
    2.     void OnTriggerEnter(Collider other ){
    3.         if(other == InvManager.Player.collider)
    4.         {
    5.             if(ItemType == 0)
    6.             {
    7.                 InvManager.AddItem(MyTransform); //Add this item to the bag
    8.             }
    9.             if(ItemType == 1)
    10.             {
    11.                 InvManager.AddCurrency(MyTransform); //Add this currency to the inventory
    12.             }    
    13.             Debug.Log("Dynamic Pickup");
    14.         }
    15.         Debug.Log(gameObject.name);
    16. }
    17.  
    For them that might want it.
     
  17. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    I have noted a VERY large cpu usage overhead when adding circa 60 items. That just get's worse and worse when adding Tens more. 140 fps becomes 88 fps very fast (60,70 items), then it's all downhill from there...

    like massive. seem like there is a serious need for some update refactoring.
    Surely not every item in inventory is "Update"d over every frame?

    I will have to go dig but, honestly, this is on a 4 core desktop, how can it take that long to iterate over?

    Meh, Tomorrows job I guess

    14ms doesn't leave me much room for a game...
    88.JPG
     
  18. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    It used to run slowly - now it doesn't
    here is a few more. 23 ms Update loop! YIKES!

    23.JPG

    And finally - taking the test to it's logical conclusion:


    Garbage.jpg

    Assets used: Just the ones provided. Values used: The default ones that it comes with.

    Erk! Hope that the 4.6 GUI update really does bring some performance increases, and sorry if this appears negative but thought you would want the results of the tests.

    GARBAGE! get rid of some. seriously. 875k per second at the spikes... ? Gonna stumble anything. I'll have a look at some point if you don't.
     
    Last edited: Dec 24, 2014
  19. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    I'm really sorry about the performance. I didn't actually know it was this bad. S-Inventory is built on GUI interaction so a huge amount of code is done under OnGUI which is a called many times per frame. Luckily, it's time to update to the uGUI introduced in 4.6. I'm working hard on that update and I'm sure that the asset's performance will improve a lot. Would you be interested to test the update when I finish it?
     
  20. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Thank you! I will add this as a third type of pickup.
     
  21. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058

    Yeah sure. I would have just jumped in and done some refactoring for you already - but you are working on an alternate codebase. I am NOT wasting effort updating the old one. Come from an optimisation background on the xbox360, doubtless something can be done.
     
  22. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
    Hey just to let you know S-Quest does the same thing :)
     
    twobob likes this.
  23. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Hello, S-Inventory update will come first despite the fact that S-Quest update is easier to do.

    For everyone who's waiting for the updates, I'm working hard on them and I'm currently having some pretty important exams during these two weeks so I don't have much time to work. I hope you understand and thanks for your patience.
     
    thenamesace likes this.
  24. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    err. very first thing I looked at.

    in Update()
    Code (csharp):
    1.  
    2.     if(SaveAndLoad == true)
    3.     {
    4.         SaveItems();
    5.         SaveCurrencies();
    6.     }
    7.  
    8.  
    spikey.JPG

    well, since that will ALWAYS be true (there is no defensive boolean logic) that is where your enormous overhead is coming from. It must be saving and loading those prefs a bazzillion times (for a 100+ items, every single frame)

    I will have a play but it seems like a simple couple of "Do we really NEED to save/load this junk" checks will remove those horror-story spikes...

    like:

    Code (csharp):
    1.  
    2.     [HideInInspector]
    3.     public static bool SaveRequired; // needed to fix tight, pointless, loop
    4.     static bool saveInProgress; // probably not needed unless I find nasty co-routines...
    5.  
    6. public void  Update (){
    7.     if(SaveAndLoad == true && SaveRequired)
    8.     {
    9.         SaveItems();
    10.         SaveCurrencies();
    11.         SaveRequired = false;
    12.     }
    13.  
    and then set the flag in the various locations. Seems more sensible.

    Of course this is the very first thing I looked at, there could be more examples of this type of optimisation (and others) required, but this type of thing is where I would start. The "big lumps".
     
    Last edited: Dec 1, 2014
  25. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    InventoryManager.cs Line 380 I updated to be

    Code (csharp):
    1.  
    2.                         if (Item.transform.renderer) {
    3.                             Item.transform.renderer.enabled = false;
    4.                         }
    5.  
    (I think that == is still a valid check)

    This allows for "Other" shaped prefabs to be shoved under the parent.

    Like chests, that require more than one object or renderer.


    Oh. And I checked. That one line fix above is all you need to improve the performance MASSIVELY. (from 75% CPU usage to 0%) put it in. (and the relevant switches in the "I HAZ TO SAVE STUFF" methods)
     
    hopeful likes this.
  26. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    if you send me a copy of your other stuff (released and stable) I'll have a dig thru that too.
    Never hurts to have a couple of pairs of eyes on things.

    Offers there.
     
  27. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Thanks for your help. Items will only be saved when added or removed from now on. I'll make sure you get to test the update before I submit to the asset store but it might take some time for the reasons I mentioned above.
    It was really hard for me to see exactly asset's performance on memory and CPU since I'm don't own a pro license but I was aware that these issues exist because of the huge amount of code under OnGUI.
     
  28. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    EDIT: Author says he is fixing it :)
     
    Last edited: Dec 2, 2014
  29. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Meh, it's cool, I remember the heady days of actual "Pressure", I won't say favourably.

    Always happy to profile where I can, or convert resources to the newer 5.0 substance format.
    Have tools, Will Travel.

    (okay, I won't actually travel, but I do haz tools)

    Be well, for those users who can't wait those weeks I posted a - seemingly- complete solution above, EDIT: which I have now removed.
    Enjoy

    Now, back to that game I was writing two days ago hah.
     
    Last edited: Dec 3, 2014
  30. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    I can assume that the update will be released from 14 December to 16 December. Thanks for your patience everyone.
     
    thenamesace likes this.
  31. HelixU4

    HelixU4

    Joined:
    Jan 25, 2013
    Posts:
    61
    This script is amazing.

    A few questions tho. Im using RFPS and how can I freeze player and camera, and show the cursor when either inventory, crafting or looting window is open? and then enable them all again when all of the windows are closed.

    Also how to make consumables and make them send an message on consumed? I'm using PlayMaker for programming so let's say I want to eat something from the inventory to prevent starvation, it sends an message / event to PlayMaker which then does its thingy.
     
  32. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Top of my head:
    Timing:

    http://docs.unity3d.com/ScriptReference/Time-realtimeSinceStartup.html
    http://answers.unity3d.com/questions/9878/freeze-game-using-timetimescale-0-wait-3-secs-and.html

    Playmaker:

    I was rather under the impression there is a "USE" function that does much the same thing for potions and such.
    Although, You could send a DROP message to the item and toggle the "Item is Spawned" value; and manage your "increment" (such as health) externally, this would effectively consume it.

    As for actually getting playmaker to do that... perhaps it can send messages. I forget.
    I abandoned it when I saw how agonising setting up arrays was. The kids use it though.

    Assuming you have to actually MacGyver it:
    It would arguably be a case for 1) setting up a flag in the relevant .cs file that you could check over at update time (it is TRUE? then 2) consume whatever string (name of thing) is in string:"EATME" (made-up name, there is no string called EATME)

    To actually trigger that:
    Setting that boolean (true/false) flag, and also the string, via reflection (not in that order)

    That would work. (Playmaker does "setting values by reflection" OOTB IIRC),

    That type of "flag", "name" construct can be used to cause any number of actions to be manipulated externally when implemented. (having a "I'm busy doing it, wait a sec" flag doesn't hurt neither)

    However using the provided methods would of course be easier, quicker, painless and robust going forward as there is a new version just around the corner.

    Good luck.
     
    Last edited: Dec 9, 2014
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    If you have the Dialogue System, import the Realistic FPS Prefab Support package, the S-Inventory Support package, and the RFPS S-Inventory Support package. Then add an SInventoryFPSBridge component to your player. It takes care of this. If you don't have the Dialogue System, you can still download the S-Inventory Support package from here. You'll have to modify the code a bit, since it expects to talk to the Dialogue System.

    In brief, it checks InventoryGUI.ShowInv || ShowEquipment in Update(). If the S-Inventory window(s) just opened this frame, it disables the RFPS components -- FPSPlayer, FPSRigidBodyWalker, and InputControl -- and shows the cursor. If the S-Inventory windows just closed this frame, it re-enables the RFPS components and hides the cursor.

    I won't speak for @SoumiDelRio, but I did submit a request to get an event for this. The current version of S-Inventory doesn't do this yet. We're all looking forward to the new version with these events and new Unity UI support. As @twobob writes, it's just around the corner.
     
    Last edited: Dec 9, 2014
    twobob likes this.
  34. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    yeah, he's busy for a couple of weeks. just doing some community service, thanks for wading in.
     
  35. rizawerx

    rizawerx

    Joined:
    May 30, 2013
    Posts:
    38
    Hi,
    I just bought your plugin. When I import it, there's a warning in Unity's console said:
    Assets/S-Inventory/JS/Scripts/InventoryGUI.js(980,13): BCE0005: Unknown identifier: 'ItemScript'.

    So I went up to the top and found on line 266 :
    var ItemScript : Item;

    I'm not sure what it is and how to fix it....

    Thanks,
     
  36. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    That is basically saying "By the time I get to line 980, column 13" the "variable" (a place to store info) called 'ItemScript' is either "no longer called what I expected, in the context I expected it" or "Has never been set up" or "When I look for something to fill this it ain't there"

    I personally use the C# version so I did not experience this error.

    I'll have a quick look.

    hmm....

    ItemScript = ActionItem.GetComponent("Item"); //Getting the item script.

    SO.... You have actually assigned something to that?
    Basically that is saying (AFAIK) there is no "Item" associated with the request to find "Item".

    Somethig is missing? as in - "file not componently connected to other thing."
    so that is "When I look for something to fill this it ain't there"


    Looks like that to me
    so you have a script called "Item" attached to that?



    Also: WARNING? or ERROR? - warnings you can ignore (yellow) errors you cant (red)

    EDIT: according to the comment below the answer was:

    "Has never been set up"
     
    Last edited: Dec 9, 2014
  37. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    This is actually planned to be in the next update.

    Just 4 more days :D and sorry for making you wait guys.
     
  38. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Go to line 979 and replace this: "ItemScript = ActionItem.GetComponent("Item"); //Getting the item script." with this: "var ItemScript = ActionItem.GetComponent("Item"); //Getting the item script.". On JS, it shouldn't give you an error because of that but well it happens sometimes.
     
  39. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    heh. UnityScript. :p Bites you while you sleep.
     
  40. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Please don't feel rushed on my account. It's a lot of work to switch to the new Unity UI system, so take whatever time you need!
     
    OussamaB and hopeful like this.
  41. rizawerx

    rizawerx

    Joined:
    May 30, 2013
    Posts:
    38
    I haven't put anything..I just download and import...and wham! that error...

    I have put 'var' like you said but still error...

    first.jpg second.jpg

    first without change anything, second after I add "var"...
    I have delete C# folder since I don't use C#..
    I believe it related to my project, because if create new clean project and import your plugin, no error at all...
    I'm still reading the code..wondering which one...

    UPDATE
    Nevermind, I have fixed it..
    I just move "var ItemScript : Item;" to the top...now it works...hopefully doesn't break anything...
     
    Last edited: Dec 9, 2014
    OussamaB and twobob like this.
  42. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    That should be fine. sounds like a scope problem. looks like you fixed it.
     
  43. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Twobob, this might be excessively obscure, but I'm looking at how I'm going to implement S-Inventory once it's updated to the new UI, and while I'd been planning on having a single, generic container interface and messaging it with specific details each time you open something, the guide seems to like having a separate container script on each item. To that end, do you have any idea what the overhead for containers is like? I'm planning on having dozens or low hundreds of containers active at any one time, and if that's going to be a performance issue it'd be nice to start planning around it sooner than later :)
     
  44. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    You don't say what you are building for.

    Assuming "the worst Android device on earth" - send me an instance of an example Container class and I will try running a few hundred for you on such a device.

    The actual footprint - assuming a relatively tiny class - should be negligible, however I think you should consider batching/staggering your Update processing given the likely cpu impact of that.

    Only one way to tell. Profiler.
    Happy to look.
     
    OussamaB likes this.
  45. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Ack sorry, should've been more specific. :) In addition to general lootable objects (drawers, cabinets), I'm thinking of putting a container on each NPC to represent the contents of their pockets, both for the purposes of looting bodies and pickpocketing- it isn't implemented yet, and it can't possibly involve more than 70-100 containers at any one time (the level streams in and out, so most will be inactive), I was just checking in case they were a major system component, and the thought of adding more than a few at one time made you scream in horror. :)
     
  46. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    I have only tested this suite En passant.
    Since the new version is ready to drop in the next couple of days and the last version is frankly unusable on big numbers I shied away from any more dev time until it drops.

    My guts instinct is "That should be fine" but I would still consider batching/staggering the Updates,
     
  47. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Probably quite smart, I'll wait until 4.6 drops and take a tinker... would you mind posting your impressions on performance once it's out? I've learned a lot from your prior comments, and I need to start figuring out whether I can use this, or whether I need to dump 40-50 hours into learning and deploying my own inventory system :)
     
  48. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Certainly, Very happy to check this out,
     
  49. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Thanks, really appreciate it :)
     
  50. OussamaB

    OussamaB

    Joined:
    Feb 8, 2013
    Posts:
    1,470
    Actually, the update will only hit the asset store after making sure that it performs well with the profiler. Thanks to twobob for agreeing to run the required memory/CPU tests!
     
    hopeful and twobob like this.
Thread Status:
Not open for further replies.