Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 D4rt · Jan 24, 2015 at 12:20 PM · prefabresources.loadlevel editor

Saving a level with the help of prefabs

Hi,

I'm making a run-time level editor and have ran into some issues while implementing a save feature. I have a large amount of different GameObjects that can be added to the level. Instead of saving all of their components, I only need to save a few variables (for example the position). Instead of saving every GameObject separately, I'd simply like to save some sort of reference to the prefab they use.

When loading, I could just use Resources.Load(...) to load the prefab from the resources folder, saving me the trouble of having a reference to the prefab set up in the scene. Let's say we have 1000 different prefabs. Maintaining a reference to them all manually from some collection in the scene wouldn't be very plausible. I'd much rather load a GameObject only when it's actually used in the level.

I tried looking around but apparently the paths to prefabs can only be found while in the Unity editor (using the PrefabUtility). What kind of a solution would let me get the prefab path of a GameObject so that I could use Resources.Load() during my level loading? Or is there perhaps some totally different way of approaching the problem that I haven't thought about?

Thank you

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

3 Replies

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

Answer by Cherno · Jul 12, 2015 at 10:11 AM

Take a look at my SerializeHelper here:

SerializeHelper - Free save and load utility. (De)Serialize all objects in your scene.

If you use it, you will be able to decode what kind of data is saved. For your case, I recommend ignoring the part the saves and loads component data, and instead add a string variable to the ObjectIdentifier script that holds the path to the prefab. Since this path will then get saved along side the other gameobject information, you can just use it to load and instantiate the gameObject after loading. Note that in it's current form, the project creates a dictionary of all prefabs in the resources folder and uses that to instantiate gameObjects after loading. Feel free to ignore, or rather modify, that as well.

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 D4rt · Jan 20, 2016 at 04:00 PM 0
Share

Saving the path to the prefab was the way I solved the problem (with my own implementation though).

avatar image
0

Answer by Chris333 · Jan 24, 2015 at 01:47 PM

Hi,

did you already looked into this tutorial about saving GameData?

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading

Comment
Add comment · Show 2 · 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 D4rt · Jan 24, 2015 at 09:29 PM 0
Share

Hi and thanks for the answer. Unfortunately the video doesn't really contain any new information for me. I got a decent solution by stuffing my prefabs in to one folder and hard coding the path to my loader. After that it's just a matter of calling Resources.Load(path + "/" + prefabName).

avatar image adhamBer · Jul 11, 2015 at 09:18 PM 0
Share

Hi, i am sorry I can't help you, im in the same fix..but in correspondence to your last comment, I understand that you figured how to do it and so I ask can you share your info? $$anonymous$$y problem is saving anything the player does in the level editor. - hope u reply and thank you!

avatar image
0
Wiki

Answer by starikcetin · Jul 11, 2015 at 09:40 PM

I don't understand why you need to save gameobjects as prefabs, an xml serialization formed like this would be fine for a runtime editor:

 <gameobject prefabname="_name">
 <Xpos>_pos</Xpos>
 <Ypos>_pos</Ypos>
 <Zpos>_pos</Zpos>
 <Xscale>_scale</xScale>
 .
 .
 .


Also, this will give players the opportunity to import and export their desings.

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

22 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

Related Questions

Resources.Load prefab from outside start or update 1 Answer

All calls to Resources.Load stopped working on Amazon devices (Unity 5.6.3p3) 1 Answer

Loading prefabs into a list 1 Answer

Resources.Load() What has to be in Resources Folder 1 Answer

Eliminating prefabs from resources folder? 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