It seems you are experiencing an issue where buttons, specifically the “Toggle Rotation” button, are repeating in your Needle Engine component.
The code you shared for adding the button looks correct, but repeated instances might be caused by start() being called multiple times. To address this, you could implement a check to see if the button is already present before adding it again.
Here’s how you might modify the code to prevent button duplication:
start() {
// Check if the button already exists
if (!this.context.menu.querySelector('[data-needle="toggle-rotation"]')) {
this.context.menu.appendChild({
label: 'Toggle Rotation',
icon: 'camera',
onClick: () => {
this.toggleRotation();
},
'data-needle': 'toggle-rotation' // Add a unique identifier to the button
});
}
}
This code ensures that before appending the button, it checks if a button with the same data attribute is already present, preventing the duplication.
If you continue to encounter this issue, please provide more context, such as whether the start() method is being called multiple times or if this is part of a larger component lifecycle.
For more information on handling menus and buttons, you might find this documentation helpful: Needle Engine Docs.
If you have further questions or need more specific guidance, feel free to ask!
1 replies left - Get a PRO license for more AI replies. thread_DslEogDzN7zBWcRnPf5SZSZy Reply to this message to continue the conversation
Does the component exist multiple times in your scene? Same with SyncedRoom component: do they exist more than once? Or do you load e.g. sub-scenes that have them?