Dontdestroyonload and interfaces

Hi, please consider the following: (all in c#)

interfaces:

public interface ITypeA 
{
    ITypeB { get; set; }
}
public interface ITypeB { }

container class:

public class OuterContainer : MonoBehaviour, ITypeA
{
    void Awake()
    {
        if (InnerObjectB == null) InnerObjectB = AddComponent<InnerClass>();
    }

    ITypeB InnerObjectB { get; set; }
}

inner class:

public class InnerClass : MonoBehaviour, ITypeB
{
    // Some implementation
}

script:

private OuterContainer storage;

void Awake()
{
    DontDestroyOnLoad(this);
    var component = AddComponent<OuterContainer >();
    storage = component;
}

What I am seeing happen is the following:

The normal MonoBehaviour methods (Awake, Start, Update etc) are called on all objects (the script, Outer container and inner class) as normal in the first scene. Then when the scene is changed using LoadLevel although the script still is called as normal, the ‘InnerClass’ object no longer receives any MonoBehaviour calls (although it does exist!)

Can anybody shed any light on why this might be happening?

I don’t fully understand your context, but try DontDestroyOnLoad(gameobject) instead of DontDestroyOnLoad(this). In a component “this” refers to the component, not the game object. According to the documentation it shouldn’t matter, but docs can lie.

Check if the behaviours are still present on the game object in the editor by pausing the game after a level load and inspecting the objects in the inspector.

Objects can still exist in the C# VM after they have been “destroyed” by Unity because Unity. Destroying an object in Unity only means that it is not part of the running scene and Unity doesn’t hold any references to it anymore. But the object might not have been GC’ed yet and if your in-scene objects still hold a reference to it it won’t get GC’ed.