You can use the GameObject Flags to have it behave in different ways. This is especially useful when you're creating the GameObject via code. See below on how to use the GameObject.Flags enum property.
GameObject.Flags = (GameObjectFlags)128; //or GameObject.Flags = GameObjectFlags.DontDestroyOnLoad;
None = 0, /// Hide this object in heirachy/inspector Hidden = 1, /// Don't save this object to disk, or when duplicating NotSaved = 2, /// Auto created - it's a bone, driven by animation Bone = 4, /// Auto created - it's an attachment Attachment = 8, /// There's something wrong with this Error = 16, /// Loading something Loading = 32, /// Is in the process of deserializing Deserializing = 64, /// When loading a new scene, keep this gameobject active DontDestroyOnLoad = 128, /// Keep local - don't network this object as part of the scene snapshot NotNetworked = 256, /// In the process of refreshing from the network [Obsolete] Refreshing = 512, /// Stops animation stomping the bone, will use the bone's local position ProceduralBone = 1024, /// Only exists in the editor. Don't spawn it in game. EditorOnly = 2048, /// Ignore the parent transform. Basically, position: absolute for gameobjects. Absolute = 4096, /// The position of this object is controlled by by physics - usually via a RigidBody component PhysicsBone = 8192, /// Stops this object being interpolated, either via the network system or the physics system NoInterpolation = 16384