Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

ScriptableObject Update() error

Discussion in 'Scripting' started by Flavelius, Dec 15, 2015.

Thread Status:
Not open for further replies.
  1. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Hi,
    i have a ScriptableObject derived class where i want to have a method named "Update" with a float parameter in.
    Unfortunately Unity tells me:
    "Script error (ClassName): Update() can not take parameters."
    But it's a ScriptableObject, not a Monobehaviour.. (?)
     
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    You're right, that is interesting. There is no mention of an Update() in the API for a ScriptableObject. It is, however, receiving messages of the other kinds (OnDestroy, OnEnable). It could well be hooked up to a interface in Object, which handles all those events, including Update(), which is just not something they show to us? This is a total guess. Long and short of it though. It looks like you can't have a method named Update() in ScriptableObject. So long as you're definitely not inheriting from Monobehaviour...
     
  3. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Sounds plausable. And if that's the case, they should mention that in the documentation.
    ScriptableObjects are getting more and more weird :p. It's time for Unity to support polymorphism in its serialization system!
     
    Nigey likes this.
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,356
    This definitely deserves a bug report.
     
  5. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    " polymorphism" Is on the way. Also they are working on a new version of Monobehaviour (which maybe ships in 5.4?), and maybe ScriptableObject? I can't remember right.
     
    Flavelius likes this.
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,356
    There's a new MonoDevelop out in 5.3, are you mixing those?
     
  7. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    I don't remeber the versions, still on 5.2.2
     
  8. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    I saw that too, somewhere. I think they mentioned, they want to get rid of the many special case treatments inside Monobehaviour. But as far as i remember that was more a nice-to-have.
     
  9. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,432
    I imagine this 'warning' is shown in case someone puts Update with a parameter with a monobehaviour by accident or whatnot. And under the hood, scriptable objects are treated like monobehaviours in a lot of ways, being one of the two custom assets we're allowed to make in Unity. So probably a case of mistaken identity by whatever code checks this.

    Scriptable objects don't get an Update call which makes this even more amusing.

    So did anyone report this bug 9 years ago?
     
    Bunny83 likes this.
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,765
    You'll have a better chance of the beta team noticing it in the section for the beta.

    https://forum.unity.com/forums/unity-6-beta.978/
     
    Spy-Master, Bunny83 and spiney199 like this.
  11. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,429
    I once heard a Unity engine guy (I forget who) assert that internally they were actually the same C++ structure (ScriptableObject and MonoBehaviour) with different features enabled.

    That would likely mean that the same automated "find-and-bind" of the Update() method would complain regardless of what the derived C# side object was.
     
    CodeSmile, Spy-Master, Sluggy and 2 others like this.
  12. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,432
    Yeah I believe that also gets mentioned - or something to that effect - in the "Overthrowing the MonoBehaviour Tyranny" Unite video. Open a scriptable object asset in a test editor and one of the first things you see in the yaml is 'Monobehaviour', too, so what you're saying makes perfect sense.

    Wonder how old the code in that part in the engine is...
     
    Kurt-Dekker, Spy-Master and Bunny83 like this.
  13. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,533
    Yes @ 9m 42s
    It's a good talk in case anyone has missed it.
     
    Bunny83 and spiney199 like this.
  14. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    1,023
    Pretty sure that was Richard Fine aka superpig.
     
  15. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,839
    Thread is very old, so I'm gonna lock it up. Feel free to create a new thread to continue the conversation.
     
Thread Status:
Not open for further replies.