Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Assign scene to variable in a scriptable object

Discussion in 'Scripting' started by TeamDefiant, May 20, 2021.

  1. TeamDefiant

    TeamDefiant

    Joined:
    Mar 29, 2017
    Posts:
    50
    Hello, I'm trying to create a game environment system using scriptable objects and was wondering if there was a way to assign a unity scene in the inspector so it can be loaded as a subscene in the game?

    For example, all the game mechanics exist in the main scene, but the background environments are all in seperate sub scenes. If I wanted a space level, I'd just unload the existing subscene and load in the space scene.

    If I try to add a public Scene variable in my scriptable object, the variable name appears in the inspector, but not the field where I can drag the scene fine onto it.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Natively no, but you can just put the name of the scene in as a string.

    There are lots of people who have written little scripts to let you drag scenes in, but I've never trusted them in case the references get mucked up. I just use strings.
     
  3. TeamDefiant

    TeamDefiant

    Joined:
    Mar 29, 2017
    Posts:
    50
    Kurt-Dekker likes this.