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 chris666 · Oct 12, 2016 at 11:48 PM · gameobjectlistadd

List().Add freezes Unity

I have a method that I try call and it just freezes when it reaches the biggestTiles.Add (list [x, y]);. I've tried eliminating every single line, and I'm pretty sure that's the cause of the freeze. It doesn't seem to have a problem with adding it to a completely new List of GameObjects inside the loops, but the biggestTiles List just doesn't seem to like that specific GameObject, or something. The tiles are not null or destroyed. And I can't even debug the error since Unity hangs before anything can be printed. Commenting those lines makes the game run fine, but without the intended functionality.

 public void ChooseWeakPoint(GameObject[,] list){
         //Loop trough tiles to check for highest elapsedToBuff
         var biggestTiles = new List<GameObject>();
         float biggestValue = 0f;
         for (int x = 0; x < 5; x++) {
             for (int y = 0; y < 3; y++) {
                 var comp = list [x, y].GetComponent<BattleButton> ();
                 if(comp.buffCoroutine == null && comp.elapsedToBuff > biggestValue && comp.ButtonState != ButtonStates.Disabled && comp.ButtonState != ButtonStates.Occupied ){
                     biggestValue = comp.elapsedToBuff;
                     biggestTiles.Clear();
                     //biggestTiles = new List<GameObject>(); // Tryed using instead of Clear(). Still doesn't work.
 
                     //var newList = new List<GameObject> (); // Creating a new list inside the loop seems to work
                     //newList.Add (list [x, y]);             // It added the GameObject with no problem.
                     //biggestTiles.AddRange (newList);       // But when trying to add it to biggestTiles, it freezes Unity.
 
                     biggestTiles.Add (list [x, y]);          // THIS FREEZES UNITY
                 } else if (comp.elapsedToBuff == biggestValue) {
                     biggestTiles.Add (list [x, y]);          // THIS ALSO FREEZES UNITY
                 }
             }
         }
         //Choose a tile from the selected biggestTiles
         if(biggestTiles.Count > 0){
             int rand = Random.Range (0, biggestTiles.Count);
             GameObject chosenTile = biggestTiles [rand];
             chosenTile.GetComponent<BattleButton> ().elapsedToBuff = -999;
             chosenTile.GetComponent<BattleButton> ().FadeTileForBuff (3f,ElementTypes.WeakPointBuff);
         }
     }
Comment
Add comment · Show 1
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 meneliki3 · Nov 22, 2020 at 12:03 AM 0
Share

I know this is an old thread, but I seem to be having the exact same problem. I've reached out to a few different dev communities and nobody seems to know what's going on.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

null referance when adding to a list please help 1 Answer

Get a selected item from a GameObject list? 0 Answers

Add inactive objects to list 0 Answers

Insert object to the list in the script in real-time. 1 Answer

What range of values need to be inserted if we need to pull a random item from the list? 0 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