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 BitMax · Nov 15, 2013 at 04:46 AM · crashlistarrays

Unity Crash on Adding to List Array, bug?

Hey guys, I am creating a custom editor and I have a list array of custom class. What I want to do is empty that array and dump a new array into the original one.

What I am doing:

 //serialize original list array
 IFormatter formatter = new BinaryFormatter();
 Stream stream = new FileStream("Assets/Resources/LevelGFX_" + currentLevelID.ToString() + ".bin", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
 formatter.Serialize(stream, test.Stages);
 stream.Close();
 
 //retrieve previously serialized list array and insert into obj variable
 IFormatter formatter = new BinaryFormatter();
 Stream stream = new FileStream("Assets/Resources/LevelGFX_" + currentLevelID.ToString() + ".bin", FileMode.Open, FileAccess.Read, FileShare.Read);
 List<CStage> obj = (List<CStage>) formatter.Deserialize(stream);
 stream.Close();
 
 //clear original array and insert obj array into orignal array
 foreach(CStage s in test.Stages.ToArray())
 {
    test.Stages.Remove(s);
 }
 foreach(CStage s in obj)
 {
    test.Stages.Add(s);    
 }

Here is the CStage Class:

 using UnityEngine;
 using System.Collections;
 using System;
 
 [Serializable]
 public class CStage {
     
     public string StageName = "New Stage";
     public float StartTime = 0F;
     public float EndTime = 150F;
     public float SpeedMin = 1F;
     public float SpeedMax = 2F;
     public float MinSize = 2F;
     public float MaxSize = 4F;
     public float speed = 1F;
     public float ZDepth = 5F;
     public float Frequency = 2F;
     public bool Sequential = false;
     public float SequentialFudge = 2F;
     public float RotationY = 0F;
     
     
     [NonSerialized()] public GameObject EntryModel;
     [NonSerialized()] public GameObject[] InbetweenModels = new GameObject[5];
     [NonSerialized()] public GameObject ExitModel;
     
     public bool FlipRandomally = false;
     public bool RandomizeRotation = false;
     [NonSerialized()] public Color TintMin = Color.white;
     [NonSerialized()] public Color TintMax = Color.red;
     
     //pos
     [NonSerialized()] public Vector2 XminMax = new Vector2(-5F, 7F);
     [NonSerialized()] public Vector2 YminMax = new Vector2(-4F, 4F);
     [NonSerialized()] public Vector2 ZminMax = new Vector2(0F, 8F);
     
     //internal
     public bool selected = false;
     public int gridY = 0;
     public int buttonWidth = 100;
     public int buttonHeight = 60;
     public bool modelsFoldout = false;
     public bool additionalFoldout = false;
     public bool stopped = false;
     public float rendererx = 5F;
     
     //test
     public GUIStyle gstyle = new GUIStyle();
     public bool colorSet = false;
     
     //state
     public enum stateM
     {Middle, Entry, End}
     public stateM state = stateM.Entry;
 
 }
 

However this causes Unity to crash. Any ideas will be greatly appreciated!

Comment
Add comment · Show 13
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 flamy · Nov 15, 2013 at 04:51 AM 1
Share
 test.Stages.clear();
 
 foreach(CStage s in obj)
 {
    test.Stages.Add(s);  
 }


clear list and add ins$$anonymous$$d of removing in a fashion that doesnt sound good. you are doing ToArray() in for each any specific reasons?

avatar image BitMax · Nov 15, 2013 at 05:35 AM 0
Share

I did ToArray in clear because otherwise it would give me this error: InvalidOperationException: Collection was modified; enumeration operation may not execute.

avatar image flamy · Nov 15, 2013 at 05:38 AM 0
Share

ins$$anonymous$$d of for each just use .clear (); and try

avatar image BitMax · Nov 15, 2013 at 05:42 AM 0
Share

Yeah I gave it a try but the error remains, the problem isnt in clear but in adding the obj array to the original one.

avatar image flamy · Nov 15, 2013 at 06:01 AM 0
Share

wat is the datatype of test.Stages

Show more comments

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

19 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

Related Questions

A node in a childnode? 1 Answer

How to store gameobjects with specific scripts in a list ? 1 Answer

Populating a list in the editor 2 Answers

Adding Item object to Inventory List 0 Answers

Unable to serialize my list in a Unity Custom Editor script. 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