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 Lord-Samy · Oct 02, 2017 at 03:42 PM · scripting problemprefabsprefab-instance

How can I save multiple instances of a single prefab?

A couple of months ago I started working on a city builder game, all went well till the moment I decided to add a save/load function to the game. The big problem is that the buildings that the player places are prefabs. I tried to do the following with multiple save/load assets I downloaded( basically they handled sterilization and saving/loading from/to a file):

1-Initialize save slots with a name and type.

2-OnButtonClickLoad, A building will send its x,y,z coordinates to a central script which will save it as 3 ints (can't save vector3s for some reason).

3-OnButtonClickSave, the x,y.z int values are loaded and assigned to the buildings vector3.

Only problem is that this only works for a single instance of a prefab (like 1 player camera vector3) but I found it impossible to make it work with buildings that could be of any number in the scene.

Naturally, I tried assigning random generated ids to every building instance, but there was no way I could initialize save slots for an unknown number of instances with unknown ids.

I am quite lost on what to do now as I have pretty much exhausted all of my ideas! How can I save multiple instances of a single prefab?

Comment
Add comment · Show 1
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 Cuttlas-U · Oct 02, 2017 at 04:19 PM 0
Share

hi; that seems a big project; i cant help u but give u some idea; but i can work with u on it to see what can we do for it ;

if u want u can install $$anonymous$$m viewer and send me a massage to my gmail : savajjad@gmail.com

good luck

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Faen_run · Oct 02, 2017 at 04:20 PM

If i understand it well you have a scenery with multiple buildings that are prefab clones. If you dont make any changes to them and they are only a prefab in x,y,z coordinates you have to save the coordinate and asign every type of building an ID to link them with it's prefab. Then you can make an object that links every ID with its prefab (a simple list of objects would do, just make a public list of GameObjects and add your prefabs to it, the ID would be the position in the list), so when you load your game your loader read the ID and the coordinates, searches the list and Instantiate that prefab in the position you want.

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.

Follow this Question

Answers Answers and Comments

122 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

Related Questions

Serialize script fields of prefabs with other prefabs, so that when I drag them into hierarchy, the connection becomes between game objects? 1 Answer

Unity loading prefabs difficulties. optimization 1 Answer

Unity 2D Game Issue: Script is only affecting one prefab instead of all of them. 0 Answers

Making multiple instances of a prefab,Instantiating multiple instances of a prefab 1 Answer

Find Source of Prefab Instance in 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