Search Unity

PlayerPrefs saves registry name strange!

Discussion in 'Scripting' started by macbread0625, Nov 27, 2019.

  1. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Hi, I'm connecting Unity with Labview...

    Code (CSharp):
    1. public void HeadTrack()
    2.     {
    3.         RotationX = (int)transform.eulerAngles.x;
    4.         RotationY = (int)transform.eulerAngles.y;
    5.         RotationZ = (int)transform.eulerAngles.z;
    6.  
    7.         PlayerPrefs.SetInt("RotationX", RotationX);
    8.         PlayerPrefs.SetInt("RotationY", RotationY);
    9.         PlayerPrefs.SetInt("RotationZ", RotationZ);
    10.     }
    I save 3 values with this code above (Rotation X to Z).

    upload_2019-11-27_15-9-35.png

    It seems work well.

    But registry names are different what I want to make. Strange numbers are attached after!...

    I set their name such as "RotationX" (like code above).

    I hope your kind reply... :)
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,936
    Why do you care what names they are in the registry? PlayerPrefs doesn't claim the entries in the registry are named exactly as the key you specify, just that when you request the value by the same key you saved as that you get the correct value back.

    Where does Unity ever state that the name of the registry entry is the name of the provided key?
     
    Last edited: Nov 27, 2019
    macbread0625 likes this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,916
    That's all you really need to know. You don't need to care how PP stores values, as long as it works.

    If you want to get a file that's more human-readable for whatever reason, you can serialize values yourself, maybe use JsonUtility, something like that. PlayerPrefs is best for the most basic "fire and forget" sort of permanent data.

    Speaking of which, this really looks like a poor usage of PlayerPrefs. What are you actually trying to do with this? It looks like you'd probably be better offer with JsonUtility regardless.
     
    macbread0625 and Joe-Censored like this.
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    6,180
    I'm also a LabView user, how are you using both?
     
  5. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Thx for reply Joe!...

    I want to send some values from Unity to Labview. To read reg value in Labview, I need exact name of that.

    upload_2019-11-28_10-8-52.png


    Now I'm doing this in my own PC. But If I move this other PC I can't assure Unity will save its reg value in same name in my PC.

    So as I learned, I want to make a rule for naming to read reg value regardless of which computer is running what I make.

    I dont test yet reading reg value in Unity. I didnt know I can read just with reg name I saved.
     
    Joe-Censored likes this.
  6. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Thx for reply, StarManta.

    I'm trying to send some values from Unity to Labview. I can figure using txt file at first, but It will grow too large over time. And I'm afraid that may make slow all system. So I think a way to send value not saving a file or record will be better and I used PP.

    After finish initial configure of whole system I'll try what you recommend. Thank you!
     
  7. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    6,180
    Exchanging data via the registry is not recommended! Just write to a circular file buffer, or use a custom DLL.
     
    xVergilx and macbread0625 like this.
  9. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    395
    macbread0625 likes this.
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,916
    Yeah, you definitely need to learn to write files yourself - it's not difficult (and about a hundred times easier than trying to reverse-engineer the PlayerPrefs file format).
     
    macbread0625 and xVergilx like this.
  11. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    May I ask why regsitry is not recommended if you don't mind?.. I alread read about hooking issue from blogs but Vive used that on their SDK. So I thought that might be safe sending internal program to internal. Thanks for reply!
     
  12. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Thanks for reply! As I understand.. Yoda recommended to use 'Registry' class(?) than PlayerPrefs.
    I got it why Unity adds hash. :)
     
  13. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,916
    macbread0625 likes this.
  14. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,912
    System efficiency. Microsoft recommends storing your data in external files and referencing the files in a registry entry when you need to store more than 2KB. Because storing large amounts of data within the registry will adversely affect system performance.

    https://docs.microsoft.com/en-us/windows/win32/sysinfo/registry-storage-space
    https://docs.microsoft.com/en-us/windows/win32/sysinfo/registry-element-size-limits
     
    macbread0625 likes this.
  15. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    I dont mean to bother you keep asking.. Just I need to clear reasons and why/why not to report a reason why I choose any method to my research chief(Also comparison with other methods...).
    And personaly a little bit curious why registry method is not recommended (System efficiency - Thx Ryiah!) 'cause Vive SDK sends rotation data to registry.

    Again I really hope you not to be irritated. And Thanks for link!.. I'll refer them. :)
     
  16. macbread0625

    macbread0625

    Joined:
    Sep 11, 2019
    Posts:
    13
    Thx Ryiah! I didnt know about that restriction. I may able to talk why I need to change data sending method.
     
  17. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    840
    The registry is a complex mechanism with lots of features you probably don't need. This is the best argument against it. I'm sure there are also many constraints to using it, such as the one Ryiah linked.

    Also, PlayerPrefs doesn't say anything about the registry, so you're breaking encapsulation by even discovering that it's writing there. If you want to control where you're writing to in the registry, use the correct tools.

    Make things as simple as possible.
     
    macbread0625 likes this.
  18. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    6,180
    What are you trying to accomplish in connecting Labview with Unity? I use both myself, and they are great programs. Passing data via the file system is rarely recommended, and is slow. How frequently is the data changing, and what is the data? And you mentioned "Yoda", who is that? Someone told you to exchange data via the Registry? I suspect you are making references out of context. The registry is used for app-specific values for data that rarely changes, like storing the most recent used file list that many programs use. This may help http://www.ni.com/tutorial/10060/en/
     
    Ryiah and macbread0625 like this.