Search Unity

Better UI

Discussion in 'Assets and Asset Store' started by Hosnkobf, Jan 30, 2017.

  1. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    What you could try as a workaround is writing a manager class that has a reference to a Better Axis Aligned Layout Group Prefab and has one attached to itself. When you add the first element using this manager class, it will instantiate the referenced prefab as a child and puts the element as child of that layout group. The manager stores that layout group as "active".
    Whenever another element is added, the manager checks if it fits into the active layout group. If not, it creates another instance from the prefab, puts the object inside there and sets that new layout group as "active".
     
  2. Heurazio

    Heurazio

    Joined:
    Dec 24, 2021
    Posts:
    8
    Had the same problem with Unity 2021.3.8f1. Also, it seems BetterUI has some problems if it is not in the Asset root. I placed it in a Folder "3Party" which seems to be a problem. Furthermore, it always creates a folder "TheraBytes" again at the Asset Root which is not so lovely. Anyway to resolve this problem so that stuff stays inside the folder or that I change paths?
     
  3. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Yes, other paths are not supported out of the box. But you can adjust paths manually, see here.
    Note that it will make updates more difficult if you use a different root path.
     
  4. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    Hi

    I have a Better Axis Aligned Layout Group with a Landscape and Portrait Setting like so:

    upload_2023-1-11_15-11-12.png

    This works great in the Editor/Device Simulator but on the iPhone Build it stays in the Portrait setting. Do you have any idea what the cause could be for this?

    Thank you!
     
  5. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    iddqd likes this.
  6. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    Great, thanks for the quick solution. It all works perfectly now. Made my day a lot better!
     
    Hosnkobf likes this.
  7. capirot

    capirot

    Joined:
    May 2, 2013
    Posts:
    1
    Hello!
    I would like to know if I am able to control individual cell size in the same grid. I want to achieve something like this:

    upload_2023-1-19_0-57-24.png

    Thank you! And congratulations for the asset!
     
  8. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Unfortunately, this is not supported. This would need a completely new layout group component.
    However, if your elements are not created during runtime, you can set it up without any layout group just by using anchors.
     
  9. melos_han_tani

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    79
    Hi all, I seem to be getting a crash when click+drag resizing the scene view in play mode and pausing/unpausing. Unfortunately I can't consistently reproduce it... any ideas? Here's the stack trace. I haven't looked into it closely but wanted to see if I'm missing something obvious, or if I should just try upgrading unity (I'm on 2021.03.0f1).

    The scene's UI does have a few BetterImages in it, but that's all and I don't think we're doing anything wild.

    FWIW Unity was also crashing a few other times but without any stacktraces - but then it started to consistently crash with this Stacktrace mentioning BetterUI. We haven't had any problems in the past so I wonder if it could just be a mysterious editor thing tied to my computer's current state.


    =================================================================
    Native Crash Reporting
    =================================================================
    Got a UNKNOWN while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.
    =================================================================

    =================================================================
    Managed Stacktrace:
    =================================================================
    at <unknown> <0xffffffff>
    at UnityEngine.Object:FindObjectsOfType <0x000eb>
    at UnityEngine.Object:FindObjectsOfType <0x000a2>
    at <GetAllEditableObjects>d__66:MoveNext <0x0012a>
    at <AllResolutionDependencies>d__65:MoveNext <0x00441>
    at TheraBytes.BetterUi.ResolutionMonitor:ResolutionChanged <0x00868>
    at TheraBytes.BetterUi.ResolutionMonitor:playModeStateChanged <0x00182>
    at <Module>:invoke_void <0x002b6>
    at UnityEditor.EditorApplication:Internal_PauseStateChanged <0x000e0>
    at <Module>:runtime_invoke_void_int <0x0018d>
    at <unknown> <0xffffffff>
    at UnityEditor.EditorApplication:set_isPaused <0x000e0>
    at UnityEditor.Toolbars.PlayModeButtons:OnPauseButtonValueChanged <0x000b2>
    at UnityEngine.UIElements.EventCallbackFunctor`1:Invoke <0x003c9>
    at UnityEngine.UIElements.EventCallbackRegistry:InvokeCallbacks <0x004e2>
    at UnityEngine.UIElements.CallbackEventHandler:HandleEvent <0x006ea>
    at UnityEngine.UIElements.EventDispatchUtilities:propagateEvent <0x00dd9>
    at UnityEngine.UIElements.DefaultDispatchingStrategy:DispatchEvent <0x0021a>
    at UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies <0x002b5>
    at UnityEngine.UIElements.EventDispatcher:processEvent <0x00432>
    at UnityEngine.UIElements.EventDispatcher:processEventQueue <0x0031a>
    at UnityEngine.UIElements.EventDispatcher:OpenGate <0x001ea>
    at UnityEngine.UIElements.EventDispatcherGate:Dispose <0x0008a>
    at UnityEngine.UIElements.EventDispatcher:processEvent <0x00d82>
    at UnityEngine.UIElements.EventDispatcher:processEventQueue <0x0031a>
    at UnityEngine.UIElements.EventDispatcher:OpenGate <0x001ea>
    at UnityEngine.UIElements.EventDispatcherGate:Dispose <0x0008a>
    at UnityEngine.UIElements.EventDispatcher:processEvent <0x00d82>
    at UnityEngine.UIElements.EventDispatcher:Dispatch <0x00402>
    at UnityEngine.UIElements.BaseVisualElementPanel:SendEvent <0x0017a>
    at UnityEngine.UIElements.UIElementsUtility:DoDispatch <0x009fa>
    at UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent <0x002c2>
    at UnityEngine.UIElements.UIEventRegistration:processEvent <0x00233>
    at <>c:<.cctor>b__1_2 <0x0009a>
    at UnityEngine.GUIUtility:processEvent <0x00114>
    at <Module>:runtime_invoke_void_int_intptr_intptr& <0x001b5>
    =================================================================
    Received signal SIGSEGV
    Obtained 63 stack frames
    0x00007ff79938edb5 (Unity) scripting_object_get_class
    0x00007ff799388214 (Unity) Scripting::FindObjectsOfType
    0x00007ff7985dc870 (Unity) Object_CUSTOM_FindObjectsOfType
    0x00000206f09219cc (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Object:FindObjectsOfType (System.Type,bool)
    0x00000205e42778f3 (Mono JIT Code) UnityEngine.Object:FindObjectsOfType<T_REF> ()
    0x000002069c2fafcb (Mono JIT Code) [ResolutionMonitor.cs:492] TheraBytes.BetterUi.ResolutionMonitor/<GetAllEditableObjects>d__66:MoveNext ()
    0x000002069c2fa342 (Mono JIT Code) [ResolutionMonitor.cs:467] TheraBytes.BetterUi.ResolutionMonitor/<AllResolutionDependencies>d__65:MoveNext ()
    0x000002069c2f6359 (Mono JIT Code) [ResolutionMonitor.cs:433] TheraBytes.BetterUi.ResolutionMonitor:ResolutionChanged ()
    0x000002069c2f5a43 (Mono JIT Code) [ResolutionMonitor.cs:297] TheraBytes.BetterUi.ResolutionMonitor:playModeStateChanged ()
    0x000002069c2f5687 (Mono JIT Code) (wrapper delegate-invoke) <Module>:invoke_void ()
    0x000002069d598a51 (Mono JIT Code) UnityEditor.EditorApplication:Internal_PauseStateChanged (UnityEditor.PauseState)
    0x00000205e2c0580e (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_int (object,intptr,intptr,intptr)
    0x00007ffc9447e0a4 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
    0x00007ffc943be744 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke
    0x00007ffc943be8dc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke
    0x00007ff799385bee (Unity) CallStaticMonoMethod
    0x00007ff799385986 (Unity) CallStaticMonoMethod
    0x00007ff799f916d4 (Unity) PlayerLoopController::SetPaused
    0x00007ff798c1bcfe (Unity) EditorApplication_Set_Custom_PropIsPaused
    0x000002069d598811 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.EditorApplication:set_isPaused (bool)
    0x000002069d5985b3 (Mono JIT Code) UnityEditor.Toolbars.PlayModeButtons:OnPauseButtonValueChanged (UnityEngine.UIElements.ChangeEvent`1<bool>)
    0x000002057a8d9ada (Mono JIT Code) UnityEngine.UIElements.EventCallbackFunctor`1<TEventType_REF>:Invoke (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.PropagationPhase)
    0x000002057a8d8eb3 (Mono JIT Code) UnityEngine.UIElements.EventCallbackRegistry:InvokeCallbacks (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.PropagationPhase)
    0x0000020419a7429b (Mono JIT Code) UnityEngine.UIElements.CallbackEventHandler:HandleEvent (UnityEngine.UIElements.EventBase)
    0x0000020419a70dda (Mono JIT Code) UnityEngine.UIElements.EventDispatchUtilities:propagateEvent (UnityEngine.UIElements.EventBase)
    0x00000205f0f4e27b (Mono JIT Code) UnityEngine.UIElements.DefaultDispatchingStrategy:DispatchEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    0x00000205f0f4c306 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,bool)
    0x00000205f0f4ae23 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:processEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    0x00000205f0f4ed1b (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:processEventQueue ()
    0x0000020419a7ad4b (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:OpenGate ()
    0x0000020419a7aaeb (Mono JIT Code) UnityEngine.UIElements.EventDispatcherGate:Dispose ()
    0x00000205f0f4b773 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:processEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    0x00000205f0f4ed1b (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:processEventQueue ()
    0x0000020419a7ad4b (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:OpenGate ()
    0x0000020419a7aaeb (Mono JIT Code) UnityEngine.UIElements.EventDispatcherGate:Dispose ()
    0x00000205f0f4b773 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:processEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    0x00000205f0f49de3 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:Dispatch (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,UnityEngine.UIElements.DispatchMode)
    0x00000205f0f4992b (Mono JIT Code) UnityEngine.UIElements.BaseVisualElementPanel:SendEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.DispatchMode)
    0x00000205e2b7301b (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel)
    0x00000205e2b721e3 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (int,intptr,bool&)
    0x00000205e2b71b54 (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration:processEvent (int,intptr)
    0x00000205e2b7184b (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration/<>c:<.cctor>b__1_2 (int,intptr)
    0x00000205e2b71315 (Mono JIT Code) UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    0x00000205e2b71556 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_int_intptr_intptr& (object,intptr,intptr,intptr)
    0x00007ffc9447e0a4 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
    0x00007ffc943be744 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke
    0x00007ffc943be8dc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke
    0x00007ff79938ecf4 (Unity) scripting_method_invoke
    0x00007ff799389914 (Unity) ScriptingInvocation::Invoke
    0x00007ff799383235 (Unity) ScriptingInvocation::Invoke<void>
    0x00007ff79948be2a (Unity) Scripting::UnityEngine::GUIUtilityProxy::processEvent
    0x00007ff799ec2396 (Unity) GUIView::processRetainedMode
    0x00007ff79a4062ab (Unity) GUIView::OnInputEvent
    0x00007ff799ec21aa (Unity) GUIView::processInputEvent
    0x00007ff79a4071c7 (Unity) GUIView::processEventMessages
    0x00007ff79a400dcc (Unity) GUIView::GUIViewWndProc
    0x00007ffd016ce7e8 (USER32) CallWindowProcW
    0x00007ffd016ce229 (USER32) DispatchMessageW
    0x00007ff79a3dbe03 (Unity) MainMessageLoop
    0x00007ff79a3e084b (Unity) WinMain
    0x00007ff79b701d4e (Unity) __scrt_common_main_seh
    0x00007ffd014e7614 (KERNEL32) BaseThreadInitThunk
    0x00007ffd02d426a1 (ntdll) RtlUserThreadStart
     
  10. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    208
    Whenever I remove my Library folder (to reset everything, feels good once in a while) it looks liek the resolution monitor resets as well. I can see it in the git diff.

    upload_2023-3-12_16-49-7.png

    I've changed the code here manually, but these values here are otherwise "enforced" whenever I remove the library folder, despite otherwise being changed to totally different values.
     
  11. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Thanks for the report.
    Actually, I never came across this error and it was also never reported before. All I do here is this:
    Code (CSharp):
    1. foreach (GameObject go in GameObject.FindObjectsOfType<GameObject>())
    So, It has to do with Unity's internal logic maybe in combination with your open scene...
     
  12. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Ah, this is good to know.
    I already know the issue that the ResolutionMonitor resets when upgrading the unity version of a project. It is very likely that this is the same bug. But your report has much easier reproduction steps :)
    That makes it much more likely that I can fix it soon*ish ;)
     
  13. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    @theforgot3n1 I couldn't reproduce it. Which Unity version do you use?
     
  14. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    208
    2021.3.15f1

    Who knows... maybe it's something I've done separately? Haven't touched BetterUI code much tho. Appreciate you looking into it
     
  15. DhiaSendi

    DhiaSendi

    Joined:
    May 16, 2018
    Posts:
    43
    Hi, thank you very much for the amazing asset, very excited to start using it.
    I got some errors with the BetterUI 2.5 Unity 2021.3.16
    Code (CSharp):
    1. Assets\TheraBytes\BetterUI\Runtime\Scripts\BetterUiElements\BetterToggle.cs(46,51): error CS0246: The type or namespace name 'SelectionState' could not be found (are you missing a using directive or an assembly reference?)
    Code (CSharp):
    1. Assets\TheraBytes\BetterUI\Runtime\Scripts\BetterUiElements\BetterToggle.cs(31,33): error CS0115: 'BetterToggle.OnEnable()': no suitable method found to override
     
  16. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Oh, wow, the new version is already published! That was much faster than I expected :D (I will publish the new documentation in a few minutes).
    EDIT: just updated the documentation.

    Regarding your error message: This is very strange. I tested this with many Unity versions (2018 LTS, 2019 LTS, 2020 LTS, 2021 LTS, 2022.2, 2023.1 - so 2021.3 was included. maybe not patch 16 but they wouldn't make such a big change in a patch) and didn't see this error.

    I have two possibilities in mind which could be the error:
    1. You have a class called "Toggle" in your project and BetterToggle thinks it should derive from that class
    2. You do not have the UGUI package installed (very unlikely)
    So, if you have a "Toggle" class in your project (possibility 1), you can either wrap it in a namespace, so that the BetterToggle class doesn't "see" it, or install assembly definition files (go to
    Assets/TheraBytes/BetterUI/Packages
    and double click
    asmdef_excl_TextMeshPro
    - if you later insall TextMesh Pro support, don't change the assembly definitions through the wizard, but doubleclick the
    asmdef_incl_TextMeshPro 
    package instead).

    Please let me know if you manage to fix it. If not, I would need to look into the project to see what's the problem.
     
  17. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Finally!
    Better UI 2.5 is here!

    • Features:
      • New Control - Better Offsetter: replaces the "Size Delta Sizer" and allows to change the anchored position in addition to the size delta (with responsive design options)
      • New Control - Value Dragger: Allows to press an element while dragging to change a value. Similar to a Slider but without a knob.
      • Better Toggle - There are now individual transitions for selection states when the toggle is on as well as transitions for when it is off.
      • Better Content Size Fitter - can be treated as layout element (Handy when it should be part of a layout group)
      • Color Transitions - Can now also target secondary color (for gradients) and overwrites colors instead of mixing them (optional for main color).
      • Anchor Override - Update Modes introduced, to not update positions every frame. Also exposed the target to allow changing it via code.
      • Snap Anchors Window - There is a button now to stretch the element to the size of the parent and move the anchors to the border (like a panel).

    • Improvements:
      • Almost all Better Components - Implemented properties with same name as base-class-properties which makes it easier to apply certain values via code.
      • Transitions - List of transitions is now rendered as a reorderable list (using rotorz implementation). Custom code can now also mark a List<Transition> with a TransitionStatesAttribute or a DefaultTransitionStatesAttribute.
      • Better Input Field / Better TextMesh Pro Input Field - Additional Placeholders using a reorderable list as well now.
      • Better Locator - Auto Pull & Auto Push state persists for a session (when you disable Auto Pull, it will not be enabled automatically when you (re)select a Better Locator)
      • Better Locator - If the current screen configuration is not defined, Live update options are disabled. This prevents changing transform data for the wrong config accidentally.
      • Screen Config Collections - Button to add the current screen config if it is not present.
      • Size Modifiers - Min Size and Max Size are optional now and off by default
      • Size Modifiers - There is a warning if the Canvas Scaler is not "Constant Pixel Size" and Size Modifications are registered. There are also two options to fix it easily.
      • Materials - Each predefined material has it's own helper class now to easily access their name ids and parameter indices via code.
      • Smart Parent Window - Snap button ignores inactive objects.
      • Size Change Tracker - Performance improved a lot. This required a re-design of the component.

    • Fixes:
      • Better Image - Can correctly handle sprites that are set to "Tight" now.
      • Better Image - Can correctly scale borders of sliced sprites in a Texture Atlas which are set to "Tight" now.
      • Better Image - "PixelPerUnit" multiplier can be used now (also in combination with Better UI's sizing options).
      • Better Image - "Use Sprite Mesh" option is disabled as it is not supported for the better version of images (because gradients would be hard to implement and would likely have artifacts)
      • Better Image (and potentially others) - Settings were not copied correctly leading to empty sprites and transparent black color for newly added settings configs.
      • Better Toggle - doesn't subscribe to onValueChange event anymore, so RemoveAllListeners() doesn't kill better transitions anymore.
      • Snap Anchors Window - also works with rotated canvases / parents now.
      • Location Animations - did not work when chaining animations through "Action After Finish" event
      • Better Locator - disabled objects don't overwrite location data anymore.
      • Screen Config Collections - When a screen config was added, the list of configs was not sorted correctly. This could lead to the selection of the wrong config (e.g. If there is "Landscape" and then "Landscape Large", "Landscape" was chosen even if the current Screen config was detected as "Landscape Large" - so the order in the resolution monitor was not matched).
      • Transitions - Instantly apply material property transitions if object is not active (avoids coroutine errors)
      • Materials - NullReferenceException fixed when trying to set a material via code while Materials-Singleton is about to create its instance.
      • ResolutionMonitor - Fixed compile error in Unity 2021.2+.
      • Pick Resolution Window - Also works with Unity 2022 now.
      • Pick Resolution Window - Scene View updates more reliably when resolution is changed.

    • Feature: Better Content Size Fitter - can be treated as layout element (Handy when it should be part of a layout group)
      • In most cases this doesn't change anything when updating. In rare cases it needs to be turned off to prevent wrong sizes.
    • Impovement: Size Change Tracker - Performance improved a lot. This required a re-design of the component.
      • It now requires a component that implements ILayoutElement. This is usually the case, but if not, an update will break the tracker.
    • Improvement: Size Modifications - Min Size and Max Size are optional now and off by default
      • In most cases you don't want a min or max size. However, if you have UI Elements that require it, you will need to manually enable it after updating.
    • Fix: Screen Config Collections - When a screen config was added, the list of configs was not sorted correctly. This could lead to the selection of the wrong config (e.g. If there is "Landscape" and then "Landscape Large", "Landscape" was chosen even if the current Screen config was detected as "Landscape Large" - so the order in the resolution monitor was not matched).
      • If you rely on the wrong ordering, this might be problematic. While the existing entries will not be reordered automatically, they will as soon as another config is added. Also, new components with screen configs will have the correct sorting now.

    If you upgrade a project with Better UI in it, please read the Upgrade Guide.

    I didn't manage to include everything I wanted in this version, but I didn't forget your feature requests.
    Here is a list of the features I plan for the next releases (might not be complete, in case something is too hard to do, it might be left out or postponed to a later version).

    • New Control - Area Adopter: Changes the position / size of the element to the Safe area of the screen or a Notch
      (I plan more control for UI around notches, but this is the first step)
    • Extract Utility Runtime functions (like "Snap to Border") and integrate Shortcuts
    • Implement "Better Standalone Input Module" that allows skipping the "Selected" state when interacting with a cursor (mouse / touch).
    • Introducing sizers where they are still missing (Scrollbar Sensitivity)
    • Implement "Better Rect Mask 2D" to control sizes of Padding and Softness
    • Implement "Better Outline" and "Better Shadow" allowing to work with Better UI materials, so that you can have completely colorized effects if your Image has the "ColorOverlay" material.
    • Fix resetting of Resolution Monitor when upgrading unity (or sometimes when deleting the Library folder)
    • Allow changing the root folder of Better UI
    • Implement a "collapsed mode" for sizers to see all necessary information in less vertical space
    Please let me know if I forgot your feature request or if you have any new feature request.

    Thank you all for using Better UI :)
     
    Last edited: Mar 22, 2023
  18. DhiaSendi

    DhiaSendi

    Joined:
    May 16, 2018
    Posts:
    43
    Thank you for quick reply!
    I just created an empty project with Unity 2021.3.16 and I can confirm that everything works fine and the new update is stable.
    So for the errors I got above are as you said related with having some classes derive from another ones.
    Again thank you and keep it forward!
     
    Hosnkobf likes this.
  19. mchangxe

    mchangxe

    Joined:
    Jun 16, 2019
    Posts:
    69
    Hey hosnkobf, thanks for the asset. One question, when i want to build the ResolutionTracking scene for webgl, like in the setup wizard's example, things are not responsive, when i resize the browser, nothing happens. I suspect this is caused by WebGL template, which im currently using "Minimal", is this correct?
     
  20. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Hey @mchangxe,
    Probably, your web-app or iFrame doesn't get notified about a change in size.

    A while ago, I played around to get this working.
    Here you can see a working version: https://documentation.therabytes.de/better-ui-webgl-dpi-test/container.html

    And here you can download the html files (with java script) that I used there: https://documentation.therabytes.de/better-ui-webgl-dpi-test/resizable_iframe_html_source.zip

    Hope this helps to figure out how to get it running.
    (Also, make sure you have an IngameResolutionMonitor)
     
  21. mchangxe

    mchangxe

    Joined:
    Jun 16, 2019
    Posts:
    69
    Thanks for getting back to me. Im quite new to HTML and im not so sure what to do with the container.html and the content.html. After building from unity, I have the index.html file and not the container and content. How should I change my index.html file?

    My index.html is like this, using unity 2021.3.16
    Code (CSharp):
    1. <!DOCTYPE html>
    2. <html lang="en-us">
    3.   <head>
    4.     <meta charset="utf-8">
    5.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    6.     <title>Unity WebGL Player | UnityWebsiteTest</title>
    7.   </head>
    8.   <body style="text-align: center; padding: 0; border: 0; margin: 0;">
    9.     <canvas id="unity-canvas" width=1920 height=1080 style="width: 1920px; height: 1080px; background: #231F20"></canvas>
    10.     <script src="Build/Build.loader.js"></script>
    11.     <script>
    12.       if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
    13.         // Mobile device style: fill the whole browser client area with the game canvas:
    14.         var meta = document.createElement('meta');
    15.         meta.name = 'viewport';
    16.         meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
    17.         document.getElementsByTagName('head')[0].appendChild(meta);
    18.  
    19.         var canvas = document.querySelector("#unity-canvas");
    20.         canvas.style.width = "100%";
    21.         canvas.style.height = "100%";
    22.         canvas.style.position = "fixed";
    23.  
    24.         document.body.style.textAlign = "left";
    25.       }
    26.  
    27.       createUnityInstance(document.querySelector("#unity-canvas"), {
    28.         dataUrl: "Build/Build.data",
    29.         frameworkUrl: "Build/Build.framework.js",
    30.         codeUrl: "Build/Build.wasm",
    31.         streamingAssetsUrl: "StreamingAssets",
    32.         companyName: "DefaultCompany",
    33.         productName: "UnityWebsiteTest",
    34.         productVersion: "0.1",
    35.         // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOM element size.
    36.         // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
    37.       });
    38.     </script>
    39.   </body>
    40. </html>
    41.  
    And BetterUI seemed to have stopped working in my builds this morning, I have ingame resolution monitor created at start. It was working fine last night, and when this morning, I added a targetframerate line and build again, betterUI does not seem to work, and all my better raw images sizes do not change when i resize browser window
     
    Last edited: Apr 28, 2023
  22. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    The container.html is basically the new index.html. You can remove your index html and rename the container.html.
    However, the example simply shows how you can propagate resolution changes when your build is running in an iFrame and you resize the window.
    If you simply want to display it in a frame with the ability for fullscreen, like the default index.html does, you don't need to change any html files.
    you still can test the resizing features, by switching to full screen and open the development console (F12 in most browsers. Tested with Google Chrome) and resize the console.

    The target framerate should not affect anything in Better UI. My best guess is that you added code before the creation of the ingame resolution monitor which causes an exception. That exception skips the rest of the method.
    Try to create it as the very first thing, or create it directly in the scene (not via code).
     
  23. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Hi, I have dynamic text that goes into a vertical scrollview.
    When I put the text inside of the scrollview, it doesn't detect dynamic height so it doesn't scroll correctly.
    Can you give some suggestions of how to set this up correctly.
    Cheers.
     
  24. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Hi,
    Have you tried this little tutorial?
     
  25. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Super Awesome, that worked like a charm.
     
    Hosnkobf likes this.
  26. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Another quick question:
    I have two character Sprites in the scene, I would like to position the sprites in a set position in Portrait and another position in Landscape mode.
    There are two components on each sprite : BetterRawImage and BetterLocator
    In the editor, when changing from Portrait to Landscape, the sprites changes position correctly, but when publishing to android, the sprites are squashed in landscape. Do you know what this could be?
     

    Attached Files:

  27. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    To detect resolution changes in a build, you need to create an IngameResolutionMonitor. :)
     
  28. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    I tried it and still the same problem. I sent you an email.
     
    Hosnkobf likes this.
  29. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    208
    I've been having a very laggy scene for a while. The issue is the lag in the Editor. Singular frames can cost up to 100 ms. It's slowly crept up on me as I've worked on the project for months. Here's a profiler showing the performance in a scene with the issue.

    upload_2023-6-22_14-35-43.png

    Note that the performance goes up and down. Some frames cost only 13 ms, some up to 90-100 again.

    Here's an example of the hierarchy for an expensive frame

    upload_2023-6-22_14-37-31.png

    Here's an example of a cheap one.

    upload_2023-6-22_14-38-8.png

    I troubleshot the issue and found that a ton of performance is lost due to AnchorOverride. AnchorOverride also costs around 2% of my frame budget in play, but it's nothing compared to how much faster everything was when I turned off AnchorOverride in the editor.

    I have a ton of AnchorOverrides in my scene because I have a lot of health bars, stamina bars and experience bars all using AnchorOverride.

    Any ideas what this is about? Is it fixable or do I have to find a way to replace AnchorOverride?
     
  30. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Thanks for bringing this up.
    I agree that there are performance issues when using AnchorOverrides. This is caused by the layouting engine of UGUI: if an element changes position or size, the layout has to be recalculated. As AnchorOverride constantly changes positions and sizes by default, the layouting is triggered every frame.

    In Better UI 2.5 I added some features to be able to avoid this issue:
    • In AnchorOverride there is a Mode field now. If this is set to "Manual" the anchors are only applied on enable, when the resolution changes or when you trigger it in code. Animations still work if triggered manually.
      This option only makes sense, if the anchored object has a static position / size.
    • The new component BetterOffsetter allows you to set positions and sizes that are scaled with the resolution. This way you can nicely adjust positions without referencing other objects, if the position doesn't need to be relative to an element that can change its size.
    If you still need AnchorOverrides that are updating constantly, you can improve performance by telling the layouting engine which parts of the hierarchy need to be recalculated. To do this, add Canvases to elements that contain other elements which can change position / size (and maybe also canvases to the elements with the AnchorOverride, not sure if this has an actual effect). If you need to interact with elements inside such a sub-canvas, you also need to add a GraphicsRaycaster component to the object with the canvas.

    I defenitely want to investigate the problem further. Maybe I can improve the performance of AnchorOverride itself. But maybe there is no optimization possible... I am not sure yet.
     
    theforgot3n1 likes this.
  31. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    My app is in portrait mode and would like to force the screen to be landscape in some cases and then force back to portrait mode again at other times. Is there a utility function in BetterUi that can do this?
     
  32. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Simple solution: Screen.orientation = ScreenOrientation.Portrait;
     
    Hosnkobf likes this.
  33. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    145
    @theforgot3n1 I never reach more than 10kb GC allocation, how come you have 10x more GC than mine.
     
  34. millibar

    millibar

    Joined:
    Aug 3, 2015
    Posts:
    8
  35. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Hi,

    Thanks for reporting this, and sorry for my late response.
    A coworker changed some DNS settings while I was on vacation. We will fix it today. I will let you know when it is accessible again.

    Sorry for the inconvenience.
     
  36. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    The documentation is back.
    Sorry again for the down-time.
     
  37. millibar

    millibar

    Joined:
    Aug 3, 2015
    Posts:
    8
    It became working, thanks.
     
    Hosnkobf likes this.
  38. ahmararif

    ahmararif

    Joined:
    May 12, 2023
    Posts:
    2
    in location Animations, 2nd animation doesn't start when i add it in the event of first animation to play.
     
  39. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Hi,
    There was a bug in version 2.4 that prevented the start of a chained animation. In Version 2.5 this should be fixed (I explicitly tested this use case). So, either you are on an old version or you might have a typo in the animation name. If both isn't the case, there might be some other mechanism that prevents the change of the animation... (maybe it is started by a transition? This actually should work, but I didn't test that yet).
     
  40. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    326
    any good stuff coming in 2.5?
     
  41. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
  42. rrtc26

    rrtc26

    Joined:
    Feb 23, 2022
    Posts:
    11
    Selecting several elements and modifying the elements together does not update all the "better locator", is there a solution? Auto-Pull only updates one element, apparently if I modify several it does not save the changes, I don't want to save the changes one by one, any solution?
     
  43. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Hi @rrtc26

    I just checked and realized that you are right. I only handle the main target in the code.
    Implementing this for all selected objects automatically might be a bit tricky as it should not pull under certain circumstances. But I think I found a solution that should be good enough for you: A button which pulls for all selected objects.

    To implement it, open the script file
    BetterLocatorEditor
    and find the method
    OnInspectorGUI()
    (line 35-60). In there you can paste the following code at the end or right before the
    ScreenConfigConnectionHelper.DrawGui(...)
    call:

    Code (CSharp):
    1.             if(targets != null && targets.Length > 1)
    2.             {
    3.                 if(GUILayout.Button("Pull All Selected Objects", GUILayout.MinHeight(30)))
    4.                 {
    5.                     foreach(var bl in targets.OfType<BetterLocator>())
    6.                     {
    7.                         bl.CurrentTransformData.PullFromTransform(bl.transform as RectTransform);
    8.                     }
    9.                 }
    10.             }
     
  44. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    I have the same need, I put in the code changes but the button doesn't show up in the inspector.
     
  45. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    It should only show up when multiple objects are selected...
    1. Did you selected multiple objects?
    2. Did you double check if you put it into the correct class at the correct place?
    3. Are there any errors in the console?
     
  46. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Would you be able to make a short video to explain how to use this please.
     
  47. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Does anyone know how to keep the aspect ratio of the standalone mac or windows build?
    Reason is that I optimized my project for 1920 x 1080. When I build it for stand alone it's too small on a retina screen. I would like for users to be able to resize the window but keep the aspect ratio.
     
  48. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Ok,
    Let's go with the code first. To not get confused, I copy over the whole OnInspectorGUI() method of BetterLocatorEditor.cs for you (patched):
    Code (CSharp):
    1.         public override void OnInspectorGUI()
    2.         {
    3.             string currentScreen = ResolutionMonitor.CurrentScreenConfiguration?.Name;
    4.             bool isCurrentScreenConfig = currentScreen == null // fallback is always present
    5.                 || locator.CurrentTransformData.ScreenConfigName == currentScreen;
    6.  
    7.             if (isCurrentScreenConfig)
    8.             {
    9.                 EditorGUILayout.PrefixLabel("Live Update");
    10.                 EditorGUILayout.BeginHorizontal();
    11.                 EditorGUI.BeginDisabledGroup(!locator.isActiveAndEnabled);
    12.                 bool newPull = GUILayout.Toggle(autoPull, "↓   Auto-Pull", "ButtonLeft", GUILayout.MinHeight(30));
    13.                 bool newPush = GUILayout.Toggle(autoPush, "↑   Auto-Push", "ButtonRight", GUILayout.MinHeight(30));
    14.                 EditorGUI.EndDisabledGroup();
    15.                 EditorGUILayout.EndHorizontal();
    16.  
    17.                 // PATCH START: Pull all Objects
    18.                 if (targets != null && targets.Length > 1)
    19.                 {
    20.                     if (GUILayout.Button("Pull All Selected Objects", GUILayout.MinHeight(30)))
    21.                     {
    22.                         foreach (var bl in targets.OfType<BetterLocator>())
    23.                         {
    24.                             bl.CurrentTransformData.PullFromTransform(bl.transform as RectTransform);
    25.                         }
    26.                     }
    27.                 }
    28.                 // PATCH END
    29.  
    30.                 if (newPull != autoPull)
    31.                 {
    32.                     autoPull = newPull;
    33.                     autoPullFromTransform = newPull;
    34.                 }
    35.  
    36.                 if (newPush != autoPush)
    37.                 {
    38.                     autoPush = newPush;
    39.                     autoPushToTransform = newPush;
    40.                 }
    41.             }
    42.             else
    43.             {
    44.                 EditorGUILayout.BeginVertical(GUILayout.MinHeight(52));
    45.                 GUILayout.FlexibleSpace();
    46.  
    47.                 EditorGUILayout.HelpBox($"To prevent accidentally overriding the wrong config, live update is disabled. It is enabled only if you have a config for the current screen configuration ('{currentScreen}') present.",
    48.                     MessageType.Info);
    49.  
    50.                 EditorGUILayout.EndHorizontal();
    51.             }
    52.  
    53.             if (autoPull && locator.isActiveAndEnabled && isCurrentScreenConfig)
    54.             {
    55.                 locator.CurrentTransformData.PullFromTransform(locator.transform as RectTransform);
    56.             }
    57.  
    58.             ScreenConfigConnectionHelper.DrawGui("Rect Transform Override", transformConfigs, ref transformFallback, DrawTransformData);
    59.  
    60.             if (autoPush && !(pauseAutoPushOnce) && isCurrentScreenConfig)
    61.             {
    62.                 locator.CurrentTransformData.PushToTransform(locator.transform as RectTransform);
    63.             }
    64.  
    65.             pauseAutoPushOnce = false;
    66.         }
    Attached is a gif of how to use it.
     

    Attached Files:

  49. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    So, you want to keep the aspect ratio of the Window itself? Not really something for Better UI, I guess, because AFAIK you can simply specify this in the Player settings:
    upload_2023-11-5_23-35-48.png
     
  50. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Documentation not accessible
    We changed the host for our website which lead to some DNS problems and as a result the documentation for Better UI is not accessible right now. As we are all currently in Christmas holiday and have no access to a 2FA device, we cannot fix this at the moment. I apologize for this inconvenience.
    As a workaround, I uploaded the documentation to my personal webspace. You can access it here.
     
    Last edited: Dec 26, 2023