Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by Barsonax · Jan 01, 2016 at 10:47 PM · arrayserializationslownew

Very slow performance when variable has serialize tag

When i make a new layer in my tilemap editor i have a function that initialises that layer. One of the things it does it making a new byte array to hold all the tileid's in. Ofcourse i want to serialize this so i dont lose it when i enter playmode or something like that. However when i add the serialize tag making a new byte array is suddenly extremely slow even for something like 10000-20000 length it takes several seconds. The slowness seems to scale with the size of the byte array.

First the TileIDData was public but during bugtesting i made this private to ensure not some weirdness is going on outside the class. This worked until i added the serializefield tag to it which makes me think serialization is the culprit here.

Is this some bug or am i doing something very wrong here?

 public void Initialize(int _mapsize_x, int _mapsize_y, int _chunksize, int _tileresolution){
         //Debug.Log ("Initialize");
         TileResolution = _tileresolution;
         MapSize_x = _mapsize_x;
         MapSize_y = _mapsize_y;
         ChunkSize_x = _chunksize;
         ChunkSize_y = _chunksize;
         Chunks_x = (_mapsize_x / ChunkSize_x);
         Chunks_y = (_mapsize_y / ChunkSize_y);
 
         if(Chunks_x*ChunkSize_x < _mapsize_x)
             Chunks_x = Chunks_x + 1;
         if(Chunks_y*ChunkSize_y < _mapsize_y)
             Chunks_y = Chunks_y + 1;
 
         Chunks = new GameObject[Chunks_x*Chunks_y];
         ChunkData = new Chunk[(Chunks_x*Chunks_y)];
         TileIDData = new byte[MapSize_x*MapSize_y];
     }
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

Answer by Barsonax · Jan 01, 2016 at 11:25 PM

So i decided to change the name of the variable and see if that changes anything. By turning TileIDData to TileIDarray it fixed the problem. So the whole script is exactly the same except that all the TileIDData variables are changed to TileIDarray.

Still if there is someone who can tell me what the heck is going on here please tell me.

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 Barsonax · Jan 02, 2016 at 09:28 AM

So the problem came back :(

After hours of trying to figure out what is going on i noticed it has to do with prefabs. When i use PrefabUtility.InstantiatePrefab to instantiate the layers the TileIDarray is very slow. When i use instantiate all problems are gone.

So dont use PrefabUtility.InstantiatePrefab when you need to serialize stuff in it. Kinda broken system is you ask me...

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 isinan85 · Jan 21 at 01:14 PM

thank you for share this experiment

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

42 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 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

Using arrays of vector3s to avoid new 1 Answer

NullReferenceException with serialized array 0 Answers

Why do Constructors return null when used within EditorWindow 1 Answer

Help with arrays of arrays please 2 Answers

Best way to serialize a big array of a class 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