Set_position does not seem to be working for child elements

I have child GO’s that I need to move around the parent GO

But neither of these don’t seem to do anything

go.set_position(self.position, self.id)
go.set(self.id, "position", self.position)

But this strangely works

go.animate(self.id, "position", go.PLAYBACK_ONCE_FORWARD, self.position, go.EASING_LINEAR, 0.01)

Could you please provide a bit more context? What value does self.id have? Is the script added to the child GO? If it is, what happens if you replace self.id with “.” (which is the shorthand url for the current game object).?

Hmm, I think it’s my mistake, but partially caused by confusing architecture. I can’t set children position synchronously while I make a parent GO, because to set their parent I need to use a message, which is executed asynchronously.

So, I have to wait until msg.post(".", “set_parent”, …) executes, and then I can use set_parent.

Of cause, there are workarounds around it (such as setting children position in factory call, using world coordinates), but they are, well, workarounds.

Can we have a sycnhronous set_parent?

P.S. And also maybe a way to call deferred code without using a hack that uses animate and a dummy property?

1 Like

There are many ways of achieving this. The most powerful way is probably by running your code in a coroutine and yielding while waiting for whatever asynchronous thing it is you are waiting on.

In this example I use one of my utility Lua modules called “flow” to start a coroutine and run synchronous looking code that in fact is doing a lot of async stuff: