Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Selzier · Sep 06, 2016 at 04:37 PM · editor-scriptingchangevalueplayer settingsplayersettings

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eexxoo · Aug 07, 2017 at 12:13 PM 0
Share

Did you managed to find a solution? I am very interested in this.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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 ?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Selzier · Sep 06, 2016 at 07:47 PM 0
Share

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.

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image guneyozsan · Dec 10, 2018 at 12:43 AM 0
Share

All PlayerSettings properties are static so this doesn't work.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges