Studio Niantic: setParent affect the eid reference?

Hi everyone,
The eid changed when I setParent for it. I don’t understand why setting the parent affects the referenced eid?
This is my code:

// Set obstacle in row
  for (let i = 0; i < obstacleIdArray.length; i++) {
    const obstacle = Obstacles.cursor(world, obstacleIdArray[i])
    if (obstacle.isReady) {
      obstacle.isReady = false
      const randomPosX = posXMovingArray[getRandomValue(0, posXMovingArray.length - 1)]
      world.setPosition(obstacle.iD, randomPosX, 0, 0)
      world.setScale(obstacle.iD, 1, 1, 1)
      console.log(`1.1 Set acitve obstacle eid: ${obstacle.iD} -> isReady: ${obstacle.isReady}`)
      world.setParent(obstacle.iD, rowObstacle.iD)
      console.log(`1.2 Set acitve obstacle eid: ${obstacle.iD} -> isReady: ${obstacle.isReady}`)

      if (rowObstacle.obstacleArray === '') {
        rowObstacle.obstacleArray += `${obstacle.iD}`
      } else {
        rowObstacle.obstacleArray += ` ${obstacle.iD}`
      }

      // Reset collider
      world.setParent(obstacle.colliderId, obstacle.iD)
      world.setPosition(obstacle.colliderId, 0, 1.45, 0)
      world.setScale(obstacle.colliderId, 1, 1, 1)
      break
    }
  }

Console log:

1.1 Set acitve obstacle eid: 721 -> isReady: false
1.2 Set acitve obstacle eid: 759 -> isReady: true

Take a look at this best practices guide. It’s possible something weird is happening with invalidated cursors. I recommend using .acquire and .release for long-running cursors.

1 Like

Thanks for your support!

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.