How to keep an instance through scenes

Hello everyone, we’re working on our first Multiplayer Application using our Server Backend which is Planned for Open-Source release at a later date, however with using Unity3D we are having an issue with understanding how to keep the instance of the TcpClient connection alive through scenes in the Client. After some research we’ve discovered the method using (DontDestroyOnLoad) however this seems to not work how we want it to, as the Script starts becoming duplicated after loading the same scene multiple times. Basically, what we need to do is have a script that is running throughout the entire lifespan of the application which can be referenced from scripts at any moment. Writing the test-client for this was easy using C#~ However, now that we’re working with Unity and it’s transition of Scenes, how to go about properly doing this is completely boggling our developers minds. I guess that’s one of the things you’ll run into when the team isn’t familiar with the tools provided.

The way I plan to do this is by creating all of my persistent scripts in an “Entry” scene - that is never revisited after the game starts. This way I don’t have to worry about duplicates being instantiated and I know all of my objects will follow the player from scene to scene.

Do what @TrevorP suggests or add an “ThereCanBeOnlyOne” script


  using System.Collections;
  using UnityEngine;

   public class ThereCanBeOnlyOne : MonoBehaviour {
            public static ThereCanBeOnlyOne instance;

            void Awake() {
                if(instance != null && instance != this) {
                instance = this;