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 mrday · Oct 01, 2014 at 02:04 AM · textassetcsvsemicolon

Problem reading csv file when last semicolon is missing

I have a csv file with this text inside

Cube;Mat_3;

Sphere;Mat_2;

Cylinder;Mat_6;

This is the script that load the file, reads its content and then assigns the materials to the relative objects.

 //Variables
 private var update : int;
 private var textAsset : TextAsset;
 private var oggetti = new Array ();
 private var materiali = new Array ();
 private var linee : String[];
 private var i : int;
 
 function Start () {
     //initialization
     update=1;
     i=0;
 }
 
 function Update () {
     //We need to update?
     if (update==1){
         //get text from a csv file
         textAsset = Resources.Load("settings", TextAsset);
         linee = textAsset.text.Split("\n"[0]);
         //handle the content in 2 string[] (object names, material names)
         for(i=1; i<linee.Length ; i++){
             if(linee[i]!=""){
                 oggetti.Push(linee[i].Split(";"[0])[0].ToString());
                 materiali.Push(linee[i].Split(";"[0])[1].ToString());
                 
             }
         }
         //for each object element set the material if the file exist 
         for(i=0; i<oggetti.length ; i++){
             //here is my problem
             if(Resources.Load(materiali[i], typeof(Material)) as Material){
                 gameObject.Find(oggetti[i]).renderer.material = Resources.Load(materiali[i], typeof(Material)) as Material;
             }
         }
         //we don't need to update again
         update=0;
     }
     
 }

My problem is: the csv file need, for each column, a final semicolon to load the right material, if the semicolon is missing, the material won't be loaded.

Example row:

Cube;Mat_2

Resouces.Load(materiali[i]) won't find the material

Example row:

Cube;Mat_2;

Resouces.Load(materiali[i]) will find the material

the strangest thing is that if I debug.log(materiali[i]) the console will output the same result. Using ToString() on materiali[i] doesn't helps, Excel saves the csv files without the last semicolon, so I need to add it by hand. There is a solution to make it work without manipulate the file? Thanks

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

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

2 People are following this question.

avatar image avatar image

Related Questions

UnityEngine.DefautAsset as TextAsset 1 Answer

How do I find a specific file type with getfiles? 1 Answer

Automatic CSV to TXT conversion [solved] 1 Answer

check for word in dictionary 3 Answers

ReadLine to a Variable 2 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