Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pickle chips · Jul 02, 2013 at 01:34 AM · arraylistinventoryitemshift

Preventing Items from shifting in a list

I'm using a list for the inventory, and when the player drops an item (Inventory.remove(index)) all of the items in the inventory shift up a spot to fill in the empty space. My question is:

Is there a way to stop this from happenning?

Should I be using an array?

If I use an array how would I add an item to the inventory (Equivalent to list.add)?

Does anyone have any suggestions?

Thanks

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Jul 02, 2013 at 02:11 AM 0
Share

Without seeing your code, this becomes just a discussion question. Consider creating a item for your inventory called 'No Item'. When you drop an item, you would place a 'No Item' in the list. When adding an item, you would first search out any slots that have 'No Item' in the slot and replace them, only adding a new item to the end of the list if no 'No Item' slots are found.

avatar image ebogguess · Jul 02, 2013 at 03:10 AM 0
Share

I'll suggest another approach. If you are modeling an inventory with a certain number of slots, an array might be exactly what you are looking for. You could quickly check if any inventory slots are empty by walking the array, looking for nulls. If you find a null, add the inventory item to that index. If not, tell the player that they don't have space for a new item.

avatar image pickle chips · Jul 02, 2013 at 08:41 PM 0
Share

Actually using an array does sound appealing to me now, and it would also allow me to be able to click and drag things around the inventory as well. I think I will remodel my system to implement an array

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pborg · Jul 02, 2013 at 03:08 AM

You could set each element to be a class (if not already); in each list add a Boolean called canbeseen. if a player or any other script tries to view the list or modify it just set it so that it won't be shown unless canbeseen. When you try to place something in that spot, just overrideit. Hope this helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scroll List Problem 1 Answer

Setting generic list length 2 Answers

Can't add GameObjects to ArrayList 1 Answer

A node in a childnode? 1 Answer

How can I store game data outside of scripts.(e.g Total list of inventory items) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges