• 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 dyari_dlshad · Aug 25, 2021 at 02:28 PM · gameobject

How to save gameObject?

So its been a while ago that am looking for an answer for this question that how can I save a gameObject, Basically am so new to unity and one thing important that i don't know about is saving data, I already tried PlayerPrefs to saving the coins, other strings and things that can do with PlayerPrefs, and now I want to save GameObject but it cannot in PlayerPrefs, So About saving GameObject I want when a user buys a skin and then closes the application, the skin saves and load when the user back to the game or buliding an Object in the scene want to save, is there any easy way to do that...?

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 Marioooo · Aug 25, 2021 at 03:04 PM

Hi!! there are several ways to do what you want...

Method N1: PlayerPrefs!

Just save a small string that contains the skin you're into, and then load the 3D file or Sprite into the player object.

Method N2: PlayerPrefs + Prefabs!

Same as the method above but load the player prefs on a level manager and load a Prefab object (if you don't know what's a prefab then google it up, is like a copy of an object) then load the prefab from Resources and instantiate it (google load assets from Resources)

this might be a litle tricky if you're new into Unity but is a really good method. Also don't forget that player prefs were created to save... player prefs... if you have to load or save data, you should use a Json File (again google how to save data with Json)

Method N3: Ugly but effective!

A litle bit like the one before but from a manager (like level manager or game manager)

just save a lot of prefabs of the player, one for each skin, and then add references to the manager (to avoid loading from resources) and instantiate the prefab according to the player's current skin...

My Method would be:

1 Save player data inside a Json File

2 Load Player data From a Manager

3 Load the correct prefab from Resources

4 Instatiate the correct Prefab

hope this helps!

Comment
Add comment · Show 5 · 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 Marioooo · Aug 25, 2021 at 03:05 PM 0
Share

Remember that Unity doesn't save any data, you have to manually save and load data

avatar image dyari_dlshad · Aug 25, 2021 at 03:11 PM 0
Share

thank you, helped alot!

avatar image dyari_dlshad · Aug 25, 2021 at 04:03 PM 0
Share

Hello so for now, I want to use the method1 which is PlayerPrefs for this, but can you do the first method with an example, because when I create a string and contain with a skin like that: PlayerPrefs.SetString("Something", mySkin); it gives me an error that says: Argument2 cannot convert from UnityEngine.GameObject ....

avatar image rage_co dyari_dlshad · Aug 26, 2021 at 06:50 AM 0
Share

it is because you are trying to save a skin(presumably a gameobject) as a string, you should rather use that string to acess what string you are using from the game files

avatar image dyari_dlshad rage_co · Aug 27, 2021 at 01:00 PM 0
Share

Thanks, but for some reason lets say I want to save a Destroyed GameObject to be not available when the user closes the game and Back to it ?

avatar image
0

Answer by dowranmaster1234 · Aug 28, 2021 at 08:17 PM

 using UnityEngine;
 
 public class Example : MonoBehaviour
 {
     public void SetInt(string KeyName, int Value)
     {
         PlayerPrefs.SetInt(KeyName, Value);
     }
 
     public int Getint(string KeyName)
     {
         return PlayerPrefs.GetInt(KeyName);
     }
 }
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

190 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 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

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

What do the "active" and "static" checkboxes do? 1 Answer

How to store a list of GameObjects with all components (scripts, colliders etc) 0 Answers

NullReference when accessing GameObject in array (C#) 1 Answer

speed change in standalone compared to editor? 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