WorldTransform always zero?

I’m trying to get the absolute world coordinates of an object inside my script. I imagined it would be as simple as:

const myObj = await Scene.root.findFirst(‘myObj’);
const objX = myObj.worldTransform.x.pinLastValue();
const objY = myObj.worldTransform.y.pinLastValue();
const objZ = myObj.worldTransform.z.pinLastValue();

However I found the values for objX, objY and objZ will always be zero, regardless of the actual position.

If I monitor the actual values using for example Diagnostics.watch("objX: ", myObj.worldTransform.x) then the values will show correctly. I am just unable to retrieve them inside my script?

What am I doing wrong?

Thanks for any help or pointers!

Andy

I imagine you’re running this script when the effect starts. I think the position values always start at 0, then they get real positions on the first rendered frame.

If you want to constantly react to these positions, you should use a signal monitor, similar to what the watch method is doing.

myObj.worldTransform.x.monitor().subscribe((snapshot)=>{
  // snapshot.newValue
})

Thanks for your suggestion Josh! If that’s indeed the case then I believe this is a bug with Spark Studio (or at least “unexpected and undocumented behavior”).

I’ve worked around the issue by adding a patch for the required object and feeding the global position vector as an input value into my script via a Global Transform patch. Calling pinLastValue() on the components of the input value works as expected.

Anyway, it’s weird that such a workaround is necessary…

Regards,
Andy

I think it’s technically doing the correct thing since there is no value that exists BEFORE the effect starts. I agree that it’s not intuitive though.

Returns a new RgbaSignal containing a constant value which is the last value of the specified signal before pinLastValue is called.

Anyway, for the sake of responsiveness, I always recommend using signal monitors and not pinLastValue, since the latter always gives a slightly outdated value.