Blender - how to add multiple of the same component like in Unity?

I’m trying to make a clickable hotspot in Blender like the samples for Unity has so I am using the set active on click component but I can’t add multiple of them like you can in Unity. I need one to hide/show the other state button and one to toggle a panel.

To add multiple instances of the same component in Blender using Needle Engine, similar to Unity, you typically need to manage these components within the constraints of Blender’s design. Here’s a straightforward approach:

  1. Create Custom Components: Since you want multiple SetActiveOnClick components to handle different objects, consider creating custom components in TypeScript. Each TypeScript class can represent a different behavior you want to apply, enabling you to add multiple components.

  2. Use Blender’s Needle Components Panel: You can add components through the Needle Components panel in Blender. This is done by creating unique components for each specific function you want, which can be then easily added to any object (see the documentation).

  3. Component Setup Code:

    • Define a custom component by creating a .ts file in your project. Here’s an example TypeScript layout for creating a new component:
      import { Behaviour } from "@needle-tools/engine";
      
      export class ShowButtonOnClick extends Behaviour {
          targetButton: Object3D;
      
          start() {
              this.gameObject.onClick.Add(() => {
                  if (this.targetButton) {
                      this.targetButton.visible = !this.targetButton.visible;
                  }
              });
          }
      }
      
    • Similarly, create other variations of components for different interactions.
  4. Adding Components: Use the operator wm.component_selection, provided by Needle Engine, to add these components to your objects in Blender .

  5. Component Management: Register your scripts so they appear in the Needle Components panel. Use the needle.addcomponent operator to programmatically add your written components .

Remember, each unique functionality should be encapsulated in its own component file to effectively simulate having multiple instances of the same component with different settings.

For step-by-step guidance and to ensure your setup aligns with the Needle Engine specifications, see the Needle Engine documentation: Needle Engine Docs. If you encounter any issues, make sure that all components are properly registered and that dependencies like @needle-tools/needle-component-compiler are up-to-date (see index).

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

Hello, multiple components of the same type on the same object is currently not supported in the Blender UI. A workaround would be to use a custom component that adds the necessary SetActiveOnClick component at runtime in awake()

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