Search Unity

Win32 IO returned ERROR_INVALID_NAME (block entire script)

Discussion in 'Scripting' started by NSA23, Aug 29, 2018.

  1. NSA23

    NSA23

    Joined:
    Sep 23, 2013
    Posts:
    8
    Hello there,

    I am getting a error who is very annoying and i can't figurate out. I am hoping someone already has something like this and help me with that. This error block the script at the beginning...

    Thank you !

    Script :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. using System.IO;
    4. using System.Collections;
    5.  
    6.  
    7. public class FirstRun : MonoBehaviour
    8. {
    9.     void Awake ()
    10.     {
    11.         CreateFirstLoadFile ();
    12.     }
    13.  
    14.     public void CreateFirstLoadFile()
    15.     {
    16.         // Choose the output path according to the build target.
    17.         string outputPath = Path.Combine(GetPathBasedOnOS(), "IsFirstLoadFile");
    18.         if (!Directory.Exists(outputPath))
    19.         {
    20.             Reset ();
    21.             Directory.CreateDirectory(outputPath); //ERROR HERE
    22.             Debug.Log("No file, reset all");
    23.         }
    24.         else
    25.         {
    26.             SceneManager.LoadScene("Home");
    27.             Debug.Log("There is a file, loading home");
    28.         }  
    29.     }
    30.  
    31.     private static string GetPathBasedOnOS()
    32.     {
    33.         if (Application.isEditor)
    34.             return "file://" + Application.persistentDataPath + "/";
    35.         //else if (Application.isWebPlayer)
    36.             //return System.IO.Path.GetDirectoryName(Application.absoluteURL).Replace("\\", "/") + "/";
    37.         else if (Application.isMobilePlatform || Application.isConsolePlatform)
    38.             return Application.persistentDataPath;
    39.         else // For standalone player.
    40.             return "file://" +  Application.persistentDataPath + "/";
    41.     }
    42.  
    43.  
    44.     private void Reset()
    45.     {
    46.         PlayerPrefs.DeleteAll ();
    47.  
    48.         //Music default
    49.         PlayerPrefs.SetInt("KeyRef", 1);
    50.         AudioListener.volume = 1;
    51.  
    52.         PlayerPrefs.Save();
    53.         SceneManager.LoadScene("Language");
    54.     }
    55. }
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,848
    Looks like you have a recursion here. Error may be related to creating a filepath with too many nested folders which makes pathname too long (2048 characters or so, there is a limit in Windows but I can‘t say exactly what it is).

    The callstack repeats a lot. You should attach debugger and step through to see what‘s happening.
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What is the runtime value of outputPath?
     
  4. NSA23

    NSA23

    Joined:
    Sep 23, 2013
    Posts:
    8
    Hello,

    Thanks for your answer. After some little modifications, the error is still here but everything is now working well. So i think i will let that for the moment. I'll let you after resolution of this error.

    Thank you!
     
  5. yasith321w

    yasith321w

    Joined:
    Oct 4, 2019
    Posts:
    2
    IOException: Win32 IO returned ERROR_INVALID_NAME. Path: D:\Augmented Reality\Load Scene From Bundle\Assets\DLC\uc?export=download&id=1QQPUgh7hXYK8bHJBpOSW9h3EQgrTe7VO.

    Can anyone help me with this problem?
     
  6. yasith321w

    yasith321w

    Joined:
    Oct 4, 2019
    Posts:
    2
    Thankyou for this answer. This helped me a lot in fixing the problem after 24 hours.