Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DerDerErIst · Jan 31, 2018 at 02:19 PM · scripting problemscriptableobjectdata storage

Store Playerdata in Scriptable Object

Hello,

Actually i try to use Scriptable Object as Data Container. So far as good he raise up the Variable as example a Counter


I destroy a Brick and he tell the Scriptable Object i destroyed a brick and increase the int by 1 Working Fine


But as soon i stop Playing an restart the Game all Data in the Scriptable Object are gone. I was thinking Data in Scriptable Object are persisant and stay at the Values. Because i need Access from various Scripts i made a PlayerManager:

 public Player player;
     public static PlayerManager playerManager;
 
     private void Awake()
     {
         playerManager = this;
         DontDestroyOnLoad(this);
     }

he is the Reference in every Scene to get Access to the Player Scriptable Object which only look like this:

 using UnityEngine;
 
 [CreateAssetMenu(fileName = "Player", menuName = "Player")]
 public class Player : ScriptableObject
 {
     public int brickCounter;
     public float score;
     public float highscore;
 }

My Idea behind that is simple, sure i can store that information in PlayerPrefs, but PlayerPrefs are susceptible to Cheater and i someone Know where to look he find them easy. Sure i can make as example a JSON and make a big Security behind that all, but for a small game like mine im not sure if its economic to make so much effort to prevent player from cheating.


So when i set Data in a Scriptable Object like i say in Inspector brickCounter = 100; i close the Game and restart the game the brickCounter is still at 100;


But if i start the game play a bit and destroy some Bricks the Counter go from 100 to 105 (i destroyed now 5 brick) then i can see in the Scriptable Object its 105. But as soon i stop the Game and start again it is set back to 100. Why is that? How can i solve this?


Hope someone can give me a hint or idea to solve it different way. I have EasySave2 Asset but as i said..... its a small game....

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DerDerErIst · Jan 31, 2018 at 02:41 PM

As i go through my Code i consider about.


My PlayerManager is a static so i have access all over the scene to it. Means that my Player player (the Scriptable Object) is also a static? That would explain to me why he reset the Scriptable Object after i restart the Game?


If i make it non Static and make something like FindGameObject would this work?


Mhh okay i tried to make my PlayerManager non static and get in all Scripts a reference to that PlayerManager but sadly he still delete all information if i restart the Game/Unity

Comment
Add comment · 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
0

Answer by grizzly48 · Jan 31, 2018 at 03:18 PM

Hi, the way I did it (also didnt want to use PlayerPrefs to save stuff) was by using the BinaryWriter/BinaryReader of the "System.IO" package. This way I could hide the file wherever I wanted, and since only you know wich bit refears to wich piece of information (CheatEngine and whatnot can still figure this out), I felt somewhat safe about cheaters. But if you really want it to be cheatsafe then you can´t save it locally either way.

Comment
Add comment · Show 1 · 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 DerDerErIst · Jan 31, 2018 at 03:25 PM 0
Share

I think around that yes.

Actually i also using Gamesparks as Cloud to save the Highscore and the Brick Count so my idea now is i keep the Scriptable Object but when u start the Game i just load all Data stored from the Cloud and insert it into the Scriptable Object then its not Zero anymore and you have the actual data saved on a cloud for the player.

I think this will be now the easiest way to handle this. To Prevent players from Cheating and having a easy life as Coder :p

One of the reason why i wanted to make that, is that i wanted the player can play Offline and when u come Online and start Playing he automatic set ur scores u made offline to the Cloud.

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

130 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make ScriptableObject assets customizable. 1 Answer

Reference to scene objects from scriptable objects 1 Answer

ScriptableObject reference resetted after a method is finished. 2 Answers

Some data of scriptable object resets when Unity Editor restarts 0 Answers

Instantiate ScriptableObject with a random asset from List 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