UI Canvas Lua - Find Element By ID

0

I am following along with one of the Lua UI tutorials (which is out of date) but I have found the replacement function that searches for the UI element based on the id of the element, however the function call doesn't work as expected - meaning it doesn't work.

I call:

local entity = UiCanvasLuaBus.Event.FindElementById(self.canvasEntityId, 2);

which should return an entity with id = 2, but instead it returns nil.

Am I using this function wrong or is there another error here?

feita há 6 anos249 visualizações
9 Respostas
0
Resposta aceita

Hi @REDACTEDUSER

Sorry it sounds like that tutorial is out of date. The UiCanvasLuaBus is a deprecated bus. Use the buses named UiCanvasBus, UiElementBus etc instead. These are documented here: https://docs.aws.amazon.com/lumberyard/latest/developerguide/lua-scripting-ces-api-ui.html

In general we do not recommend using the old element Ids to access UI elements. The most flexible way is to use the Lua Script component and have a property on the script that is the EntityId of the element you want to use. You can then use the UI editor to connect the UI element to that Lua script property.

Some intro info on using the Lua Script Component is here: https://docs.aws.amazon.com/lumberyard/latest/developerguide/lua-scripting-intro.html

There is an example level that uses Lua with the UI system in SamplesProject. The level is called: Levels/UI/UiMainMenuLuaSample

Hopefully that will get you going with Lua and the UI system. Let us know if you have more questions.

Rob

respondido há 6 anos
0

Hi @REDACTEDUSER https://docs.aws.amazon.com/lumberyard/latest/developerguide/lua-scripting-ces-api-ui-uifadercomponent.html

The assets for the the fader samples can be found here: dev\Gems\LyShineExamples\Assets\UI\Canvases\LyShineExamples\Comp\Fader
dev\Gems\LyShineExamples\Assets\UI\Scripts\LyShineExamples\Fader\

respondido há 6 anos
0

Hi RobP,

Thanks for the reply, this is what I was assuming but was hoping it wasn't the case. I have been reading through that documentation and was hoping to find something similar to find by id, because object names are subject to change, and I can't use the Entity property picker because the script was located outside the canvas. I have created a work around so I'm not concerned about it working but rather it being modular and convenient to change down the road.

In that same tutorial it also references a function called HasFade(entityId), I was wondering if there was a function similar or if that too has been deprecated?

respondido há 6 anos
0

Hi @REDACTEDUSER

I'm curious what the use case is for HasFade. Why does the script need to know if a UI element has the UiFaderComponent on it?

Rob

respondido há 6 anos
0

But that doesn't answer my question, you are just pointing me to more documentation which I have already seen. I am asking if there is a function which returns true or false whether a Fader component is attached (or if there is a more generic one to test for other types of components).

respondido há 6 anos
0

I guess now that there isn't a "find by" type of function it is less useful, however I feel like it would be good to have a function that simply tests for whether the object grabbed "Has blank". It also is good for sanity checks and error testing.

respondido há 6 anos
0

Hi Chase,

This is really good to know! So when you say we, do you mean at Amazon? Because my followup question to you saying that is, should I just be using C++ to do anything in Lumberyard because it seems that the Lua functions/buses can be deprecated and just generally hard to get working.

respondido há 6 anos
0

Hi @REDACTEDUSER

bool isRadioButton = UiRadioButtonBus::FindFirstHandler(radioButton) != nullptr;

respondido há 6 anos
0

Hi @REDACTEDUSER

Using C++ vs Lua really depends on what you want to do, your desired workflow, the "customer" of your work, etc. Anything you can do in Lua, you can do in C++, but not everything in C++ is available in Lua.

Lua has a very fast workflow, great for rapid iteration, and is more accessible to other members of your team that aren't engineers/programmers. C++ is more powerful but has a slower turnaround time and (for the most part) is generally inaccessible to anyone who doesn't have coding experience.

If it helps, the "UiFeatures" level in SamplesProject was done completely using Lua.

respondido há 6 anos

Esta postagem está fechada: a adição de novas respostas, comentários e votos está desativada.