Author Topic: Volumetric lights in prefabs  (Read 243 times)

trueh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Volumetric lights in prefabs
« on: November 23, 2020, 12:19:33 PM »
Hello:

I am trying to create a prefab consisting in a showcase model with volumetric lights inside it but I am getting the following error when I drag the GameObject from the hierarchy to the project view:

Code
[Exception] ArgumentException: UnpackPrefabInstance must be called with a root Prefab instance GameObject.
PrefabUtility.UnpackPrefabInstance() at <bd45cfd5e8c2437da9b5cc29b19f336f>:0

VolumetricLight.<UnPrefabFirst>b__93_0() at /VolumetricLights/Scripts/VolumetricLight.cs:102
100:   if (prefabInstanceStatus != UnityEditor.PrefabInstanceStatus.NotAPrefab && prefabInstanceStatus != UnityEditor.PrefabInstanceStatus.Disconnected) {
101:       UnityEditor.EditorApplication.delayCall += () => {
-->102:           UnityEditor.PrefabUtility.UnpackPrefabInstance(gameObject, UnityEditor.PrefabUnpackMode.Completely, UnityEditor.InteractionMode.AutomatedAction);
103:           RefreshInternal();
104:       };

EditorApplication.Internal_CallDelayFunctions() at <bd45cfd5e8c2437da9b5cc29b19f336f>:0

I am using the latest version of Volumetric Lights (3.0.1) with Unity 2020.1.14f1 and the built-in pipeline.

I am pretty sure that my hierarchy is not containing any other prefab.

Has anybody the same problem?

Regards.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6851
    • View Profile
Re: Volumetric lights in prefabs
« Reply #1 on: November 23, 2020, 12:42:25 PM »
Could you please try latest beta?

trueh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Volumetric lights in prefabs
« Reply #2 on: November 23, 2020, 02:51:44 PM »
I have just tried it. I get the same exact error.

It is weird. The object I am trying to convert into a prefab has several lights. Only one of them has Volumetric Lights attached. I can create a prefab for that light only without any problem. The exception only happens when the volumetric light is attached to the whole GameObject. If I remove Volumetric Lights from the offending light, I can also create the prefab for the whole GameObject. I tried to create the prefab that way and then editing it to add the Volumetric Lights component, but it is not working either.

My hierarchy is the following: https://ibb.co/XtBgXTJ

Showcase contains the model. Spot Light Top is the light with the Volumetric Light component.

Regards.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6851
    • View Profile
Re: Volumetric lights in prefabs
« Reply #3 on: November 23, 2020, 02:58:42 PM »
Problem may be related to how Volumetric Lights creates and destroys its own children objects (ie. local particles, shadow occlusion cam, etc.). Unity doesn't allow destroying children objects in the hierarchy if the parent is part of a prefab. In this case it requires you to enter prefab mode and remove the children objects there. But since these children are procedurally created, this doesn't make much sense.
I guess Volumetric Lights could detect that its parent is part of a prefab and try to unpack the entire prefab from the root parent - this should work but then you will lose the link between the scene prefab and the prefab itself.
Another option is that you create a prefab for the volumetric light itself (with the script) and attach this prefab to the group in the hierarchy, instead of making the volumetric light part of the whole group.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6851
    • View Profile
Re: Volumetric lights in prefabs
« Reply #4 on: November 23, 2020, 02:59:53 PM »
Just to clarify: Volumetric Lights will unpack itself automatically when dragging it to the hierarchy from a prefab but it will fail to do so if it's part of a group (this is why I suggest to keep the Volumetric Light prefab as an independent element).

trueh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Volumetric lights in prefabs
« Reply #5 on: November 23, 2020, 03:37:50 PM »
Thank you for the explanation. I have dealt with Unity's prefab API in the past and I know that it can be quite annoying. I did not remember the limitation you are writing about. Now everything seems "logical" :-)

It seems that there is no perfect solution. I will opt by the second one (to have a separated prefab for the light). I am more interested in keeping the link between the Showcase prefab and their instances and adding the volumetric lights script beforehand. Maybe I can even instance a volumetric light prefab in the correct place at runtime.

Thank you and best regards.