Linq performance

Defiantly not.
It’s okay for me to use Debug.Log, I didn’t know that:

I found this Unity forum. That kinda explained the issue, but not solving it.

Documentation says “Awake is called as the ScriptableObject script starts.” but no one told you that SO script starts when you hit Play in the editor:)

Scriptable objects are instantiated in edit mode (as all other referenced assets) and not re-instantiated or reloaded when you start playing in the editor, this allows fast start without loading everything every time.

So documentation is true, while your expectations are false. Sorry.

P.S. I was blocked by this feature too and I do understand your pain.

There are also some solutions:

Im not sure if will it run in the build correctly or not.

[InitializeOnLoad]
public class Test : ScriptableObject {
 
     void OnEnable () {
           Debug.Log ("Unity editor has just started up!");
     }
 
}

Now the method is called whenever the ScriptableObject is created and whenever Unity is launched.

Also, they come up with that:

using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
 
    [InitializeOnLoad]
    public abstract class ManagedObject : ScriptableObject
    {
        abstract protected void OnBegin();
        abstract protected void OnEnd();
 
#if UNITY_EDITOR
        protected void OnEnable()
        {
            EditorApplication.playModeStateChanged += OnPlayStateChange;
        }
 
        protected void OnDisable()
        {
            EditorApplication.playModeStateChanged -= OnPlayStateChange;
        }
 
        void OnPlayStateChange(PlayModeStateChange state)
        {
            if(state == PlayModeStateChange.EnteredPlayMode)
            {
                OnBegin();
            }
            else if(state == PlayModeStateChange.ExitingPlayMode)
            {
                OnEnd();
            }
        }
#else
        protected void OnEnable()
        {
            OnBegin();
        }
 
        protected void OnDisable()
        {
            OnEnd();
        }
#endif
    }

And when you inherit from it, you implement the OnBegin and OnEnd methods. It runs on starting unity editor, on entering/exiting playmode and on starting your built application.

I will be happy to hear your opinion about that solutions. May be better approach would be to use the method that I mentioned earlier.

UPD:
I will use CalculateDelta because other approaches fix only Scriptable Object and not classes in it.

Finally, all working correctly.
I refactored the code according to your suggestions and I got a problem with level-up) Sometimes it levels up to the full 100 level and sometimes to 6-5 levels.
It was a tricky issue that had been noticed when I started to write a test (I didn’t finish it, to be honest, but it did its function :grin:)
So the problem was there

or there

they both behave similarly and calculate delta once, but it required dynamic calculation, which caused weird behavior.

I’m very happy, that issue is gone and now all works fine :tada:

Thank you for your help in resolving issues that have been unrelated to the topic for some time. :heart:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms