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 bocalexandru · Feb 05, 2013 at 09:13 AM · assetbundleassetsxmlloadlevelserverside

Loading game objects dinamycaly

Hello community!

I am trying to understand how can I load the game objects in the scene dynamically as it loads on loading screen?

I was thinking that I could load the scene with empty game objects and after parsing a XML file from witch I will load every game object in it's place. All the assets that will be loaded will be pulled from a Asset Server. I want to keep the same screen and modify the game objects and how they are positioned in the scene.

Has anyone tried this method and has some experience with this, or is it possible to do something like this ? I am trying to understand how it works and what Unity has to offer for this kind of application.

Comment
Add comment · Show 2
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 whydoidoit · Feb 05, 2013 at 09:16 AM 0
Share

I presume you mean your own Asset Server as the product in Unity with that name is a Source Control system.

It's generally not a good idea to load objects which the game is playing, you'd certainly want to $$anonymous$$imise it because Instantiate is very very expensive.

$$anonymous$$y Unity Serializer does allow you to load and save individual objects, but again, expensive and not suggested unless you use it at level start time or do very few.

avatar image bocalexandru · Feb 05, 2013 at 01:59 PM 0
Share

Yes a personal Asset Server and the resources are loaded at level start(sorry for the confusion). To be more precise I want to use the same scene put to repopulate with different game objects positioned in different places.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Gizmoi · Feb 05, 2013 at 12:24 PM

First of all, look into XML serialisation, I find it easiest to serialise directly to a class. For example in my simple 2D game I use this class

 public enum Map
 {
     Alps,
     Canyon,
     Jungle,
     City,
     Space
 }
 
 public enum Tile
 {
     Standard,
     Sliding,
     Breakable,
     Broken,
     Worm,
 }
 
 [System.Serializable]
 public class LevelData
 {
     public Map MapName { get; private set; }
 
     public Tile[] LeftWall { get; private set; }
     public Tile[] RightWall { get; private set; }
 
     public LevelData()
     {
         MapName = Map.Alps;
 
         LeftWall = new Tile[8];
         RightWall = new Tile[8];
     }
 }

With Unity it's best to use Resources.Load to load your xml as then it will get bundled into the final build. I ran into issues with this because I'm building on mobile devices.

 LevelData data = null;
 
 TextAsset text = Resources.Load(path, typeof(TextAsset)) as TextAsset;
 
 // set up streams to read text asset
 XmlSerializer serialiser = new XmlSerializer(typeof(T));
 using (StringReader stringReader = new StringReader(text.ToString()))
 {
     using (XmlTextReader xmlReader = new XmlTextReader(stringReader))
     {
         // deserialise object
         data = serialiser.Deserialize(xmlReader) as LevelData;
 
         // close readers
         xmlReader.Close();
         stringReader.Close();
     }
 }

This allows me to have an XML file that is easily readable and modifiable.
These files must be saved as .txt to be read in by Resources.Load however.
As whydoidoit mentioned, it's best to only do this at level start up.
From this data, I can iterate through each tile and use GameObject.Instantiate() to instantiate prefabs at given locations. Personally I have the tiles already set up and then I simply iterate through and change the GUITexture. But the system is similar.

Hope that helps!

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 bocalexandru · Feb 05, 2013 at 02:12 PM 0
Share

Thank you for your answer! I will look into it and try out.

Just one aspect: the xml must be loaded as a .txt file?

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

11 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

Related Questions

Loading assets for a level from asset bundle 1 Answer

Addressables - Use Asset Database (faster) - Not loading assets within a folder 1 Answer

Scene Asset Bundle - LoadLevelAdditive and OnLevelWasLoaded 1 Answer

RenderSettings in AssetBundles 3 Answers

AssetBundleRequest is done but asset is null 2 Answers


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