1
\$\begingroup\$

I'm a bit of a novice to lighting, but I think what I want to do is possible, so please bear with me.

Due to the nature of my game, I've taken an approach where a singular scene game is where all of the gameplay occurs.

For each level, I'm arranging all the GameObjects and Terrain in a secondary scene (named testbed) to my liking. Once I've got it to my liking, I save that to a prefab, which in turn is saved to an AssetBundle. I also generate the lighting at this point, which I can see appear in my project under a Assets/Scenes/testbed/ folder.

At runtime, a script in the game scene reads the appropriate AssetBundle, and then loads & positions all of my objects and characters. Everything about this works, except for updating the lighting.

My approach is to store references to the lighting textures that have been output into the aforementioned testbed folder via a ScriptableObject (after trying and failing to use the LightingData object that appearred in this same folder):

scriptable object for lighting

Then, when I'm loading my level up into the game scene, this block is executed:

    public void LoadLighting(LevelKey key)
    {
        var data = levelMap.metaData.Find(it => it.key == key);
        var directions = data.lightData.directions;
        var lights = data.lightData.lights;

        var lightmaps = new LightmapData[directions.Length];
        for (int i = 0; i < directions.Length && i < lights.Length; i++)
        {
            var lightmapData = new LightmapData();
            lightmapData.lightmapDir = directions[i];
            lightmapData.lightmapColor = lights[i];

            lightmaps[i] = lightmapData;
        }

        LightmapSettings.lightmaps = lightmaps;
    }

Based on a lot of searching, this should cause something to happen, but I can't detect any change in the scene.

Does what I'm trying make any sense? Should I just scrap this and make dozens of different scenes (which I'm trying to avoid) instead? Really any advice here is appreciated.

\$\endgroup\$
4
  • \$\begingroup\$ Why are you trying to avoid multiple scenes? That seems no more convoluted than your current workflow with prefabs. \$\endgroup\$ Commented Jan 7, 2020 at 0:16
  • \$\begingroup\$ @DMGregory good question - I think I avoided it subconsciously since the last time I worked on a similarly structured game (using Unity 4), the prefab tools were a lot less fleshed out, and I ended up having to manually make dozens of edits in individual scenes. I should probably switch back, but I thought I should see if the above possible given I'm already at this point. \$\endgroup\$ Commented Jan 7, 2020 at 0:30
  • \$\begingroup\$ @DMGregory also, most of the info I could find on this topic is from Unity Answers 3 - 5 years ago, and wanted to create a record on stack exchange if possible. \$\endgroup\$ Commented Jan 7, 2020 at 0:31
  • \$\begingroup\$ Additive scene loading and multi-scene editing in modern versions of the engine should help with those aspects. \$\endgroup\$ Commented Jan 7, 2020 at 0:46

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.