Forum rules - please read before posting.

Scene changer destroying Player

I have a Player prefab in every scene (including loading) as I am using Opsive Third Person Controller and it throws 999+ null exception errors if it gets destroyed or not in the scene.

I understand the SceneChanger.cs destroys this player when transitioning, but is there a way for it not to do this ? What are the consequences if this is stopped?

I never used to get these errors in Unity 2018, but I think 2019 is a lot faster so it picks these up.

Thanks!

Comments

  • What are the exact error messages, and where are they coming from - Opsive?

    If your Player is part of the scene file, SceneChanger isn't strictly deleting it - rather it's just being removed as part of the scene itself as part of the scene-switching process.

    You can avoid this by making the Player a prefab and spawning it in at runtime, but this may need further tweaking from the Opsive side of things to get this to be possible.

  • Errors were from Opsive .

    "Null Reference Exception. Object reference not set to an instance of an object"
    Opsive.ThirdPersonController.RigidbodyCharacterController.Update()

    Hundreds of them.

    But I figured it out. It was happening on my Main Menu scene where I have a New Game button. I was using Restart Game to a new scene, and in the one second before to reaches the loading scene, my player loses all it's references.

    Is it possible to customize the restart game ? I have a lot of Remember scripts.

  • Customise in what way, and what references are you referring to?

    Is your Player spawned in or part of scene files?

  • Customize as in just reset all variables and reset all remember components to original values. That's all I need.

    My Player is not spawned at runtime, it is part of scene files. If I use a restart game, Opsive thinks my Player has no weapon, no health, no hair and teeth and whatever else it checks.

    I'll just try spawning it at runtime and see if that works. Thanks for your help!

  • I misspoke - AC does destroy the Player upon restarting, though this likely should only be in the case that the Player is spawned.

    Open up KickStarter.cs, and replace the code block:

    if (KickStarter.player)
    {
        DestroyImmediate (KickStarter.player.gameObject);
    }
    

    And replace with:

    if (KickStarter.player && !KickStarter.player.IsLocalPlayer ())
    {
        DestroyImmediate (KickStarter.player.gameObject);
    }
    

    Does that resolve it?

  • Whoops, sorry forgot to mention I'm on AC 1.70.4!

    Reason is I'm porting to Xbox and I just got the AC save files working perfectly now to their connected storage, so I am kind of reluctant to upgrade.

    Anyway you have pointed me in the right direction, as I can see in the Kickstarter.cs a static void ResetPlayer that destroys the player. I'll try and modify it to include not the local player and see what happens.

    Thanks!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.