A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.unity3d.com/Manual/script-serialization-best-practices.html below:

Unity - Manual: Serialization best practices

Integrating third-party code libraries (plug-ins)

Serialization best practices

Apply the following coding practices and organizational principles to prevent errors and optimize serialization performance in your project.

Thread safety

Most Unity APIs can only be called from the main thread. Don’t call Unity APIs from constructors and field initializers of serializable types because these run on a separate loading thread.

In development buildsA development build includes debug symbols and enables the Profiler. More info
See in Glossary
, Unity throws an error if you attempt to call main thread APIs from a loading thread. In a release build, the code runs without errors but can produce crashes and other unexpected behavior in your application.

Tip: To reduce the risk of errors during serialization, don’t call API methods that can influence the project state or that involve other Unity objects. APIs that are safe to call include Debug.Log and those that work on simple data types, such as math functions and Vector3.

Finalizers

Don’t initiate serialization from finalizer methods. Finalizers don’t run on the main thread. The garbage collector determines when they run and in some circumstances they might not run at all.

Attempting to serialize data from a finalizer can lead to unexpected behavior and crashes. For more information, refer to the Microsoft documentation on Finalizers.

Organizing your data

You can organize your data as follows to ensure optimal use of Unity’s serialization:

Additional resources

Integrating third-party code libraries (plug-ins)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4