Property transform does not exist on type Gameobject?

Updated Needle by a few versions in Unity to the latest available as of today and now I get this error, what should I replace transform with if I want to access it from a Gameobject? e.g. this example here now fails when it used to work:

    //Reset object pos first
    console.log(this.new?.transform);
    //@ts-ignore
    this.new?.transform.position.copy(this.resetPos);

In the updated version of Needle Engine, it seems that direct access to the transform property on GameObject has been replaced or modified. From the files, it appears you should directly access the position by using properties or methods provided specifically for the GameObject or Transform class in Needle Engine.

In your code example:

// Reset object pos first
console.log(this.new?.transform);
// @ts-ignore
this.new?.transform.position.copy(this.resetPos);

You might need to change the way you access the transform properties. A possible solution can be using built-in methods or accessing the properties directly on a compatible object or wrapper provided by Needle Engine.

For instance, if this.new is a GameObject, you should maybe do something like:

// Assuming 'this.new' is a suitable instance that can access position directly
console.log(this.new?.position);  // Ensure position is a defined property or getter
// Copy position
this.new?.position.copy(this.resetPos);

This adjustment is necessary due to internal changes in how transform properties might be accessed via Needle Engine’s integration with Three.js and the potential shift in accessing scene graph elements like position, rotation, etc. (see the documentation).

I’d recommend checking out the detailed Needle Engine Docs for up-to-date examples of how to handle GameObject manipulations in the latest version if this suggestion does not fully resolve your issue.

Please provide more context or any logs if the issue persists or if there are additional components involved.

24 replies left
thread_zCv5eefvevPqgw0wv7NVmgVe
Reply to this message to continue the conversation

Hello,

transform has been removed, please just use this.gameObject (or this.new.gameObject in your example)

The transform property in Needle Engine has always been just a wrapper around this.gameObject for users coming from Unity - but the use of it was never encouraged and causes more confusion than it helps since it is effectively the same (just one more indirection)

1 Like

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