Version: Unity 6.6 Beta (6000.6)
LanguageEnglish
  • C#

BaseField<T0>.IgnoreValidation

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public IgnoreValidationScope<TValueType> IgnoreValidation();

Returns

IgnoreValidationScope<TValueType> A scope that re-enables validation when disposed.

Description

Disables BaseField<T0>.onValidateValue until the returned scope is disposed.

Scope this method with a using statement and use it with the BaseField<T0>.value setter or BaseField<T0>.SetValueWithoutNotify to assign a value that bypasses validation. Only BaseField<T0>.value results in a ChangeEvent<T0>. The scope can be nested safely.

The following example sets a value that skips the field's validation:

using UnityEngine;
using UnityEngine.UIElements;

namespace MyNamespace { public class BaseFieldIgnoreValidationExample { // The field clamps its value to a maximum. IgnoreValidation sets a value that skips the clamp. public IntegerField CreateField() { var field = new IntegerField("Value"); const int max = 100;

field.onValidateValue += v => Mathf.Min(v, max);

// Set a value above the maximum without clamping it. using (field.IgnoreValidation()) field.value = 500;

return field; } } }