Clampf doesn't work in iOS native? (Simulator)

This is my first time porting my game over to iOS. The game works and pretty much all the functions wordk. However I’ve noticed a weird problem where my characters “eyes” position are not being clamped. This is not a problem when testing on web or web-mobile.

Here is the code and I highlighted the code that is not getting called it seems. But iOS simulator X code is not throwing up any error messages in regards to this code. It just seems like the code isn’t getting called at all, like it’s commented out or something.

      // Set the world position of the eyes
      this.eyes.setWorldPosition(desiredNewWorldPosition.x, desiredNewWorldPosition.y, desiredNewWorldPosition.z);
      //Limit the eyes position
      this.eyes.position.clampf(new Vec3(-2.0, -2.0, -2.0), new Vec3(2.0, 2.0, 2.0)); //<-- THIS CODE NOT RUN IN IOS SIMULATOR ON XCODE. 

I confirmed its the this.eyes.position.clampf(new Vec3(-2.0, -2.0, -2.0), new Vec3(2.0, 2.0, 2.0)); by commenting it out on my local running in a browser and its not an issue, i’m using CocosCreator (3.8.3)

The simulator is running iOS version 17.5, iPhone 15 being simulated.
Xcode is version 15.4.

Can’t see any big errors, tried searching for Clampf and Math but no errors/warnings about it.

I also noticed that there is the same issue in the built in simulator.


I wrote my own clamp code and the issue is no longer there. I’m almost 100% sure this is an issue inside the cocoscreators position.clampf function when it gets turned to Native code. Strangely no errors, not sure if it’s getting skipped outright.

Does this bug exists in IPA?

@jamessimo does this.eyes is a node? If so, then Node.position is a readonly property. You can not modify it in native. As on native platforms, it returns a temple JS object, so modify the temple object can not take effect on native platforms.

You should use Node.position = xxx; to modify Node.position.

Thanks for the explanation. I would like some warnings maybe when building iOS that some functions may not work due to trying to change Read only items.

As typescript lacks of the mechanism to avoid the operation. And warning message for readonly functions are not a good idea. Indeed, there is a documentation about it: Development Notes | Cocos Creator.

1 Like