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

(9242)

2D

(233)

Ads

(42)

AI & Navigation

(70)

Analytics

(103)

Animation

(318)

Asset Store

(234)

Assets

(493)

Audio

(158)

Cloud Build

(98)

Collaborate

(33)

Docs & Tutorials

(202)

Editor

(2137)

Everyplay

(13)

Game Performance Reporting

(15)

General

(825)

Graphics

(783)

GUI

(371)

Input

(147)

Licensing

(76)

Networking

(163)

Physics

(346)

Platforms

(407)

Profiling & Optimization

(71)

Runtime

(164)

Scripting

(1030)

Terrain

(151)

WebGL

(132)