Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dawnmichal opened this issue Nov 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@dawnmichal
Copy link

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 dawnmichal added the bug Something isn't working label Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant