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 upariver · Nov 17, 2016 at 11:55 AM · serializationserializeforloop

For loop within Serializable class?

I currently have this, however if I add the for loop it doesn't work . Could anyone point me out any tips?

http://pastebin.com/74BXFQa7

Comment
Add comment · Show 2
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 Landern · Nov 17, 2016 at 02:11 PM 0
Share

What do you mean it doesn't work, no one knows what is in player parameter(of type UI_Holder) of the constructor. No one knows why you're using a loop and breaking after the first iteration. You need to supply more information then it doesn't work, is there an exception, are you having issues because only the first element is being applied(that is because you're breaking out of the for loop at the end of the first iteration). If you want to be helped, help yourself by explaining in detail what is going on, what typical data exists in the player variable and what you're expectations are.

avatar image upariver Landern · Nov 17, 2016 at 02:23 PM 0
Share

Okay. Answering your questions:

"why you're using a loop and breaking after the first iteration" - A suggestion made by someone. Didn't work, but since I was still looking for a solution, forgot to remove it.

"more information then it doesn't work" - I have Lists of containers that each have their own points and name. As such, I searched and found you cannot save prefabs, however you can store their variable values in Lists and then respawn them using those values.

As such, I need a for loop to go through the whole List of prefabs in order to get each value of each list element to store them.

There are no exceptions, it works fine with single variables, but when I try to use a for loop to store something, it doesn't work. So if I do

 [Serializable]
 public class PlayerData
 {
 
  public bool SetupComplete;
 
 public PlayerData(UI_Holder player)
     {
  SetupComplete = player.isSetupComplete;
    }
 }

If I use my Load function, it will load this bool value just fine. However, If I try to store values inside a list using a for loop the game saves no values at all.

 [Serializable]
 public class PlayerData
 {
 
     public int[] ChildrenPoints;
     public string[] ChildNames;
 
 public PlayerData(UI_Holder player)
     {
 for( int i=0; i < ChildNumber; i++)
         {
             ChildrenPoints[i] = player.Children[i].GetComponent<ChildScrollContainer>().ChildPoints;
             ChildNames[i] = player.Children[i].GetComponent<ChildScrollContainer>().ChildName;
             
         }
 
    }
 }

Hope this was able to explain the issue better.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hexagonius · Nov 17, 2016 at 10:54 PM

tried doing this before looping?

 ChildNames = new string[ChildNumber];
 ChildrenPoints = new int[ChildNumber];
Comment
Add comment · Show 1 · 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 upariver · Nov 18, 2016 at 10:45 AM 0
Share

Thank you very much!

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

80 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

Related Questions

Exlcude fields from JsonUtility but still serialise them? 1 Answer

Arrays not serializing 1 Answer

Serialization Placeholder Value for Different Fields? 1 Answer

Serializing pickups? 0 Answers

Question about Unity serialize system 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