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 GerardMe · Nov 09, 2015 at 01:07 PM · c#save-to-filetxtreading data

Reading .txt file c# problem

Hello I made a Terrain Detail Script with saving the changes to a .txt file. But the problem is the loading doesn't work. Can anyone help me?

 using UnityEngine;
 using System.Collections;
 using System.IO;
 using System.Text;
 
 
 
 public class QualityManager : MonoBehaviour {
 
     public float detailMesh;
     public float detailTexture;
     private string rawText;
     private string[] rawArray;
     private int intworker;
 
     // Use this for initialization
     void Start () {
         Debug.Log ("start");
         Load();
 
 
         Terrain.activeTerrain.heightmapPixelError = detailMesh;
         Terrain.activeTerrain.basemapDistance = detailTexture;
     }
 
     void Load()
     {
         rawArray = File.ReadAllLines("qualityManager.txt");
         foreach(var line in rawArray)
         {
             if(line.Length < 2 || line.Substring(0, 2) == "//")
                 continue;
             else if(line.Substring(0, 19) == "Terrain Mesh Detail")
             {
                 rawText = line.Substring(22, 30);
                 int.TryParse(rawText, out intworker);
                 detailMesh = intworker;
                 Debug.Log ("read 1");
                 continue;
             }
             else if(line.Substring(0, 22) == "Terrain Texture Detail")
             {
                 rawText = line.Substring(25, 30);
                 int.TryParse(rawText, out intworker);
                 detailTexture = intworker;
                 Debug.Log ("read 2");
                 continue;
             }
         }
 
     }
 }


But the save function does work.

 public void Save()
     {
         rawText = "//Quality System Info save file, version 1 \r\n" +
                 "Terrain Mesh Detail = " + detailMesh + " \r\n" +
                 "Terrain Texture Detail = " + detailTexture + " \r\n";
 
         File.WriteAllText("qualityManager.txt", rawText);
     }


I have no idea what's wrong, please help me.

Comment
Add comment · Show 5
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 Dave-Carlile · Nov 09, 2015 at 01:07 PM 0
Share

"Doesn't work" is not helpful information. What errors are you getting? What is the expected behavior, what is actually happening? Describe your problem in detail.

avatar image GerardMe Dave-Carlile · Nov 09, 2015 at 01:53 PM 0
Share

It doesn't do anything, I expect it to read the variables from the .txt file and use them in the terrain settings so players can change the settings from an options screen. Also there are no errors.

avatar image Dave-Carlile · Nov 09, 2015 at 02:00 PM 0
Share

You have log messages in there. Do any of them display? Does it get into the foreach loop at all? Add Debug.Log statements before if statements and log the values that the if statements are checking. Log the line itself right after foreach. Does it contain values you're expecting?

avatar image GerardMe Dave-Carlile · Nov 09, 2015 at 02:41 PM 0
Share

I get only the start debug. The complete loading function doesn't work.

avatar image Dave-Carlile GerardMe · Nov 09, 2015 at 03:32 PM 0
Share

Okay then, you'll need to go through and add the debug messages like I mentioned. Either that or use the debugger to step through the code. Start with one right after foreach.

 Debug.Log("Line: " + line);

If it doesn't get there then the file it's trying to read is empty. If it logs something then do the values you see match up with the parsing that you're doing? Do the first 19 characters of any of the lines equal "Terrain $$anonymous$$esh Detail"?

Also, let's see the file that's being written out by Save.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I save coordinates to a text file? 2 Answers

Cycle through different txt files to update positions 0 Answers

Save Blendshape values 0 Answers

How to read Excel files in Unity? 5 Answers

Xml Serialization - Does not save anything. 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