What are the characters that should not be added into a path name when saving a file?

I am saving a game file by using Path = Application.persistentDataPath + " \ " + "NameGivenByPlayer". The player can change what the “NameGivenByPlayer” is and that name will be saved with the games path. I know there are certain characters that cannot be in the file path name when it is saved such as just a space or question mark. Since the user can input these characters I need to block them from allowing the file to be saved with these characters or else an error will occur: UnauthorizedAccessExecption: Access to path … is denied.

What are all the characters that the player should be blocked from inputting into the path name?

I’ve found another solution to my problem, if you are using the InputField component there is actually a bunch of settings that permit only certain characters to be inputted into the InputField. The “AlphaNumeric” setting was exactly what I needed. Now when a player enters text into the InputField it is first checked to see if it is Alphanumeric, if it is then it is added to the InputField otherwise the character is not added.

I hope this is the answer you are looking for; I have never done this and don’t have a good IDE to write something out for you, but this looks like a popular response that has worked for others.


I realized I never answered your question by providing that answer! Instead of omitting the characters that cannot be used, why don’t you stick with allowing the player to type ONLY alpha numeric characters (ones you know for a fact will work) and create a list of accepted characters than try to find the list of unaccepted characters and making that list.