# Why Object3D type not "Transform" field in Unity

**URL:** <https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653>\
**Category:** 🌵 Needle Engine\
**Tags:** question, docs\
**Created:** [August 6, 2024, 6:35am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653 "2024-08-06T06:35:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oot4chi](https://forum.needle.tools/user_avatar/forum.needle.tools/oot4chi/32/3817_2.png) [@oot4chi](https://forum.needle.tools/u/oot4chi)\
**Post date:** [August 6, 2024, 6:35am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653/1 "2024-08-06T06:35:39Z")

</div>

```auto
  // this will be a "Transform" field in Unity
    @serializable(Object3D) 
    myObjectReference: Object3D | null = null;

```

[https://engine.needle.tools/docs/scripting.html#serialization-components-in-gltf-files](https://engine.needle.tools/docs/scripting.html#serialization-components-in-gltf-files)

---

<div class="post-metadata">

**Author:** ![oot4chi](https://forum.needle.tools/user_avatar/forum.needle.tools/oot4chi/32/3817_2.png) [@oot4chi](https://forum.needle.tools/u/oot4chi)\
**Post date:** [August 6, 2024, 6:44am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653/2 "2024-08-06T06:44:22Z")

</div>

![image](https://europe1.discourse-cdn.com/flex006/uploads/needle1/original/2X/7/7d310f8f40e1b484a0858dc9975e4697c7331fae.png)  
 ![image](https://europe1.discourse-cdn.com/flex006/uploads/needle1/original/2X/a/af396ec0098282a81d56105fd8a763a4f9f835eb.png)

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [August 6, 2024, 7:35am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653/3 "2024-08-06T07:35:19Z")

</div>

If you want this to be a Transform you can annotate it with a comment like so:

```ts
//@type UnityEngine.Transform
@serializable(Object3D)
myTransform?: Object3D;

```

At runtime it will both be a Object3D

Also note that your second example is missing the Object3D in the @serializable: `@serializable(Object3D)` is required so that it results in the correct type. A GameObject and a Object3D are essentially the same - the GameObject **type** just exposes some more methods

---

<div class="post-metadata">

**Author:** ![oot4chi](https://forum.needle.tools/user_avatar/forum.needle.tools/oot4chi/32/3817_2.png) [@oot4chi](https://forum.needle.tools/u/oot4chi)\
**Post date:** [August 6, 2024, 8:16am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653/4 "2024-08-06T08:16:54Z")

</div>

How About Enum Show this in Unity

```auto
enum Direction {
    Up = 1,
    Down = 5,
    Left = 10,
    Right = 15
  }
  
export class GameManager extends Behaviour {
    dir: Direction = Direction.Left;
}

```

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [August 6, 2024, 8:41am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653/5 "2024-08-06T08:41:27Z")

</div>

You can just declare it like this in your Needle component:

```ts
enum Direction = {
  Up = 1,
  Down = 5,
  Left = 10,
  Right = 15,
}

export class GameManager extends Behaviour {
  @serializable()
  dir: Direction = Direction.Left;
}

```

and in Unity make sure you have an enum with the name Direction in your C# code somewhere. Then it will be show up as an enum dropdown (we don’t automatically generate new C# enum types so you need to make sure that this type exists in Unity and it will be picked up by our compiler the next time it runs)

---

<div class="post-metadata">

**Author:** ![system](https://forum.needle.tools/user_avatar/forum.needle.tools/system/32/20_2.png) [@system](https://forum.needle.tools/u/system)\
**Post date:** [August 19, 2024, 8:42am UTC](https://forum.needle.tools/t/why-object3d-type-not-transform-field-in-unity/1653/6 "2024-08-19T08:42:01Z")

</div>

Closed on August 19, 2024, 8:42am UTC

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