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 JockShack · Jan 03, 2015 at 11:08 AM · not workingloadingxml

XML loading not working for built game

I have recently been undergoing a project and have hit a stop. I finished making the game completely in Unity where the game loads mostly from XML and saves the data. It works fine within the Unity window but when the game has been built and run, after going through the main menu, nothing loads into the game and I am left with a blank blue background. Is there something I missed that is needed for the built version?
Below is the AssetLoader class I am using. I also have a SceneAsset class and SceneAssetAggregate class, if that needs to be posted I will do so if need be.

 using UnityEngine;
 using System.Collections;
 using System.Xml.Serialization;
 using System.IO;
 
 
 public class AssetLoader : MonoBehaviour {
 
     public string filename;
 
     // Use this for initialization
     void Start () {
 
         //Terrain Loader
         GroundAsset ground = new GroundAsset("New Terrain 1");
         ground.position = new Vector3(-1213, 0, -1358);
         ground.scale = new Vector3(1, 1, 1);
 
         //Building Loader
         BuildingAsset building = new BuildingAsset ("Building_11");
         building.position = new Vector3 (-16, 0, -8);
         building.rotation = new Quaternion (-90, 0, 0, 0);
         building.scale = new Vector3 (3, 3, 3);
 
         //Key Loaders
         KeyAsset key1 = new KeyAsset ("key");
         key1.position = new Vector3 (4, 1, 5);
         key1.scale = new Vector3 (2, 2, 2);
 
         KeyAsset key2 = new KeyAsset ("key");
         key2.position = new Vector3 (-43, 1, -8);
         key2.scale = new Vector3 (2, 2, 2);
 
         KeyAsset key3 = new KeyAsset ("key");
         key3.position = new Vector3    (3, 3, -22);
         key3.scale = new Vector3 (2, 2, 2);
 
         KeyAsset key4 = new KeyAsset ("key");
         key4.position = new Vector3 (-27, 2, 10);
         key4.scale = new Vector3 (2, 2, 2);
 
         //Terminal Loader
         TerminalAsset terminal = new TerminalAsset ("Term01");
         terminal.position = new Vector3 (-16, 0, -14);
         terminal.scale = new Vector3 (2, 2, 2);
 
         //3rd person controller Loader
         PlayerAsset player = new PlayerAsset ("3rd Person Controller Level1");
         player.position = new Vector3 (-16, 1, -16);
         player.scale = new Vector3 (1, 1, 1);
 
         //Crate Loaders
         CrateAsset crate1 = new CrateAsset ("crate_2");
         crate1.position = new Vector3 (0, 2, 5);
         crate1.scale = new Vector3 (5, 5, 5);
 
         CrateAsset crate2 = new CrateAsset ("crate_2");
         crate2.position = new Vector3 (-26, 2, 5);
         crate2.scale = new Vector3 (5, 5, 5);
 
         SceneAssetAggregate list = new SceneAssetAggregate();
         list.assets.Add(ground);
         list.assets.Add (building);
         list.assets.Add (key1);
         list.assets.Add (key2);
         list.assets.Add (key3);
         list.assets.Add (key4);
         list.assets.Add (player);
         list.assets.Add (terminal);
         list.assets.Add (crate1);
         list.assets.Add (crate2);
 
         XmlSerializer serializer = new XmlSerializer(typeof(SceneAssetAggregate));
         FileStream writefile = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
 
         serializer.Serialize(writefile, list);
         writefile.Close();
 
         FileStream readfile = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
         SceneAssetAggregate readAssets = (SceneAssetAggregate)serializer.Deserialize(readfile);
 
     
         foreach(SceneAsset asset in readAssets.assets)
         {
             GameObject newGO = null;
             switch (asset.assetType)
             {
                 case SceneAssetType.Ground:
                 {
                 TerrainData t = (TerrainData)Instantiate(Resources.Load(ground.filename));
                 newGO = Terrain.CreateTerrainGameObject(t);
                 break;
                 }
 
                 case SceneAssetType.Building:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load(building.filename));
                 break;
                 }
 
                 case SceneAssetType.Key1:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (key1.filename));
                 break;
                 }
 
                 case SceneAssetType.Key2:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (key2.filename));
                 break;
                 }
 
                 case SceneAssetType.Key3:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (key3.filename));
                 break;
                 }
 
                 case SceneAssetType.Key4:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (key4.filename));
                 break;
                 }
 
                 case SceneAssetType.Player:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (player.filename));
                 break;
                 }
 
                 case SceneAssetType.Terminal:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load(terminal.filename));
                 break;
                 }
 
                 case SceneAssetType.Crate1:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (crate1.filename));
                 break;
                 }
 
                 case SceneAssetType.Crate2:
                 {
                 newGO = (GameObject)Instantiate(Resources.Load (crate2.filename));
                 break;
                 }
                     
                 default: throw new System.NotImplementedException ();
             }
 
             newGO.transform.position = asset.position;
             newGO.transform.rotation.Set(asset.rotation.x, asset.rotation.y, asset.rotation.z, asset.rotation.w);
             newGO.transform.localScale= asset.scale;
         }
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
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 Pindwin · Jan 03, 2015 at 11:28 AM 0
Share

what does output_log.txt say? its in you build_Data folder.

avatar image JockShack · Jan 03, 2015 at 01:17 PM 0
Share

Cannot make head or tails of this, sorry I am quite new to coding

link text

output_log.txt (3.8 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JockShack · Jan 05, 2015 at 05:19 PM

I managed to solve this by placing the Unity built exe and data files into the actual Unity project files.. From there it was able to load the XML data and the game was playable.

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 Testman · Apr 27, 2015 at 11:17 AM

(Mac OS X) I overcame this by placing my XML folder into the build's Resources folder. Right click -> Show package contents -> Resources.

Didn't need to alter my code at all.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Why is my script not working like it should 3 Answers

Baking with lightmap in very low resolution. 1 Answer

I am not able to see any object in scene. 1 Answer

Load file on Android 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