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 rottweiler · Feb 14, 2013 at 12:47 PM · path

the specified path is not of a legal form

Hello. I have a script that moves my objects to waypoint:

 using UnityEngine;
 using System;
 using System.Collections;
 using System.IO;
 
 public class Move : MonoBehaviour {
 public string fileName = "Settings.ini";
 Transform[] waypoint;
 private float speed;
 private float animspeed;
 private int currentWaypoint;
 private int rnd;
 Vector3 velocity;
 
 void  Start (){        
         
          using (StreamReader fileStream = File.OpenText(Path.GetFullPath(fileName)))
         {
            
             string fileLine = "";
             while ((fileLine = fileStream.ReadLine()) != null)
             {
                 string option = fileLine.Substring(0, fileLine.IndexOf("="));
                 switch (option)
                 {                    
                     case "speed":
                         speed = Convert.ToSingle(fileLine.Substring(fileLine.IndexOf("=") + 1));
                         break;
                     case "animspeed":
                         animspeed = Convert.ToSingle(fileLine.Substring(fileLine.IndexOf("=") + 1));
                         break;
                     }
 
             }
            
             fileStream.Close();
         }
             
 animation["fly"].speed = animspeed;
     waypoint = new Transform[3];
     rnd = UnityEngine.Random.Range(1,5);
         
            
     if(rnd == 1){            
             currentWaypoint = 0;
             waypoint[0] = GameObject.Find("waypointRU1").transform;
             waypoint[1] = GameObject.Find("waypointRU2").transform;
             waypoint[2] = GameObject.Find("waypointRU3").transform;
         }
         if(rnd == 2){            
             currentWaypoint = 0;
             waypoint[0] = GameObject.Find("waypointRD1").transform;
             waypoint[1] = GameObject.Find("waypointRD2").transform;
             waypoint[2] = GameObject.Find("waypointRD3").transform;
         }
         if(rnd == 3){            
             currentWaypoint = 0;
             waypoint[0] = GameObject.Find("waypointLU1").transform;
             waypoint[1] = GameObject.Find("waypointLU2").transform;
             waypoint[2] = GameObject.Find("waypointLU3").transform;
         }
         if(rnd == 4){            
             currentWaypoint = 0;
             waypoint[0] = GameObject.Find("waypointLD1").transform;
             waypoint[1] = GameObject.Find("waypointLD2").transform;
             waypoint[2] = GameObject.Find("waypointLD3").transform;
         }
 }
 
 void  Update (){
     if(currentWaypoint < waypoint.Length){
         Vector3 target = waypoint[currentWaypoint].position;
         Vector3 moveDirection = target - transform.position;        
         velocity = rigidbody.velocity;
         
         if(moveDirection.magnitude < 1){
             currentWaypoint++;
             }
         else{
             
             velocity = moveDirection.normalized*speed;
             }    
         
 }
 rigidbody.velocity = velocity;
 
 }
 
 void  LateUpdate (){
 Vector3 target = waypoint[currentWaypoint].position;
             transform.LookAt(target);    
     
 }
 }

In the Editor its work fine, but when i buid and run my game i have an error, something like this: the specified path is not of a legal form. How fix that?

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
0
Best Answer

Answer by Dave-Carlile · Feb 14, 2013 at 12:49 PM

Look in the folder where you're running the game. Does settings.ini exist in the same folder as the executable? If settings.ini isn't part of your Unity project, it won't get copied to the final build.

After looking at your log file, your filename variable is empty...

 public string fileName = "Settings.ini";

Public properties like this show in the inspector and allow you to edit them there. The value in the inspector always overrides any initialization you do when declaring the variable. If you look at this value in the inspector, what does it show?

Comment
Add comment · Show 9 · 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 rottweiler · Feb 14, 2013 at 01:53 PM 0
Share

Yes it exists. Log says that i have error in this line: if(currentWaypoint < waypoint.Length){ and this: Vector3 target = waypoint[currentWaypoint].position;

avatar image rottweiler · Feb 14, 2013 at 02:08 PM 0
Share

But when i not use stream reader ( didnt take parametr from file) its work.

avatar image Dave-Carlile · Feb 14, 2013 at 02:10 PM 0
Share

The error you mention would be caused by file IO.

 File.OpenText(Path.GetFullPath(fileName))

Before that line, add Debug.Log calls to display fileName, and the resulit of the GetFullPath call...

 Debug.Log("filename=" + fileName);
 Debug.Log("fullpath=" + Path.GetFullPath(fileName));

See what that shows.

avatar image rottweiler · Feb 14, 2013 at 02:23 PM 0
Share

I have next errors in log:

 filename=
 UnityEngine.Debug:Internal_Log(Int32, String, Object)
 UnityEngine.Debug:Log(Object)
 $$anonymous$$ove:Start() (at C:\BatGame\Assets\Scripts\$$anonymous$$ove.cs:17)
  
 (Filename: C Line: 0)
 
 ArgumentException: The specified path is not of a legal form (empty).
   at System.IO.Path.InsecureGetFullPath (System.String path) [0x0002c] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.IO/Path.cs:336 
 
   at System.IO.Path.GetFullPath (System.String path) [0x00000] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.IO/Path.cs:289 
 
   at $$anonymous$$ove.Start () [0x00015] in C:\BatGame\Assets\Scripts\$$anonymous$$ove.cs:18 
  
 (Filename: C Line: 0)
 
 NullReferenceException: Object reference not set to an instance of an object
   at $$anonymous$$ove.LateUpdate () [0x00000] in C:\BatGame\Assets\Scripts\$$anonymous$$ove.cs:100 
  
 (Filename: C Line: 0)
avatar image Dave-Carlile · Feb 14, 2013 at 02:29 PM 0
Share

Notice how your fileName variable is empty - it has no value. I updated my answer with what is likely causing the issue.

Show more comments

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

10 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

Related Questions

How to move an object linearly along a bezier spline 1 Answer

How can i loop my path instead of it ending on the lasat point 1 Answer

Waypoint Setup: How? 4 Answers

particle spawn issue. 0 Answers

Having trouble with implementing circular player movement 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