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 CiberX15 · Feb 08, 2014 at 03:54 PM · serializationsaveloadunknown-identifierunknown identifier

Unknown Identifier: 'SerializeObject'

Ok I am writing a save game function and I am using this example as my baseline : http://wiki.unity3d.com/index.php?title=Save_and_Load_from_XML

problem is when I try to use it in my script the compiler does not recognize SerializeObject. It compiles the example just fine so I know I am screwing up somewhere. I would very much appreciate if someone can point out my mistake : P

I'll include the whole script since I probably forgot to import something or get something set up properly. But the function in particular that is not working is the Save() function.

My Code:

 #pragma strict
 import System.Collections.Generic;
 import System.Xml;
 import System.Xml.Serialization;
 import System.IO;
 import System.Text;
 
 class Shipwrite extends MonoBehaviour{//Begin Class
 /*
     The players comander class
     respomsible for interpreting player Input
     and converting it into commands for Cores
 */
 var PanSpeed : float = 0.01;
 var FreeCamera = true;
 var SelectedCore : Core;
 var ShipType : ShipClass;
 var CurrentToolSet : String = "Hulls";
 var CurretnTool : Transform;
 var MouseInMenu = false;
 var _FileLocation : String = Application.dataPath;
 
 var ShipName : String = "Ship Name";
 
 private var ToolList : List.<Transform> = new List.<Transform>();
 
 private var Ghost : Transform;
 
 class ShipSave
 {
     var Data : List.<PartData>;
 }
 
 class PartData
 {
     var PartName : String;
     var PartPos : Vector3;
     var PartRot : Quaternion;
 }
 
 class WeaponData extends PartData
 {
     var Group : WeaponGroup;
 }
 
 function Start () 
 {
     ShipName = "Ship Name";
 }
 
 function Update () 
 {
     if(!MouseInMenu)
     {
         FindGrid();
         CheckKeys();
     }
 }
 
 function CheckKeys()
 {
     //Zoom
     if(Input.GetAxis("Zoom") > 0)
     {
         Camera.main.orthographicSize -= 5;
         if(Camera.main.orthographicSize < 5)
         {
             Camera.main.orthographicSize = 5;
         }
     }
     
     if(Input.GetAxis("Zoom") < 0)
     {
         Camera.main.orthographicSize += 5;
         if(Camera.main.orthographicSize > 50)
         {
             Camera.main.orthographicSize = 50;
         }
     }
     
     if(Input.GetAxis("DragCamera") > 0)
     {
         Camera.main.transform.position += Vector3(-Input.GetAxis("MouseX") * PanSpeed *Camera.main.orthographicSize, -Input.GetAxis("MouseY") * PanSpeed * Camera.main.orthographicSize, 0);
     }
     
     //Vars for placing and removing blocks
     var MouseHit = GetMouseHit();
     var GridLoc : Vector3 = GetMouseHit().point;
 
     
     //Remove Blocks
     if(Input.GetAxis("Missiles") > 0)
     {
         if(MouseHit.collider.tag != "Grid")
         {
             Destroy(MouseHit.collider.gameObject);
         }
     }
     
     //Place Blocks
     if(Input.GetAxis("Turret") > 0)
     {
         if(CurretnTool != null)
         {
             var NewPart : Transform;
             
             if(Ghost.GetComponent(Hull).Module != ModuleType._NeedFloor)
             {
                 if(MouseHit.collider.tag == "Grid")
                 {
                     GridLoc.x = Mathf.Round(GridLoc.x);
                     GridLoc.y = Mathf.Round(GridLoc.y);
                     GridLoc.z = 2;
                     NewPart = Instantiate(CurretnTool, GridLoc, Quaternion.identity);
                     NewPart.transform.parent = SelectedCore.transform;
                 }
             }
             else
             {
                 if(MouseHit.collider.tag != "Grid")
                 {
                     if(MouseHit.collider.GetComponent(Hull).Module == ModuleType._Floor)
                     {
                         GridLoc.x = Mathf.Round(GridLoc.x);
                         GridLoc.y = Mathf.Round(GridLoc.y);
                         GridLoc.z = 2;
                         NewPart = Instantiate(CurretnTool, GridLoc, Quaternion.identity);
                         NewPart.transform.parent = SelectedCore.transform;
                     }
                 }
             }
         }
     }
 }
 
 function FindGrid()
 {
     if(Ghost != null)
         Destroy(Ghost.gameObject);
         
     if(CurretnTool != null)
     {
         var GridLoc : Vector3 = GetMouseHit().point;
         GridLoc.x = Mathf.Round(GridLoc.x);
         GridLoc.y = Mathf.Round(GridLoc.y);
         GridLoc.z = 2;
         Ghost = Instantiate(CurretnTool, GridLoc, Quaternion.identity);
         Ghost.collider2D.enabled = false;
         Debug.Log(CurretnTool.name);
     }
 }
 
 //Check what is under mouse
 function GetMouseHit() : RaycastHit2D
 {
     // get mouse location 2D
     var mousePos = Input.mousePosition;
     
     //create ray from mouse and... yeah actualy I dont know how this works.
     var ray : Ray = camera.main.ScreenPointToRay (mousePos);
     
     //Used to store what we hit
     var hitInfo : RaycastHit2D;
     
     hitInfo = Physics2D.GetRayIntersection(ray);
     return hitInfo;
 }
 
 function SaveShip()
 {
     
     if(ShipName == "")
     {
         ShipName = "Ship Name";
     }
     
     var SaveData : ShipSave;
     var _data : String;
     
  
     // Time to creat our XML!
     _data = SerializeObject(SaveData);
     // This is the final resulting XML from the serialization process
     var writer : StreamWriter;
     var t : FileInfo = new FileInfo(_FileLocation+"/"+ ShipName);
     if(!t.Exists)
     {
         writer = t.CreateText();
     }
     else
     {
         t.Delete();
         writer = t.CreateText();
     }
     writer.Write(_data);
     writer.Close();
     Debug.Log("File written.");
     //TODO SAVE THE SHIP!
     
 }
 
 function OnGUI()
 {
     var BoxHight = Screen.height * 0.2;
     var BoxWidth = Screen.width;
     GUI.color.a = 200;
     GUI.backgroundColor = Color.green;
     GUI.backgroundColor.a = 200;
     var ToolBox : Rect = Rect(0, Screen.height - BoxHight, BoxWidth, BoxHight);
     GUI.Box(ToolBox, "");
     GUI.Box(Rect(0,0,BoxHight,BoxHight), "");
     if(Rect(0,0,BoxWidth,BoxHight).Contains(Input.mousePosition) || Rect(0,Screen.height - BoxHight,BoxHight,BoxHight).Contains(Input.mousePosition))
     {
         MouseInMenu = true;
     }
     else
     {
         MouseInMenu = false;
     }
     
     GUILayout.BeginArea(Rect(0,0,BoxHight,BoxHight));
         GUILayout.BeginVertical();
         
             ShipName = GUILayout.TextField(ShipName,20);
             
             GUILayout.FlexibleSpace();
             
             if(GUILayout.Button("Save"))
             {
                 SaveShip();
             }
             
             GUILayout.FlexibleSpace();
             
             if(GUILayout.Button("Save and Test"))
             {
                 SaveShip();
             }
             
             GUILayout.FlexibleSpace();
             
             if(GUILayout.Button("Menu"))
             {
             
             }
         GUILayout.EndHorizontal();
     GUILayout.EndArea();
     
 
     
     var SelectionBox  : Rect = Rect(0, Screen.height - BoxHight, BoxHight, BoxHight);
     GUILayout.BeginArea(SelectionBox);
             GUILayout.BeginVertical();
             if(GUILayout.Button("Hulls"))
             {
                 CurrentToolSet = "Hulls";
             }
             
             GUILayout.FlexibleSpace();
             
             if(GUILayout.Button("Modules"))
             {
                 CurrentToolSet = "Modules";
             }
             
             GUILayout.FlexibleSpace();
             
             if(GUILayout.Button("Weapons"))
             {
                 CurrentToolSet = "Weapons";
             }
             GUILayout.EndVertical();
     GUILayout.EndArea();
     
     var MainBox  : Rect = Rect(BoxHight, Screen.height - BoxHight, BoxWidth - BoxHight, BoxHight);
     GUILayout.BeginArea(MainBox);
             GUILayout.BeginHorizontal();
             var i = 0;
             
             if(CurrentToolSet == "Hulls")
             {
                 for(i = 0; i < ShipType.Hulls.Length;)
                 {
                     if(GUILayout.Button(Resources.Load("Materials/" + ShipType.Hulls[i].name, typeof(Texture2D)), GUILayout.Width(BoxHight), GUILayout.Height(BoxHight)))
                     {
                         CurretnTool = ShipType.Hulls[i];
                     }
                     i++;
                 }
             }
             
             if(CurrentToolSet == "Modules")
             {
                 for(i = 0; i < ShipType.Modules.Length;)
                 {
                     if(GUILayout.Button(Resources.Load("Materials/" + ShipType.Modules[i].name, typeof(Texture2D)), GUILayout.Width(BoxHight), GUILayout.Height(BoxHight)))
                     {
                         CurretnTool = ShipType.Modules[i];
                     }
                     i++;
                 }
             }
             
             if(CurrentToolSet == "Weapons")
             {
                 for(i = 0; i < ShipType.Weapons.Length;)
                 {
                     if(GUILayout.Button(Resources.Load("Materials/" + ShipType.Weapons[i].name, typeof(Texture2D)), GUILayout.Width(BoxHight), GUILayout.Height(BoxHight)))
                     {
                         CurretnTool = ShipType.Weapons[i];
                     }
                     i++;
                 }
             }
 
             
             GUILayout.EndHorizontal();
     GUILayout.EndArea();
 }
 
 
 
 }//End Class

Thanks in advance : D

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 CiberX15 · Feb 08, 2014 at 05:07 PM 0
Share

Help me Obi-Wan $$anonymous$$enobi your my only hope. (Any other jedi feel free to apply)

1 Reply

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

Answer by CiberX15 · Feb 08, 2014 at 06:12 PM

I Figured it out. I was missing a function from the tutorial:

    // Here we serialize our UserData object of myData
    //string SerializeObject(object pObject)
 function SerializeObject(pObject : Object)
 {
    var XmlizedString : String  = null;
    var memoryStream : MemoryStream  = new MemoryStream();
    var xs : XmlSerializer = new XmlSerializer(typeof(UserData));
    var xmlTextWriter : System.Xml.XmlTextWriter  = new System.Xml.XmlTextWriter(memoryStream, Encoding.UTF8);
    xs.Serialize(xmlTextWriter, pObject);
    memoryStream = xmlTextWriter.BaseStream; // (MemoryStream)
    XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
    return XmlizedString;
 }
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

18 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

Related Questions

Save and load serialization problem 0 Answers

Save/load playerprefs 2 Answers

Saving/Load using menu C# 1 Answer

Serialization/Deserialization Problems 0 Answers

SerializationException: Type UnityEngine.Vector3 is not marked as Serializable. 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