stride icon indicating copy to clipboard operation
stride copied to clipboard

Adding UIComponnent with changed RenderGroup using code only (at runtime) doesn't work.

Open dawnmichal opened this issue 2 years ago • 0 comments

Release Type: Official Release

Version: 4.1.0.1948

Platform(s): Windows

Describe the bug When adding new UIComponent using code only (at runtime) with specific RenderGroup, UI doesn't render.

Expected behavior Visible UI.

Log and callstacks Not working RenderCompositor: GraphicsCompositor.txt

Additional context I want clear UI (not effected by post-process FX). So I folowed HeroCrab's tutorial here: https://github.com/herocrab/StrideCleanUI. At the same time a need to generate entities with UIComponent and UIPage at runtime using code. So this was my attemp:

    UIPage myPage = Content.Load<UIPage>("UserInterface/InteractionMenu");
    Entity myUIEntity = new Entity();
   
    var myUIComponent = myUIEntity.GetOrCreate<UIComponent>();
    myUIComponent.IsFullScreen = false;
    myUIComponent.SnapText = true;
    myUIComponent.IsFixedSize = true;
    myUIComponent.IsBillboard = true;
    myUIComponent.ResolutionStretch = Stride.Rendering.ResolutionStretch.FixedWidthFixedHeight;
    myUIComponent.Resolution = new Vector3(700, 300, 1000);
    myUIComponent.Size = new Vector3(0.7f, 0.3f, 1);
    myUIComponent.Page = myPage;
    myUIComponent.RenderGroup = Stride.Rendering.RenderGroup.Group31;
    Entity.AddChild(myUIEntity);

When it was called inside Start() method or in first run of Update() method, it works. But when it is called in Update() method later in the lifetime of the script, UI doesn't render. Then @tebjan said on Discord:

You can't change render groups after the game has started running. You need to set them before the start.

And also based on @tebjan and other suggestions I tried to create UIComponent with 'new' statement (insted of GetOrCreate), set all paprameters, add it to entity only afterwards and add entity to scene tree at last. But that didn't work either.

Discord user SolarChrome suggested working workaround by changing GraphicsCompositor:

I've played around with that HeroCrab and saw the same issue. I suspect there's some bug in UIRenderFeature where it's not detecting new entities on the second render stage. Anyway, this version works with new entities (see the bottom two screenshots), which is simpler: https://github.com/Basewq/XenkoProofOfConcepts/tree/master/GameScreenManagerExample Basically the difference from HeroCrab's solution is there's no new render stage, ie: Reset UIRenderFeature (ie. only 1 SimpleGroupToRenderStageSelector), have all RenderGroups ticked In the second Camera Renderer where the SingleStageRenderer had UiStage, change to Transparent Remove UiStage render stage You don't need another camera.

image

dawnmichal avatar Nov 13 '23 12:11 dawnmichal