Hi :), hope you doing well. I have some classes which share some behaviors but each one has its own specific actions. I was thinking of script a abstract class (that extends Behavior) and the other classes extends this abstrac class. But when I look for those classes i “Add Component” button, neither of them are available. Do you know what could be happening ?
This is my example, first the abstract parent class and then the child class:
Hello there – we have an experimental AI bot that might be able to help you with your question. Would you like to try this out?
How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.
It sounds like you’ve correctly identified abstract classes and subclassing as a way to create shared behavior in your Needle Engine components. However, abstract classes and the components that extend them are not directly usable in the editor until you create concrete subclasses.
The behavior you’re describing where your classes are not available in the “Add Component” button could be due to a few different reasons:
Abstract Classes: The Needle Engine editor (and Unity’s, by the way) do not expose abstract classes as components to be added because they cannot be instantiated. You need to have concrete (non-abstract) subclasses of Behaviour which do not have any abstract methods.
Export Statements: Make sure to use explicit export statements for your concrete classes, because they need to be properly registered as components that can be added through the editor.
Consider checking that your concrete subclasses (like ReceiverActivation) are properly defined, exported, and are not abstract themselves. Here is an example of a concrete class based on your NetworkingReceiver class:
import { Behaviour, serializable, NetworkConnection, setActive } from "@needle-tools/engine"; // Assuming setActive is a function from Needle Engine
export class ReceiverActivation extends NetworkingReceiver {
receiverBehavior(): void {
setActive(this.gameObject, this.booleanReceived);
}
receiverSetUp(): void {
setActive(this.gameObject, this.booleanReceived);
}
}
Verify that setActive is a correctly imported function from the engine that you intended to use.
Ensure all necessary components and their respective namespaces are properly imported.
Check that ReceiverActivation is not abstract and does not have any unimplemented abstract methods from its parent class.
Ensure there’s no TypeScript error preventing proper compilation.
If everything looks correct but the issue persists, you might want to consult the Needle Engine documentation or reach out for support directly within your development community, as they might have more context-specific insight.
1 messages leftGPT 4 thread_GmO6xLIjLOy5y0Jpj6avVJed Thanks for your feedback!
Got it, DiegoEloko. To make sure that your subclass appears in the Unity Editor, you need to ensure that it is properly annotated for serialization and marked as a Needle Engine component. Additionally, it’s necessary to have the export statement for the subclass.
Here’s an example of how you can modify your child class to ensure it appears in the Unity Editor:
In this example, I’ve added @serializable annotations to the properties of ReceiverActivation and removed the abstract declarations. This ensures that the subclass will appear as a component in the Unity Editor.
Remember that you’ll need to make sure that this code is part of a TypeScript file within your Needle Engine project and is compiled properly to be available in the Unity Editor. If you’ve already done these steps and the subclass still doesn’t appear, consulting the Needle Engine documentation or reaching out to the support community for further insights is advisable.