Topic: Problem with LinkedObserver

Hey, I have a problem with LinkedObserver:

I have Source Prefab class with some ValueObserver called "value" and Watcher Prefab class with LinkedObserver called "_state"

Then, in Unity Editor I set _state linked observer to watch SourcePrefab.value

In WatcherPrefab I do:

    private void Start() {
      _state.AddListener(onStateChange);
    }

It doesn't work as Unity somehow does not call LinkedObserver's constructor, caches _isObserverInitialized as "true" (I checked with debugger) and _state.Observer remains null, despite it being set in the editor.

I use Unity 6

Re: Problem with LinkedObserver

Hi.

Unity should not call the constructor.
The constructor is for you (users) so you can dynamically create LinkedObserver's.

_isObserverInitialized should not be serialized or cached because it is private and marked using NonSerialized attribute.

From your description I think the problem is in cross scene references.
In short: project elements can only reference other project elements. Scene elements can refer to elements of the current scene or project.
But a project element cannot refer to a scene, and an element in scene A cannot refer to an element in scene B.
Unity does not support this.

If the problem remains please send me your project, I will check it.
P.S. I don't need your working project. Any temporary project that shows the problem is enough for testing.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Problem with LinkedObserver

Thanks, I'll message you on Discord