Search Feedback

30
votes

OnValidate callback for any class marked Serializable

Scripting

-

-

It would be nice if any class with the Serializable attribute could contain an OnValidate method and, if that class is contained by a MonoBehaviour or ScriptableObject and thus exposed in the inspector, have that OnValidate method called similarly to how it is called for MonoBehaviours (i.e. whenever a serialized field is changed).

Ideally, this method should be allowed to access Unity methods which are not allowed by ISerializationCallbackReceiver.OnAfterDeserialized.

A class implementing this method could look like this:

[Serializable]
public class MySerializableClass
{
[SerializeField]
private string someField;

public void OnValidate()
{
Debug.LogError("OnValidate()");
//perform validation code here
}
}

See http://answers.unity3d.com/questions/1345501/how-can-i-get-functionality-similar-to-onvalidate.html for a small discussion regarding this.

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(8816)

2D

(213)

Ads

(40)

AI & Navigation

(59)

Analytics

(88)

Animation

(292)

Asset Store

(212)

Assets

(485)

Audio

(152)

Cloud Build

(93)

Collaborate

(28)

Docs & Tutorials

(190)

Editor

(2034)

Everyplay

(13)

Game Performance Reporting

(11)

General

(796)

Graphics

(743)

GUI

(353)

Input

(143)

Licensing

(73)

Networking

(153)

Physics

(330)

Platforms

(399)

Profiling & Optimization

(66)

Runtime

(153)

Scripting

(990)

Terrain

(149)

WebGL

(130)