Brackeys Inventory System C# (FIXED)

Updated on April 14, 2017 in  [R] Scripts
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
0 on October 26, 2015

Hi! Thank you for your awesome work!!
Unfortunatelly I get an error when I try to pick up an item:

ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds
System.Array.Copy (System.Array sourceArray, Int32 sourceIndex, System.Array destinationArray, Int32 destinationIndex, Int32 length) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Array.cs:977)
System.Array.Copy (System.Array sourceArray, System.Array destinationArray, Int32 length) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Array.cs:936)
System.Collections.ArrayList.CopyTo (System.Array array) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/ArrayList.cs:3053)
Inventory.AddItem (UnityEngine.Transform Item) (at Assets/Inventory/Scripts/Inventory.cs:66)
Item.PickUpItem () (at Assets/Inventory/Scripts/Items/Item.cs:110)
FirstPersonPickUp.Update () (at Assets/Inventory/Scripts/Items/FirstPersonPickUp.cs:75)

It seems that I am not the only one since I found this thread: http://forum.unity3d.com/threads/inventory-system-from-brackeys.245201/
But since it is quite old now, you might have changed some stuff since…
Don’t you have this problem?
What would you suggest to fix it?

 

  • Liked by
Reply
Cancel
3 on October 26, 2015

Hi, did you download the latest version from this thread? As that was an issue in an older version

on October 26, 2015

Yes, it is the version you labeled as “(Most recent as of 5/10/2015)”

Inventory.rar
22 days old ·  71,25 MB

I just double-checked… So, you managed to fix it on your side? O.o
I will try to investigate your latest changes…

(Thanks alot for your reactivity !)

on November 6, 2015

Hi again,
I fixed the problem adding that line just before line 66 in Inventory.cs

       Contents = new Transform[newContents.Count]; //Ycar
l66:   newContents.CopyTo (Contents);//Array to unity builtin array
Devoted
on November 8, 2015

Sorry, i forgot to mention that you need to set the size in the inspector for the contents before you run the game!
The error was probably due to that; and your extra line should help to handle that occurrence, thank you.
I’ll upload it again :)

Show more replies
  • Liked by
Reply
Cancel
2 on November 8, 2015

Is there a way to edit my original post instead of posting all these updates as new discussions?
(Most recent Inventory as of 08/11/2015)
C# Brackeys Inventory System

Make sure that when you add ‘Inventory.cs’ to the player, you give it an initial amount of inventory slots. If you don’t, it may give you an error.
Will fix this later on.

on November 8, 2015

There is usually a pencil for editing your posts in the top right hand corner of them, I guess there is one as well for he original one (?).

The update you posted is the old version, 5 weeks old.

I think I found a mistake in Character.cs :

void UnequipItem ( Item i ){
...
 //If it's a weapon we call the RemoveWeapon function.
 if (i.itemType == "Weapon")
 {
    RemoveWeapon(i);
 }
...
}

should be replaced by:

void UnequipItem ( Item i ){
...
//If it's a weapon we call the RemoveWeapon function.
if (i.isAlsoWeapon)
{
    RemoveWeapon(i);
}
...
}

In particular if one’s slots are not named “Weapon”.

I still have some buggy behaviours, but it’s probably due to the fact that I’m drastically forking from you by now :)
Thanks a lot for your great support !

Devoted
on November 8, 2015

As this is a port over from Brackeys JavaScript system, I can’t change that (it should be exactly the same as that version)
In regards to editing, when I look at my post I can’t see the ‘edit’ pencil :/
As for the link; yeah I re-linked the old one as I wasn’t at a computer to re-upload a new version.
I’ll re-upload when I can, but it won’t have that change to weapon unequiping unless I receive approval from whoever handles this kind of stuff aha

Show more replies
  • Liked by
Reply
Cancel
1 on December 9, 2015

IS this only for pc platforms? or does it support android too. I’m having trouble installing either C# or the official one

Devoted
on December 9, 2015

Hey, this system uses controls for PC.
The system itself should be able to be used on a different platform, but it would need some tweaking in controls.
As I don’t create games for Android however, I’m not certain about that.
What are the issues you are having?

Show more replies
  • Liked by
Reply
Cancel
0 on February 10, 2016

I cry… The system doesn’t work with unity 5… there are non-functional API’s :/…

  • Liked by
Reply
Cancel
2 on March 1, 2017

Can’t find the files in Download link. :/

Master
on March 1, 2017

This is an old version and probably out-dated to the point where it would break in the later versions of Unity

Devoted
on March 1, 2017

I’m no longer updating this system as I ported it across for myself but fixed it up a bit.
Someone above said it wasn’t working in unity 5, and there are newer – easier ways to create an inventory now anyway.
If you’d like I can provide a new download link but it will need to be debugged and updated to the new version.

Show more replies
  • Liked by
Reply
Cancel
1 on April 13, 2017

Is this file has been remove? i can’t find it

Master
on April 14, 2017

It is very outdated

Show more replies
  • Liked by
Reply
Cancel