Search Unity

Can't have more than 1 different skybox per scene

Discussion in 'Editor & General Support' started by brunoenvia, Nov 11, 2019.

  1. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    52
    anyone know why is this happening?
    i'm trying to have a different skybox per scene but when i change a skybox on
    one scene, it changes for all my scenes
     
  2. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,343
    This setting applies to all scenes.

    You can change your skybox by script using RenderSettings: https://docs.unity3d.com/ScriptReference/RenderSettings.html

    Code (CSharp):
    1. RenderSettings.skybox = yourNewSkybox;
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    7,424
  4. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    52
    won't this give the same result, since i have to change the script for a different skybox?

    i already tried to add to camera and it changes for all scenes
     
  5. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,343
    Using if statements could be enough, depending on what you want to do. The script below works, I've tested it:

    Script:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class GameManager : MonoBehaviour
    5. {
    6.  
    7.     private static GameManager gameManager;
    8.  
    9.     public Material skybox_a;
    10.     public Material skybox_b;
    11.  
    12.     private void Awake()
    13.     {
    14.         if(gameManager != null && gameManager != this)
    15.         {
    16.             Destroy(gameObject);
    17.             return;
    18.         }
    19.  
    20.         gameManager = this;
    21.  
    22.         DontDestroyOnLoad(gameObject);
    23.     }
    24.     private void Start()
    25.     {
    26.         Scene scene = SceneManager.GetActiveScene();
    27.  
    28.         if(scene.name == "Scene_a")
    29.             RenderSettings.skybox = skybox_a;
    30.         else if(scene.name == "Scene_b")
    31.             RenderSettings.skybox = skybox_b;
    32.     }
    33. }
     
    Last edited: Nov 12, 2019
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    7,424
    Only if you're using the same camera object for all scenes.
     
  7. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,343
    Cameras use the skybox that is defined in the Lighting settings. ;)
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    7,424
    Yes but there is a separate component you can add to cameras to do per camera skyboxes. That's what I'm talking about. You can even have multiple cameras in the same scene with different skyboxes running at the same time. You add the skybox material to this component attached to the camera instead of the main rendersettings skybox.

    From my previous link:
    https://docs.unity3d.com/Manual/class-Skybox.html
     
  9. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,343
    Okay, my bad, I tried this and it works.

    But I prefer my script. :p
     
    Joe-Censored likes this.
  10. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    52
    i think it works if you add diferent cameras to different scenes i will try this thank you
     
    Joe-Censored likes this.
unityunity