Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
waynecochran's avatar
10 months ago
Solved

Scale component has no effect on SceneObject stored in an Entity

I am able to create SceneObject's that end up being contained within a specific entity as follows

val fooObject = SceneObject(scene, fooMesh, "foo", entity = fooEntity)

I am able to call setPosition(), setRotationQuat(), and setScale() on fooObject and get the desired effect.
When I try to set these transforms on fooEntity only the Transform component works  but fooScale is ignored:

fooEntity?.setComponent(Scale(fooScale))            // seemingly ignored
fooEntity?.setComponent(Transform(fooPose))  // works

If I replace setting the Scale component and directly set the scale on the SceneObject this works:

fooObject?.setScale(fooScale)

This work around is fine as long as stick with only uniform scales and compose the transformations by hand. But I have use cases where I have a hierarchy of transformations that do not have uniform scales.

Is there some other ingredient I need for the Scale component to work? It obviously works with Entities containing other model payloads.

  • Hi!

    Apologies for the confusion. One thing you need to make sure you do (which is often omitted from our custom SceneObject examples) is attaching it to the SceneObjectSystem. This makes it fully linked in the ECS and other Kotlin systems can grab the SceneObject (like controlling the Visible or Scale components). 

    systemManager
    .findSystem<SceneObjectSystem>()
    .addSceneObject(
    fooEntity,
    CompletableFuture<SceneObject>().apply { complete(fooObject) })

    We use a future here to allow you to do async loading or waiting on object loads.

    Hope this helps!

3 Replies

Replies have been turned off for this discussion
  • dav-s's avatar
    dav-s
    Meta Employee

    Hi!

    Apologies for the confusion. One thing you need to make sure you do (which is often omitted from our custom SceneObject examples) is attaching it to the SceneObjectSystem. This makes it fully linked in the ECS and other Kotlin systems can grab the SceneObject (like controlling the Visible or Scale components). 

    systemManager
    .findSystem<SceneObjectSystem>()
    .addSceneObject(
    fooEntity,
    CompletableFuture<SceneObject>().apply { complete(fooObject) })

    We use a future here to allow you to do async loading or waiting on object loads.

    Hope this helps!

    • Ok -- I'll give it a go.
      Why does adding Transform(Pose) component work but adding a Scale component does not?

    • I am still not sure how the sceneObject gets fully linked to the ECS system.
      Something must be done in the lambda below that associates sceneObject with fooEntity ... what does the complete () function do in this case? i.e. what is suppose to be done in the code marked XXXX below?


      val
      fooEntity = Entity.create(
      listOf(
      TransformParent(fooParentEntity),
      identityScale,
      identityPose
      )
      )
      val sceneObject = SceneObject(scene, fooMesh, "foo", entity = fooEntity)
      sceneObjectSystem.addSceneObject(
      fooEntity,
      CompletableFuture<SceneObject>.apply {
                      // XXXX sceneObject XXXX
      }
      )