Download

The Object is both "null" and "not null"

What’s the problem? This is really weird. I tried to use both UObject and None Class.

I’ve been dealing with this problem for a week.


class XXX_API UGameManager : public UGameInstance
    {
    TUniquePtr<LevelManager> level_manager;
    ...
    Init(){
    level_manager = TUniquePtr<LevelManager>(new LevelManager());
    }
    ....
    }

    class LevelManager 
    {
    ....
    }


    //Ticks per second
    if (level_manager.Get() == nullptr)
    {
        UE_LOG(LogTemp, Warning, L"null")
    }
    else
    {
        UE_LOG(LogTemp, Warning, L"not null")
    }

**When I focus on the New Editor Window or move it, this is the result:

**

Check the ‘this’ pointer, it’s most likely not the same in both cases.

The reason you get both types of messages is because you have multiple instances of your GameInstance spawned. This is normal when you’re playing in the editor.

Thank you. I noticed that there are 2 GameInstance.

But, What is the reason and how can i prevent it? Which one will affect my game? In this case, I can’t work on my project.

Also it is better to check UObjects with IsValid(…) There are some situations when pointer is no null but accessing it will fail.

It’s difficult to tell from your description. If I were to guess, I’d say that your old GameInstance hasn’t been garbage collected yet and the timer lingers. Try clearing the timer when the GameInstance shuts down and see if that helps?

Instance of GameInstance also inherits FTickableGameObject and I don’t use timer. When I close the game window, default GameInstance Process should be destroyed, Am i wrong?

I’ve only seen this happen under the circumstances I described above.

What is the value of IsValid() in Tick when this happens? It should be false.