Search Feedback

35
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

(9816)

2D

(259)

Ads

(49)

AI & Navigation

(77)

Analytics

(114)

Animation

(359)

Asset Store

(264)

Assets

(508)

Audio

(166)

Cloud Build

(119)

Collaborate

(44)

Docs & Tutorials

(216)

Editor

(2269)

Everyplay

(13)

Game Performance Reporting

(16)

General

(880)

Graphics

(814)

GUI

(394)

Input

(155)

Licensing

(82)

Networking

(174)

Physics

(361)

Platforms

(425)

Profiling & Optimization

(76)

Runtime

(168)

Scripting

(1087)

Terrain

(162)

WebGL

(138)