- Home /
Editor Scripting: How To Detect a Change in Player Settings
I want to detect when a change is made to player settings. Specifically, when the Unity user makes a change to the Android "Bundle Identifier", I want to call some Editor scripting code.
OnValidate() works with MonoBehaviours and ScriptableObjects: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
But PlayerSettings is a Unity Object:
public sealed class PlayerSettings : UnityEngine.Object {
I can make a Custom Inspector for PlayerSettings:
[CustomEditor(typeof(PlayerSettings))]
public class PlayerSettingsValidate : Editor {
public override void OnInspectorGUI() {
DrawDefaultInspector();
}
public void OnValidate() {
Debug.Log("You changed something");
}
}
But DrawDefaultInspector() does not work, nor does OnValidate().
How can I detect when a change is made to a Player Settings value?
Did you managed to find a solution? I am very interested in this.
Answer by metalted · Sep 06, 2016 at 07:13 PM
If you want to detect changes in the inspector, you can use :
if(DrawDefaultInspector()){
//Code here
}
Is this what you are looking for ?
Problem clearly states that DrawDefaultInspector() does not work with PlayerSettings. Additionally, the proper way to achieve what you are doing is to use OnValidate(), which does not work with PlayerSettings either.
Answer by cgarossi · Aug 07, 2017 at 12:27 PM
You'll need a wrapper class since your PlayerSettings does not derive from Monobehaviour and therefore is not part of the regular update cycle.
Create a wrapper class, which holds your PlayerSettings class as a field. Then create a customer editor which exposes properties of player settings to the inspector.
For example:
public class PlayerSettingsWrapper : Monobehaviour
{
private PlayerSettings _settings;
public int ASetting;
public void UpateSettings()
{
_settings.ASetting = ASetting;
}
}
Modify your editor to read PlayerSettingsWrapper instead and it should communicate the change.
All PlayerSettings properties are static so this doesn't work.
Your answer
Follow this Question
Related Questions
(C#) Return Float Variable to previous value 1 Answer
Find PlayerSettings Architecture (iOS) from Script 1 Answer
How to set ProjectSettings via script 1 Answer
Animation not recognizing small differences 0 Answers
The Checkbox for ''virtual reality supported' unchecks itself automatically? 0 Answers