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

(8572)

2D

(207)

Ads

(30)

AI & Navigation

(51)

Analytics

(82)

Animation

(284)

Asset Store

(199)

Assets

(479)

Audio

(147)

Cloud Build

(91)

Collaborate

(27)

Docs & Tutorials

(181)

Editor

(1984)

Everyplay

(13)

Game Performance Reporting

(10)

General

(775)

Graphics

(721)

GUI

(341)

Input

(139)

Licensing

(70)

Networking

(150)

Physics

(317)

Platforms

(394)

Profiling & Optimization

(65)

Runtime

(148)

Scripting

(964)

Terrain

(146)

WebGL

(128)