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 /
avatar image
0
Question by betapowers · Feb 04, 2018 at 05:59 PM · errorclassstatic

cannot be assigned to (it is read-only) Problem

I have been trying to change a non static class but when I try to do so I seem to get errors, even when I change the class to a static.

If anyone knows how to accomplish this task I would like to know.

This is the code that has been giving me the error:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Xml;
 using System.Xml.Serialization;
 using System.IO;
 
 public class SaveData : MonoBehaviour {
 
     public static SaveData ins;
     public bool LoadTiles;
     public bool MatchLists;
     public List<string> RoomName;
 
 
     public int LeftWall;
     public int RightWall;
     public int FrontWall;
     public int BackWall;
 
     // Use this for initialization
     void Awake () {
         ins = this;
     }
 
     public LocalGridNumber GridNumberDB;
 
 
     public GameObject SelectedRootObject;
 
     void Load (){
         LocalGridNumberEntry.LoadTiles ();
     }
 
 
     public string RoomDisplay; // to list individual rooms
     void Update(){
 
         LocalGridNumberEntry.Load1 = LoadTiles;
 
 
         if (LocalGridNumberEntry.Load1 == true) {
             LocalGridNumberEntry.LoadTiles ();
         }
 
 
         if (MatchLists == true) {
             LocalGridNumber.list.Count = RoomName.Count; // The error 
 
         }
 
         LocalGridNumberEntry.Room = RoomDisplay;
 
         LocalGridNumberEntry.RightWall = RightWall;
         LocalGridNumberEntry.LeftWall = LeftWall;
         LocalGridNumberEntry.FrontWall = FrontWall;
         LocalGridNumberEntry.BackWall = BackWall;
 
     }
 
 
 
 }
 
 
     // Serialize
 
 
 // 0 is Left
 // 2 is Right
 // 1 is Back
 // 3 is Front
 
 
     [System.Serializable] // localgridnumber
     public class LocalGridNumberEntry{
         
     public static GameObject TileObject;
     public static bool Load1;
 
     public static string Room; // to list individual rooms
 
     public static int LeftWall;
     public static int RightWall;
     public static int FrontWall;
     public static int BackWall;
 
     public static void LoadTiles(){
         TileObject = GameObject.Find (Room);
         if (TileObject != null) {
             Debug.Log (Room);
             TileObject.GetComponent<GridLifeSupport> ().ActiveObjectSet = true;
             TileObject.GetComponent<GridLifeSupport> ().SelectPointVar0 = LeftWall;
             TileObject.GetComponent<GridLifeSupport> ().SelectPointVar1 = BackWall;
             TileObject.GetComponent<GridLifeSupport> ().SelectPointVar2 = RightWall;
             TileObject.GetComponent<GridLifeSupport> ().SelectPointVar3 = FrontWall;
         }
     }
         
 
 }
 
 
         //////// Game Data
     [System.Serializable]
     public class LocalGridNumber{
     public static List<LocalGridNumberEntry> list = new List<LocalGridNumberEntry>();        
     }
         
 
 
 
 //    [System.Serializable]
 //    public class GameStateOverall{
 
     //////// Game Settings
 
 //    public bool GameState; // BuildMode true or false?
 
 
 
 //    }
 
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Commoble · Feb 04, 2018 at 06:57 PM

Is LocalGridNumber.list a List or similar object?

If so, you can't change the Count field of that object. The Count field is read-only because it tells you how many things are in that list. It cannot be set directly, though it will automatically change when you add or remove something from that list.

Comment
Add comment · Show 2 · 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 betapowers · Feb 04, 2018 at 08:46 PM 0
Share

"list" is a List type of such, basically what I want to accomplish is to have another separate List with values each different and basically set the "list" to the amount of values in the other List, and then set each field to the values in the other List.

By the way, do you know how to add to the list to increase the size?

avatar image Commoble betapowers · Feb 04, 2018 at 10:59 PM 0
Share

You can find the documentation for most things by googling. Here's the documentation for the List class

avatar image
1

Answer by ElijahShadbolt · Feb 04, 2018 at 09:10 PM

Given you have another List<LocalGridNumberEntry>somewhere,

     // for each index in other list,
     for (int i = 0; i < otherList.Count; ++i)
     {
         if (i < LocalGridNumber.list.Count) {
             // replace old value in list.
             LocalGridNumber.list[i] = otherList[i];
         } else {
             // add new value to list.
             LocalGridNumber.list.Add(otherList[i]);
         }
     }
     // remove elements that are not in the old list.
     LocalGridNumber.list.RemoveRange(otherList.Count, LocalGridNumber.list.Count);

Note that since LocalGridNumberEntry is a class, this code changes the list by only adding a reference to the old LocalGridNumberEntry instance, without copying every field across to a new instance.

You may want to change the code a bit. I think your LocalGridNumberEntry fields should not all be marked static, because that means each new LocalGridNumberEntry instance does not have different values.

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

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

Related Questions

Error Assigning GameObject To Var Inside A Class 3 Answers

MonoBehaviour methods in non-MonoBehaviour class 1 Answer

Public class used in another class (C#) 1 Answer

Access function (and variable) outside class in the class in Javascript. 1 Answer

Update() in non-component script? 3 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