Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Can we set file attribute as ReadOnly and Hidden ?

Discussion in 'Scripting' started by casteillet, Dec 1, 2023.

  1. casteillet

    casteillet

    Joined:
    Jun 29, 2019
    Posts:
    11
    Hi,

    I have a save system in my project where I save the players data in a file and another one which is a backup of the first one. Is it possible to set the file attribute as read only for both files and hidden for the backup one ? If so how ?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,480
    > If so how ?

    Through File.SetAttributes from System.IO. You could find that info through search engine.

    However, you shouldn't do that. The user will still be able to find and delete the files, so you're creating a minor inconvenience which... does not really achieve much.
     
    Bunny83 and casteillet like this.
  3. casteillet

    casteillet

    Joined:
    Jun 29, 2019
    Posts:
    11
    I've saw online people telling to just encrypt and let the user manipulate the files (deleting, moving ect) but nothing about how to do it. Thanks for the information, and I think I'll let the files like that
     
  4. If this is a single player or a non-competitive multiplayer game, you shouldn't spend too much time defending your save files, doesn't matter, the player(s) can't cheat meaningfully.
    If you're doing competitive game, you should not store the save file locally, you should save to the cloud. The only way the players can't access it.
     
    Kurt-Dekker and casteillet like this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,236
    If you're concerned about the user 'hacking your save files,' or 'cheating in your game,' which is playing on their computer, just don't be.

    There's nothing you can do about it. Nothing is secure, it is not your computer, it is the user's computer.

    If it must be secure, store it on your own server and have the user connect to download it.

    Anything else is a waste of your time and the only person you're going to inconvenience is yourself when you're debugging the game and you have savegame errors. Work on your game instead.

    Remember, it only takes one 12-year-old in Finland to write a script to read/write your game files and everybody else can now use that script. Read about Cheat Engine to see more ways you cannot possibly control this.
     
    casteillet likes this.