[KNIT] Should I use components for my tools?

I’m making a modular item/tool system.

Right now i’m just using metatables to make my own classes, but should I be using Knit Components instead? I don’t use components and i’m restructuring my framework since i’ve been using services as regular scripts instead of actual services. I worry that each item will need it’s own component, even if they have the same functionality only slightly tweaked.

I never actually thought about how to script tools using Knit since typically you’d put a script in each tool, but I want modularity and single script architecture.

A major issue is that every single item sends a remote event through one single Knit signal on one service, the “Item Service”. This isn’t the best way to do this, but I also don’t want to have to make a seperate service for each type of tool in the game. What can I do, and should I be using components for my tools instead of custom metatables?

2 Likes

You should have a ToolsService and ToolsController, I don’t think you would need components but u will certainly need classes, create a main Tool class that has the base functionality that all other tools will have, then create other tools by adding functionality to it (inheritance you can say?). ToolsController will make these classes work, make them pickup-able (if that’s a word), and do things that the tool itself shouldn’t handle. ToolsService will be to confirm buying and owning of a tool and for server side damage, hit detection etc. I’m unsure if that will require changing your current system too much but I’m pretty sure it’ll make it better.

1 Like

That’s currently what i’m doing, I have a ItemController which loads the item module, and the item module does everything else, the item controller just requires the module and creates a new item class when an item is created.

I was just wondering whether components would be a better choice for this, but I believe your answer works.
The main reason I was wondering was because every item uses the same event, but it sends over its’ instance and a string that contains the event name so the server knows which event to call. It’s not the best way but I was wondering if components would fix it.

Services and Controllers should be fine in this case.

The only time I would seriously recommend Knit components is within UI.

Additionally, creating custom classes and configs to help generalize your properties and methods for re-use as much as possible is a great approach for clean and performant code.

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