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 Anton Grigoryev · Feb 18, 2011 at 04:18 PM · vector3standaloneserializefield

[SerializeField] private Vector3[] array works in editor/doesn't work in stand-alone build

I have class like

[ExecuteInEditMode] public class Trajectory : MonoBehaviour { [SerializeField] private Vector3[] points;

private void Awake() { Debug.Log(string.Format("Adding {0} saved points to trajectory.", points.Length)); } }

I assign array in the Editor, it contains value when I click "Play", but doesn't work in Windows/Mac Standalone builds. In Mac the log is:

Adding 0 saved points to trajectory.

In Windows:

Adding 1 saved points to trajectory.

I'm using Unity 3.2. Any ideas?

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 yoyo · Feb 18, 2011 at 05:40 PM 0
Share

I assume you're not in play mode while adding the points (they would disappear when you stop playing). I wonder if [ExecuteInEdit$$anonymous$$ode] somehow fools Unity into thinking you're in play mode and therefore changes shouldn't be saved? Complete speculation, but try removing ExecuteInEdit$$anonymous$$ode and see if it makes any difference.

avatar image Anton Grigoryev · Feb 21, 2011 at 06:55 AM 0
Share

I add points using class derived from Editor. The situation was that I added points, click Play and saw result as trajectory. Ok, points are saved. But when I compiled stand-alone application (e.g. for Windows), I got no points. This is was due to conditionally serialized field before my serialized array(((

1 Reply

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

Answer by Anton Grigoryev · Feb 18, 2011 at 05:39 PM

I think I've found the answer. In my code there was conditionally serialized field before my array:

[ExecuteInEditMode] public class Trajectory : MonoBehaviour { #if UNITY_EDITOR

[SerializeField] private bool smart;

endif

[SerializeField] private Vector3[] points;

private void Awake() { Debug.Log(string.Format("Adding {0} saved points to trajectory.", points.Length)); } }

Data was saved in editor, but in stand-alone there is no field 'smart' and boolean value 0 or 1 (if smart was set to false or true) as size of the Vector is loaded.

Do you have any idea how to improve the code above to prevent such errors in the future? Or maybe some related information? I'm using this flag only in editor to edit trajectory. How can I refactor the code?

Comment
Add comment · Show 1 · 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 yoyo · Feb 18, 2011 at 10:10 PM 0
Share

The Unity serialization process deals with fields being added and removed. I had assumed this would work for conditionally compiled fields as well, but perhaps not. So I would not expect the value of "smart" to be deserialized into "points". But I could be wrong -- just yesterday I added some #if UNITY_EDITOR fields to my project as well, so I'd like to know the answer!

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

No one has followed this question yet.

Related Questions

SerializeField does not work when a value set using code 0 Answers

Can a GameObject be serialized? 1 Answer

Mac Standalone mark .app as executable 1 Answer

Trying to open a windows standalone exe from another windows via SSH. but there's no video. 1 Answer

Need help with rotation 4 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