Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Probuilder - meshes in prefabs

Discussion in 'World Building' started by Symo7, Sep 8, 2020.

  1. Symo7

    Symo7

    Joined:
    Mar 2, 2014
    Posts:
    23
    I'm trying to use ProBuilder to create prefab instances of wall sections (straight bits, windows, corners etc.) but if I copy the prefab instance it creates a new mesh rather than using the existing reference. If I try and edit an instance and apply it to the prefab, I get this error:

    A reference to an object in the scene cannot be applied to the Prefab asset.

    Is there a way to get ProBuilder to properly instance the original prefab mesh?
     
  2. Symo7

    Symo7

    Joined:
    Mar 2, 2014
    Posts:
    23
    As a workaround you can edit the actual prefab itself which does update all the instances ok.
     
  3. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    385
    At the moment the workaround is to use the Export option in ProBuilder to create a prefab, or create a mesh asset prior to making the object a prefab.
     
    Symo7 likes this.
  4. Symo7

    Symo7

    Joined:
    Mar 2, 2014
    Posts:
    23
    I've tried exporting (to obj) but am getting this error:

    OverflowException: Value was either too large or too small for an Int32.
    System.Convert.ToInt32 (System.Double value) (at <fb001e01371b4adca20013e0ac763896>:0)
    System.Convert.ToInt32 (System.Single value) (at <fb001e01371b4adca20013e0ac763896>:0)
    UnityEngine.ProBuilder.IntVec2.round (System.Single v) (at Library/PackageCache/com.unity.probuilder@4.2.3/Runtime/Core/IntVec2.cs:60)
    UnityEngine.ProBuilder.IntVec2.Equals (UnityEngine.ProBuilder.IntVec2 p) (at Library/PackageCache/com.unity.probuilder@4.2.3/Runtime/Core/IntVec2.cs:37)
    System.Collections.Generic.GenericEqualityComparer`1[T].Equals (T x, T y) (at <fb001e01371b4adca20013e0ac763896>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) (at <fb001e01371b4adca20013e0ac763896>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].TryGetValue (TKey key, TValue& value) (at <fb001e01371b4adca20013e0ac763896>:0)
    UnityEditor.ProBuilder.ObjExporter.AppendArrayVec2 (System.Text.StringBuilder sb, UnityEngine.Vector2[] array, System.String prefix, System.Boolean mergeCoincident, System.Collections.Generic.Dictionary`2[System.Int32,System.Int32]& coincidentIndexMap) (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/EditorCore/ObjExporter.cs:486)
    UnityEditor.ProBuilder.ObjExporter.WriteObjContents (System.String name, System.Collections.Generic.IEnumerable`1[T] models, System.Collections.Generic.Dictionary`2[TKey,TValue] materialMap, UnityEditor.ProBuilder.ObjOptions options) (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/EditorCore/ObjExporter.cs:190)
    UnityEditor.ProBuilder.ObjExporter.Export (System.String name, System.Collections.Generic.IEnumerable`1[T] models, System.String& objContents, System.String& mtlContents, System.Collections.Generic.List`1[System.String]& textures, UnityEditor.ProBuilder.ObjOptions options) (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/EditorCore/ObjExporter.cs:105)
    UnityEditor.ProBuilder.Actions.ExportObj.DoExport (System.String path, System.Collections.Generic.IEnumerable`1[T] models, UnityEditor.ProBuilder.ObjOptions options) (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/MenuActions/Export/ExportObj.cs:90)
    UnityEditor.ProBuilder.Actions.ExportObj.ExportWithFileDialog (System.Collections.Generic.IEnumerable`1[T] meshes, System.Boolean asGroup, System.Boolean allowQuads, UnityEditor.ProBuilder.ObjOptions options) (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/MenuActions/Export/ExportObj.cs:66)
    UnityEditor.ProBuilder.Actions.Export.DoAction () (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/MenuActions/Export/Export.cs:185)
    UnityEditor.ProBuilder.Actions.Export.OnSettingsGUI () (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/MenuActions/Export/Export.cs:124)
    UnityEditor.ProBuilder.MenuOption.OnGUI () (at Library/PackageCache/com.unity.probuilder@4.2.3/Editor/EditorCore/MenuOption.cs:78)
    UnityEditor.HostView.OldOnGUI () (at <143cf05d15c44625b70169dc5194636e>:0)
    UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcher.OpenGate () (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <b2edc98e33594892b0860f938df4f420>:0)
    UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <0ac0c8f6dff941899c750352cc6dc10e>:0)
     
  5. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    385
    If you just need prefabs you can use the "Asset" or "Prefab" export options.

    Regarding the OBJ export, could you please file a bug report in the Editor with that particular mesh attached?
     
  6. Symo7

    Symo7

    Joined:
    Mar 2, 2014
    Posts:
    23
    I do find that meshes in PB frequently get corrupted (to the point where I've gone back to just using Blender I'm afraid). When this happens the lighting will flash to black (including the sky - I'm using the HDRP) when the view is over the broken part of the mesh (often just a floating edge with no triangle attached). This also tends to happen when editing the mesh once its 'broken':

    Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
    UnityEngine.GUIUtility: ProcessEvent(Int32, IntPtr, Boolean&)

    These meshes are also not exportable with the issue above.
     
unityunity