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 altropetrolio · Apr 30, 2020 at 10:54 AM · listaccessing from any scriptpublic static

Public Static List Dictionary access from another Script OUT OF RANGE ERROR

I've read all answers about access to lists from another scripts....but really unable to find out the problem. What I'm trying to do : I populate a List with Dictionary, reading data from a CSV (I've found a very good function somewhere CSVReader). Debug.Log works correctly (and also CSVReader works) To optimize my code and speed ( I think ), I want to read only one time the CSV and store it in a public static list. (actually I populate some DropdownMenu reading everytime CSV, creating List ecc ecc... just a copy/paste of code)

So I found the way to call the public static list after the initialization (I use a Button to avoid early reading before creation). But even if my public static List was created and worked... It seems like disapearing and accessing to List from another script give me OutOfRange Error

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class BootLoader_VideoGame : MonoBehaviour
 {
     [Tooltip("Inserire nome del File da cui prelevare la lista")]
     private string FileName="ListeSingole";
     
     
     public static List<Dictionary<string,object>> SingoleListe = new List<Dictionary<string,object>>();
     
     // Start is called before the first frame update
     void Start() {    
      // Legge il nome del file (deve essere in /Resource) e lo mette in una lista
       List<Dictionary<string,object>> SingoleListe = CSVReader.Read (FileName);
       Debug.Log("ListaSingole:"+SingoleListe[2]["CONSOLE"]);
     }
 
 }

Above I create the List and Debug.Log show me it is populated. Below I recall it...and give me OutofRange Error

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.IO;
 
 public class MakeCSV : MonoBehaviour
 {
     [SerializeField]
     private string FileNameCSV;
     
     public GameObject BootLoader;
     private string teststring;
     
     public void CreateCSV()
     {
         Debug.Log("TestString :" + BootLoader_VideoGame.SingoleListe[2]["CONSOLE"]);

Not sure...but can be CSVReader function delete my list every time is called (for example from Dropdown Scripts)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class DropDownScript : MonoBehaviour
 {
 
     [Tooltip("Punta al DropDown da popolare...")]
     public Dropdown Maindropdown;
     [Tooltip("Inserire nome del File da cui prelevare la lista")]
     private string FileName="ListeSingole";
     [Tooltip("Inserire nome della colonna da Popolare")]
     public string ColName;
  
  void Start () {
      
      // Legge il nome del file (deve essere in /Resource) e lo mette in una lista
      List<Dictionary<string,object>> data = CSVReader.Read (FileName);     
      Debug.Log("Test String : "+int.Parse((data[0][ColName]).ToString()));
      //clear/remove all option item
      Maindropdown.options.Clear ();
      //fill the dropdown menu OptionData with all COM's Name in ports[]
      for(var i=1; i < (int.Parse((data[0][ColName]).ToString())+1); i++)
      {
          // Popola il DropDown con il contenuto della lista
          Maindropdown.options.Add (new Dropdown.OptionData((data[i][ColName]).ToString()) );
      }
      
      //Refresh the visual DdMenu
      Maindropdown.RefreshShownValue();
  }
  
 }


Not really important...but I like speed and clean (even if I'm not a programmer) To resume : I only want to create a Single Public Dictionary List from a CSV and access to it every time I want and need. But after creation it can't be accessed from others scripts.

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

1 Reply

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

Answer by ShadyProductions · Apr 30, 2020 at 11:03 AM

 void Start() {    
   SingoleListe = CSVReader.Read(FileName);
   Debug.Log("ListaSingole:"+SingoleListe[2]["CONSOLE"]);
 }

It should be like this, otherwise you are specifying a local variable. Also make sure that this script runs before the other scripts. (Script Execution Order)

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 altropetrolio · May 09, 2020 at 06:33 AM 0
Share

I've figured out...yes it was simple when you know how to do. Thank you for your reply

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

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

Accessing a list from another script 2 Answers

Access List from another script 0 Answers

Acces list from another script 2 Answers

C# List of Files 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