Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Benjames · May 04, 2016 at 09:48 PM · listsremoveremoveat

C# list removeat then collapses.

I have a array of slots that I want to remove from a list. Using RemoveAt() that is..

When I remove an item the remaining list collapses, therefore the values of my array are off after one removal.

I can think of ways around this but I was wondering if anyone knows if there is a right way or best way?

Can I make some sort of Que, then just remove everything at once, then have it collapse afterward?

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 incorrect · May 04, 2016 at 09:54 PM 0
Share

Why do you need those indexes?

avatar image gjf incorrect · May 04, 2016 at 10:35 PM 0
Share

as @incorrect asks, what are you trying to achieve? a queue might be the answer, but we need to know the question ;)

avatar image Benjames · May 05, 2016 at 12:07 AM 0
Share

So I store slot numbers to a triangle array to later sort through and remove from my mesh. If I have a giant flat surface im gonna only want two triangles not 150. I've posted something like this but my data structure has changed so I have to "rethink" my code.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eno-Khaon · May 04, 2016 at 11:47 PM

I'm guessing you're going in ascending order through the elements removing values from the List.

When you do this, removing one means that every other after it is offset by one, then remove another and they're off by another.

If you want to remove values from a List without worrying about that, go from the end to the beginning when removing them.

 // C#
 for(int i = myList.Count - 1; i >= 0; i--)
 {
     myList.RemoveAt(i);
 }

http://answers.unity3d.com/questions/527571/c-using-lists-and-removeat.html

Comment
Add comment · Show 9 · 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
avatar image Benjames · May 04, 2016 at 11:56 PM 0
Share

I see what you are saying but I can't do that necessarily as I'm dealing with triangles and vertices on a grid and they are not in an order.

avatar image Eno-Khaon Benjames · May 05, 2016 at 02:01 AM 0
Share

Could you elaborate on that?

Are you working with existing meshes and extracting vertex/triangle data from them?

Are you collapsing them down based around removing vertices/triangles relative to each other? (Like, remove a vertex and it eli$$anonymous$$ates, say, 4 triangles sharing that vertex)

avatar image Benjames Eno-Khaon · May 05, 2016 at 06:46 AM 0
Share

Ins$$anonymous$$d of running through marching cubes then simplifying the large surfaces I'm thinking of finding them while marching cubes is doing its thing.

Show more comments
avatar image Benjames · May 05, 2016 at 02:29 AM 0
Share

http://answers.unity3d.com/questions/586474/mesh-simplification-for-marching-cubes-algorithm.html

I'm essentially revising my marching cubes implementation at that link. I have a way to remove the verts, and i have an unorganized array of ints that point to the triangle list slots I want to remove. I can't just iterate through the list and call removeat() otherwise my "pointer" ints will no longer point to the correct triangle.

avatar image Eno-Khaon Benjames · May 05, 2016 at 03:09 AM 0
Share

Yeah, that does make things a bit more complicated...

Either way, you'll need to appropriately assess which triangles reference each vertex. At that point, removing them would still make the most sense to do in order from back to front of the lists after sorting the elements to be removed from each at a time.

Actually keeping everything organized to that end is a different matter entirely, though. I haven't had a chance to work with the marching cubes algorithms, so I can't offer any first-hand experience on how to manage and improve efficiency of that yet.

avatar image incorrect · May 05, 2016 at 03:06 AM 0
Share

God, yet another wierd way. Here is how it's done properly.

List.RemoveAll $$anonymous$$ethod (Predicate)

avatar image Benjames incorrect · May 05, 2016 at 06:38 AM 0
Share

Removeall removes elements based on each items value vs an expression?

avatar image incorrect Benjames · May 05, 2016 at 01:13 PM 0
Share

Based on whatever predicate you make.

avatar image
0

Answer by incorrect · May 04, 2016 at 09:53 PM

Create a copy of your array. Remove elements from it. Assign the result in place of initial array.

Comment
Add comment · Show 4 · 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
avatar image Benjames · May 05, 2016 at 12:09 AM 0
Share

$$anonymous$$y work around is similar to this. I just change the value of slots I want to delete to something way off like 99999 then make a new array discluding anything with that value.

avatar image incorrect Benjames · May 05, 2016 at 12:21 AM 0
Share

You never should do like that.

avatar image incorrect Benjames · May 05, 2016 at 12:26 AM 0
Share

Can you post your code?

avatar image Benjames · May 05, 2016 at 02:13 AM 0
Share

I can't post code till at least tomorrow. I figured its not a good way but at least its better then using remove() over and over.

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

42 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with Lists and Remove 0 Answers

Remove and RemoveAt for List not working 1 Answer

How do I pull variables from an object in a list? 1 Answer

Removing item from list makes it appear at the bottom ? 1 Answer

How to remove parts from a string 1 Answer


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