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

(9039)

2D

(221)

Ads

(40)

AI & Navigation

(67)

Analytics

(92)

Animation

(304)

Asset Store

(223)

Assets

(489)

Audio

(157)

Cloud Build

(94)

Collaborate

(31)

Docs & Tutorials

(197)

Editor

(2084)

Everyplay

(13)

Game Performance Reporting

(13)

General

(812)

Graphics

(762)

GUI

(363)

Input

(145)

Licensing

(73)

Networking

(158)

Physics

(342)

Platforms

(403)

Profiling & Optimization

(69)

Runtime

(161)

Scripting

(1015)

Terrain

(152)

WebGL

(131)