+4
Unity Bug

Unity Object picker in prefab isolation mode allows scene references

Finntroll 3 weeks ago • updated by Lazlo Bonin (Lead Developer) 5 days ago 14 1 duplicate

Hi,

Same issue as here: https://support.ludiq.io/communities/5/topics/2481-object-variables-are-not-supported-in-nested-prefabs

As soon as i save something as a prefab in 2018.3 all the object variables gets set to Null. I cannot edit or add them any way.

Steps to replicate:

  1. Create object variable in a gameobject: 
  2. Make into a prefab

It will clear them. Currently i have not found a work around except setting it manually in script during runtime.

Bolt Version:
1.4.0f11
Unity Version:
2018.3f2
.NET Version:
4x

Duplicates 1

+1

Have you tried the latest beta version of Bolt 1.4.1b3? It has some prefabs related fixes.

Tested now, still the same issue.

For info i got a sq3lite import error(could not be read/readonly). So i imported the package without the sq3lite dll.

+1

Thanks for the report, will look into it!

Cannot Reproduce

So I tried reproducing this but I can't, I will need clearer reproduction steps.

Setup:

  • Bolt v.1.4.1b3
  • Unity 2018.3.0f2

Steps:

  1. Create an empty GameObject called Root
  2. Create an empty GameObject under it called Child
  3. Add a Variables component to Root
  4. Create a variable called "child", of type GameObject, assign it Child
  5. Drag Root into the Project view to create a Prefab

As expected, the "child" variable survives, and its value becomes an override pointing to the scene instance of child. On the prefab, the "child" variable exists, and its value is a reference pointing to the prefab instance of child.

This is what my inspector looks like at Step 4:

And this is what it looks like at step 5:


I also tried creating a variable from the prefab itself:

  1. Open the new "Root" prefab in isolation moode
  2. Create a new variable called "child2", of type GameObject
  3. Assign "child2" the Child from the prefab hierarchy
  4. Exit prefab isolation mode

As expected, the "child2" variable survives, and the scene instance of the prefab is even able to map it to its scene version of the Child object automatically.

What my inspector looks like after step 3, while in isolation mode:



What my inspector looks like in step 4, in the scene view outside isolation:




Please let me know how I can reproduce the issue you described from the latest beta!
+1

this varies slightly from the posted issue but here is a video of the issue I think they are trying to get at


this is in unity 2018.2 and bolt 1.40f11 - net3

Hi Firebomb games,

Thanks for taking the time to capture a video. However, this does not seem to be related to prefabs at all, it's one of the oldest known issues of Bolt in the FAQ, Why do my variables reset to null?. If you don't assign a value to a nullable variable, the type will be lost the next time the inspector is shown. In your example, if you had actually set "var" to "obj" or "obj1", it would have stayed there.

For reproduction. Assign an unrelated gameobject that is also in the Scene to the object variable (instead of the child).

Both assigning it in isolation mode, as well as assigning it before turning it in to a prefab, results in the same thing which is that the variable type changes to Unity Object and the reference turns in to Null.

(below are screenshots of attempts at assigning the variable in isolation mode):

Before (in Prefab Isolation mode) :


After (In Scene) :


When I tried assigning the Child (SphereChild in the screenshot) it as you did in the above post, it survives. When it was an unrelated gameobject (CylinderOther) it loses the reference.

Hope that helps in reproducing the issue.
Bolt v.1.4.1b3
Unity 2018.3.0f2

    Hi AiSard, thanks for chiming in with more details.

    I'm trying to understand your repro steps but they don't quite make sense to me.

    If you're in isolation mode, how can you assign an object that is outside the prefab to a variable inside the prefab? It doesn't make sense. Specifically, in your first screenshot, I don't understand how you managed to drag Cylinder into that field, since it doesn't exist in the prefab.

    To be clear: when you're in prefab isolation mode, Unity isn't letting you edit the instance of the current prefab. Unity is opening the definition of the prefab, which has no notion of the scene or its objects at all.

    But I did run some further tests with non-children elements. Everything seems to behave normally.

    Here's my starting point:

    1. Create a Cube
    2. Create a Sphere
    3. Add a Variables component to the Cube
    4. Add a "sphere" variable that points to the Sphere

    At this point the inspector should look like this:


    Then here are my tests:

    A. Making the Sphere a prefab: the reference is preserved.



    B. Making the Cube a Prefab: the Sphere reference is preserved, but it becomes an override, as it should, because the prefab itself cannot know about scene objects.



    In this second test, if I enter the cube prefap, yes, the reference to Sphere is lost. But that's normal, because the prefab cannot know about scene objects:



    Am I missing something obvious here? Perhaps I'm not understanding the bug report.

    Huh, I guess this might be a Unity bug/oversight then. Didn't realize a prefab wasn't allowed to be aware of the Scene.

    In Isolation Mode, to select a gameobject from the Scene, clicking the circle on the right (of the Value in the Variables component) gives you access to both Assets as well as Scene objects. Which probably shouldn't happen I'm gathering..

    Working on Fix

    Right, I just tested and the fact that it lets you pick scene references is indeed a bug in Bolt's object picker. I can fix that. But the rest is part of Unity's design: assets cannot refer to scene objects, because they may be used in many scenes or none at all.

    That clarifies and solves the original problem. Its indeed when i make the change inside the prefab that it does not replicate, it seems that is how it is supposed to be.

    So i guess the option is to set it using code then, not manually before starting.

    Thanks for looking into this!

    Unity Bug

    Hi everyone,

    So I looked into this further and I was not able to fix it. The problem is that the EditorGUI.ObjectField method in the API does not seem to have been updated for the new prefab workflow, so there's no way of showing Self (isolated) objects without showing Scene objects too. Likewise, there's no way of hiding Scene objects without also hiding Self objects. 

    https://forum.unity.com/threads/editorgui-objectfield-allowsceneobjects-in-isolation-mode.610564/

    For now, because it's perfectly valid to assign Self objects when in prefab isolation mode, I can't disable the Scene objects from the dropdown. Until Unity chimes in with a fix here, it's up to you to not assign scene references to isolated prefabs. If you do, they'll become null as they should.