Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Artemiye · Sep 24, 2016 at 03:40 PM · editoreditor-scriptingserializationarray of gameobjectsserialize

Array does not serialize properly in a prefab instance for a scene

I'm currently experiencing an issue where I attempt to link up some data in the scene for one of the prefab instances via an editor menu item script, and Unity (5.4.1f1 Personal Edition) will do one of 3 things:

  1. It will serialize the array properly (size and all of its members). This rarely happens.

  2. It will partially serialize the array (size will be correct, and some of its elements will be as well). This often happens.

  3. It will minimally serialize the array (size will be correct, but NONE of the elements will be). This sometimes happens.

I ensure that I call Undo.RecordObject, and I've tried calling it directly on the game object, then the Enemy script, and then both with no improvements. I also make sure to call EditorSceneManager.MarkSceneDirty as well. I know when something has gone wrong because the text in the inspector will not be bolded, and when the scene is re-loaded, all of the non-bolded array elements will be null.

I've already spent far too long trying to figure out a pattern to this behaviour but there doesn't seem to be one and I'm hoping there's something I'm missing that will fix this issue.

alt text

If I reloaded the scene, elements 0 (inclusive) to 4 (inclusive) will be null, and thus, my game logic breaks.

Edit 1: I've found a temporary work around. What I have to do is click on an element of the array (the circle with a dot in the center), and then select a different item. At that point, all of the items in the array become properly bolded and they also serialize properly. And of course, I then change the item back to the original intended data. This method is a little unusual but it works.

unity-serialization.png (28.7 kB)
Comment
Add comment · Show 10
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 Adam-Mechtley · Sep 24, 2016 at 06:53 PM 0
Share

All that should be required is a) Undo.RecordObject(), specifying the Enemy behaviour as the target object(s) and b) that all of the values set are persistent in the scene data. Could you possibly share any code where you are calling Undo.RecordObject()?

avatar image TBruce · Sep 24, 2016 at 06:58 PM 1
Share

Could you please supply come code?

avatar image Artemiye · Sep 24, 2016 at 09:40 PM 0
Share

Sure, here's the gist of it:

 Undo.RecordObject(SelectedEnemy, "Setting Waypoints (Enemy)");
 SelectedEnemy.PatrolPoints = WalkableTiles.ToArray();
 EditorScene$$anonymous$$anager.$$anonymous$$arkSceneDirty(Scene$$anonymous$$anager.GetActiveScene());

SelectedEnemy is the Enemy script that you see in the screenshot. PatrolPoints is a public array of LevelTiles, all of which exist in the scene (they're also linked to a prefab). I don't know how helpful this is so if you want the entire function for this, let me know and I'll post it.

avatar image Adam-Mechtley Artemiye · Sep 26, 2016 at 06:44 AM 0
Share

I am assu$$anonymous$$g you have verified that WalkableTiles.ToArray() contains all the correct items when you set the value?

avatar image Artemiye Adam-Mechtley · Sep 26, 2016 at 11:40 AM 0
Share

Yeah, it does contain all of the correct items. Each Hexagon is a game object in the scene with a LevelTile script attached to it, and the Enemy that's being modified is also in that same scene as well so I'm not sure why this is happening. I might have to experiment with other methods to work around this. :(

Show more comments
avatar image YinXiaozhou · Sep 29, 2016 at 08:36 AM 0
Share

Can you give a screen shot for the prefab's inspector. Also where are these Hexagon(xxx) located?

avatar image Artemiye YinXiaozhou · Sep 29, 2016 at 02:15 PM 0
Share

Sure, here is the default prefab:

alt text

I've actually found a temporary work around, which I'll edit into the original post. The hexagons are located in the scene (they're also each an instance of a prefab).

enemy.png (33.3 kB)
avatar image YinXiaozhou · Sep 30, 2016 at 02:38 AM 0
Share

Well, you could look into the scene file and find out what's going on there. Unity's scene file will list out the prefab changes separately. If you can reproduce this issue, plz send a bug report to Unity.

avatar image Artemiye YinXiaozhou · Oct 03, 2016 at 10:58 PM 0
Share

Will do, thanks.

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

86 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 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 avatar image avatar image

Related Questions

EditorWindow and serialization of scene objects 0 Answers

UnityEvent with all derived types in listeners serialized in Inspector 0 Answers

Storing array of game objects in editor mode and click play corrupt the array.,Can't get game object from array after click on the start. 0 Answers

A script behaviour has a different serialization layout... 7 Answers

GUI.Window. Wanting to allow clickthrough 0 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