Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ccharles · Apr 29, 2014 at 10:26 PM · editorsceneserializationsavehideflags

Don't save gameobjects to scene file (No hide flags)

I am coding a terrain system that doesn't use the unity terrain engine. It works well but currently I am having problems with the terrain geometry being saved to the scene file The terrain geometry currently is over 200mb (!) when saved to the scene including all the associated splat maps and materials that go with it.

So I am looking for a way to not save the terrain tile game objects to the scene and instead load them every time unity opens by generating it from the heightmap rather than the raw meshes which uses much less data. The reason the scene cannot be such a large file is github has a 100mb limit of files and this means I cannot commit the scene to my repo, also saving the scene with the geometry in it takes longer than choosing not to save it.

Previously I was using HideFlags.DontSave however this caused issues with serialisation between the play mode and edit mode which caused the terrain geometry references to go null whenever I transitioned between these states.

Currently I have this component to place tiles in the game:

 [ExecuteInEditMode]
 
 [AddComponentMenu("Terrain/Tile Placer")]
 public class TilePlacer : MonoBehaviour {
 
     public int terrainSize = 8;
     public GameObject terrainFab;
     public List<GameObject> tiles;
     public HeightMap heightMap;
     public SplatMap splatMap;
 
     public bool dirty;
 
     public bool needsUpdate = false;
     
     void Awake()
     {
         dirty = false;
         DontDestroyOnLoad (gameObject);
         if (tiles == null)
         {
             Debug.Log ("RECREATE LIST");
             tiles = new List<GameObject>();
         }
         heightMap = GetComponent<HeightMap>();
     }
 
     void OnEnable()
     {
         bool missingTerrain = false;
         for (int i = 0; i < tiles.Count; i++)
         {
             if (tiles[i] == null)
             {
                 missingTerrain = true;
             }
         }
         Debug.Log ("MISSING TERRAIN " + missingTerrain);
         Debug.Log ("TILE COUNT " + tiles.Count + " SHOULD BE: " + terrainSize * terrainSize);
         if (tiles.Count != terrainSize * terrainSize || missingTerrain)
         {
             //StartCoroutine( PlaceTerrain() );
             MarkDirty ();
         }
     }
 
     public void MarkDirty()
     {
         dirty = true;
         if (Application.isEditor)
         {
             Debug.Log ("call dirty");
             splatMap.CreateMap(heightMap.heightGrad);
             PlaceTerrain ();
             dirty = false;
         }
     }
 
     public void ClearTerrain()
     {
         Debug.Log ("CLEAR TERRAIN");
         foreach(GameObject tile in tiles)
         {
             DestroyImmediate(tile);
         }
         tiles.Clear ();
     }
 
     public void PlaceTerrain()
     {
         ClearTerrain ();
         Debug.Log ("PLACE TERRAIN");
         for (int x=0; x < terrainSize; x++)
         {
             for (int z=0; z < terrainSize; z++)
             {
                 //Place tile
             }
         }
     }
 }

When using HideFlags.DontSave the List tiles would reference to null objects when serializing which meant MarkDirty() would get called straight away and the whole terrain mesh would have to reload itself which again would take a lot of time to load the scene.

So is there a way to have a similar behaviour to DontSave but the gameobject still serializes but never saves to the .scene file?

Or should hideflags not mess with the serialisation and I am just using them incorrectly.

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 yoyo · Mar 21, 2015 at 05:16 AM 0
Share

I don't suppose it would be as simple as marking your tiles List as [NonSerialized]?

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Saving a scene within the game? 1 Answer

What Just Happened! 2 Answers

Scene Variable Serialization issues on crash, save etc. 1 Answer

Can I serialize data in an Editor class? 1 Answer

object list not serializing 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