Announcement

Collapse
No announcement yet.

RemoveFromParent and AddToViewport don't work in the same tick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Thanks alot mate!

    I was missing the AddChildToCanvas node, Im kinda new to UE4.

    I do greatly apreciate the efford you put in explaining it so thorally. Couldn't figure it out for days.

    Cheers

    Leave a comment:


  • replied
    Create a widget with a Canvas Panel, select it and flag it as isVariable in the details panel (very upper right corner) - this will expose it as a variable as not all widgets do it by default; the Canvas Panel does not, for example.

    Ideally, create this widget in an easily accessible blueprint (Game Mode, Game Instance, Player Controller, HUD Class (my fav). Now, every time you'd normally Add(something)ToViewport, you will instead add it to the master widget's Canvas Panel.

    More details:

    Click image for larger version  Name:	Capture.PNG Views:	1 Size:	290.0 KB ID:	1496589

    Do note that you can easily take it one step further. You could have an even higher level widget blueprint with a canvas that controls other canvasses. Imagine a situation where you have multiple layers of UI (inventory widgets, item labels, enemy labels, map, damage overlays, floating windows, quest markers and so on) and you want to quickly and effortlessly bring an entire layer into focus.

    Get your layer from the highest level canvas and set its Z higher than other canvasses'; and the layer that is now on top can still control its own children's Zs independently (for depth perception purposes, perhaps).

    Think of a Diabloesque product with a typical interface; with a semi transparent map (with its own markers) and items scattered on the ground - pressing ALT sets item canvas' zOrder highest, so you can click-loot even though the map is still showing and the inventory is still open. And you did not even need to iterate through all the item labels separately and set their Zs...
    Last edited by Everynone; 07-02-2018, 01:59 PM. Reason: horrific typos mostly

    Leave a comment:


  • replied
    Hi,

    Thanks for the answer.

    I have red for this master widget technique somewhere, but couldnt figure it out how exactly to add widgets to the master widget at runtime. Which node to use?

    For the other thing, yes, I have stored the widget as variable. When I activate it, it does remove it from viewport, but dont add it. If I activate it again, it does add it. So I think its because I do them in a tick. Any wirkarounds?

    Thanks

    Leave a comment:


  • replied
    It's not the only way.

    Instead of using the viewport to handle (add/remove and whatnot) the widgets, use another master widget blueprint with a canvas only. Add the master to the viewport normally but then, rather than adding newly created widgets to the viewport, add them to that canvas.

    Canvasses have their own Zorder for their children and you can modify it dynamically without having to add or remove anything.

    In addition, you now have a single widget that is housing all other widgets, giving you the ability to treat it as a communications hub/manager for the pertinent widget related stuff.

    edit:

    But when I'm trying to do this in the same tick, first RemoveFromParent and then AddToViewport with higher Zorder, so it doesn't flicker, it doesn't work.

    If I execute it again, it does adds to the viewport with higher Zorder, so I guess the problem is doing it at the same tick.
    Makes me wonder whether you actually store a reference to the widget. What could be happening here is that you RemoveFromParent (and have nothing referencing this widget anymore), it gets flagged for garbage collection and it can no longer be re-added. There have been some fixes to the widget pins keeping the reference for too long and causing memory leaks so this behaviour could have worked in previous versions of the engine.

    Anyhow, you can still try your method but ensure the widgets you are removing and re-adding are being referenced.
    Last edited by Everynone; 07-02-2018, 11:58 AM.

    Leave a comment:


  • RemoveFromParent and AddToViewport don't work in the same tick

    Hi

    I'm trying to change the Zorder of my widgets dynamically, and as I lerned the only way to do this is to change the Zorder in the AddToViewport node.

    But when I'm trying to do this in the same tick, first RemoveFromParent and then AddToViewport with higher Zorder, so it doesn't flicker, it doesn't work.

    If I execute it again, it does adds to the viewport with higher Zorder, so I guess the problem is doing it at the same tick.

    I tried using ForceLayoutPrepass after removing it from Parent, but since I have to use it on the parent, and I just have removed it, it doesnt work either.

    Any ideas? Thanks
Working...
X