lassade / Sprite2DBakedLighting

Unity enlighten does not bake lighting into sprites. This script reaplace (temporarily) every sprite in the open scenes by a mesh so the ligth can be baked and then transfered for the SpriteRenderer.
MIT License
30 stars 3 forks source link

Lightmaps disappear after playmode #2

Open empika opened 6 years ago

empika commented 6 years ago

Hey,

Thanks for the excellent scripts!

I have an issue where lightmaps disappear from the SpriteRenderers after exiting play mode in the editor (they are still visible in play mode if started again). Retransferring the settings from the values cached in BakedLigthingSpriteData fixes the issue until the next time you play.

Any ideas what could be causing this?

Many thanks

lassade commented 6 years ago

The BakedLigthingSpriteData depends on the editor to execute its function and then transfer the lightmap data to the sprintesrender, this data isn't serialized so it depends on the BakedLigthingSpriteData to set everything.

What you need to do is add an update method that only works in editor and if isn't playing like so:

// This method will execute at every editor update event since the class have the ExecuteInEditMode attribute
[Conditional("UNITY_EDITOR")]
void Update()
{
    if (Application.isPlaying) return;
    TransferLightmapData();
}

Try this and let me know if works.

empika commented 6 years ago

Thanks for the swift reply.

That code didn't quite work, but sticking an [ExecuteInEditMode] property on the BakedLigthingSpriteData class and adding the following seems to fix it:

private void OnRenderObject()
{
    if (!Application.isPlaying)
    {
        TransferLightmapData();
    }
}