Applying properties to dynamically created entities

,

Is there a way to apply/set values for custom properties to dynamically created UI element/slices through LUA?

Hi @naotoy,

Yes, one way is to listen for the notifications on the UiSpawnerNotificationBus. For example OnEntitySpawned will give you the EntityId of each spawned entity and you can then set custom properties on it.

Typically a slice only has one top level entity. So you can alternatively listen for OnTopLevelEntitiesSpawned to get this top-level entity and then find any child entities from there.

Will that work for you?

Rob

H Rob,

I had access to my newly created Id’s so I used the gameplay bus to pass values to my created entities. side note: I am creating these child entities using UiDynamicLayoutBus.Event.SetNumChildElements

This seemed inefficient though, but I noticed you said that: “… will give you the EntityId of each spawned entity and you can then set custom properties on it”. How would you set custom properties to a UI entity by utilizing the entityId from a parent or elsewhere? This was what I was trying to accomplish.

Thank you for your help

Hi @naotoy - can you provide an example or describe what kind of properties you’d like to set?

Hi @naotoy,

Thanks for the clarification. I was thinking that you were dynamically creating entities using the UiSpawner and dynamic slices. I see that you are using UiDynamicLayout instead.

When you call SetNumChildElements the DynamicLayout component will either create more child elements by cloning the prototype or delete child elements if there are more than requested.

I would suggest that, after calling SetNumChildElements, you use other buses to get the child elements of the layout entity and iterate over them and set the properties that you want. To get the child entities you would use the UiElementBus.

Does that help?

Rob