I have trouble with object picking on items created by iteration with external layout

How do I…

Hi everyone, in my project I’m importing a JSON file that lists several objects, each of which contains a property that corresponds to a list of 6 “dices”. I’ve organized each Dice graphically in an external layout, so for each iteration of these elements and for each of them, I create objects from the external layout. For each creation, there’s a subevent where I apply the text value I’m interested in to a Text object (according to the documentation, object picking only works as a subevent).

What is the expected result

For each created object, each Text instance should have the appropriate value.

What is the actual result

The text value of the Text object always corresponds to the last iterated value (but if I do a console log of the text value and the extracted value, it’s correct; only in the rendering does it correspond to the last value).

Related screenshots


Updated with some screenshot

Can you explain the screen shot? Are you expecting the “ability: 1” texts to be different?

yes, exactly. Every field must be different. Here you are a screenshot of console log of what i need as value. The strange thing is that works if i print on console, but not on the render. Seems to be replaced in every iteration



immagine

Why are you setting the variable “Content” of Txt in this event? Don’t you want it to be the Text attribute of Txt?

Even if that was the Text attribute of Txt, it still wouldn’t work - there is no condition on the event or the parent events to restrict which Txt object to update. So GDevelop does them all, with the same value.

Sorry for the variable Content, that was a try to solve a problem and testing if is something about the value or the picking object.

There is no solution? I have to create these objects (BG and Txt) inside eventsheet instead to position them inside an external layout?

Ha, and just after I sent the reply I spotted that you set Txt.Text = Txt.Content. SMH at myself.


You won’t need to create them in the event sheet if you uniquely identify them in the external layout, but in a way that it can be easily determined what the Id is.

Could you suggest to me a better approach? If you are talking about applying a Id in creation I cannot do it because I could be the same problem with the text value

No, the Id would be in the external layout.

But I’d personally go for creating the objects in your scene events. That way if the number of abilities change, then you don’t have to add or remove any objects or Ids.

1 Like

Hi again, I changed approach using Prefabs that I dind’t remember about this feature is already active! That is awesome. With prefabs works! Thanks for help @MrMen

1 Like