Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
7
Question by Mike J · Mar 09, 2013 at 06:44 AM · assetscriptableobjectmono-behaviour

Detect when a property is changed on a ScriptableObject Asset

I have added a menu command that creates a new ScriptableObject and saves it as an asset. I have also created a MonoBehaviour that has my ScriptableObject as a property. I can add my behaviour to a game object and select my asset using the asset selector. My problem is that when I change a value on my asset, how does my behaviour detect the change and update accordingly?

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 Mike J · Mar 09, 2013 at 02:10 PM 0
Share

As a temporary work around I have am storing the old value of the scriptable object properties in my behaviour and then checking each frame to see if they have changed. This is how I detect that the user has edited the behaviour properties. It works, but is starting to get to be a lot of book keeping.

1 Reply

· Add your reply
  • Sort: 
avatar image
14

Answer by MattRix · Jul 27, 2015 at 02:53 PM

You can use OnValidate() in ScriptableObjects, but Unity forgot to document it for some reason.

Comment
Add comment · Show 3 · 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 Ash-Blue · Jul 25, 2016 at 12:17 AM 0
Share

According to this, OnValidate kinda sorta works with ScriptabeObject atm. Can you provide a working sample? I can't seem to make this work on my end.

https://feedback.unity3d.com/suggestions/onvalidate-callback-for-scriptableobjects

avatar image felixpk · Mar 29, 2017 at 01:51 PM 1
Share

This is awesome, thank you! I wasn't even thinking about just testing it!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 [CreateAsset$$anonymous$$enu()]
 public class ColorScheme : ScriptableObject {
     public Color dialogBackground;
     public Color sceneTransition;
 
     public void OnValidate() {
         Debug.Log(Time.time);
     }
 }

Thats perfectly working example.

avatar image ModLunar · Jun 09, 2018 at 08:50 PM 0
Share

Ahhh yes thank you! I didn't see it as part of the Unity messages recognized by Visual Studio so I was just like ah it doesn't work.. lol so glad it does though!

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

14 People are following this question.

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

Related Questions

How to reference variable in ScriptableObject(.asset files)? 1 Answer

Prefab as a subasset of a ScriptableObject 0 Answers

Why does my List overwrite itself when using .Add? 2 Answers

Auto removing entries form a scriptableobject list when asset is deleted. 0 Answers

How to make game moddable? 1 Answer


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