How do you structure large components with multiple logic parts?

In my older project, I made the mistake of writing all logic inside one component file, which made the code hard to maintain and debug. Now I’m considering splitting the logic into separate classes that get passed the component and then doing all logic from there. But I'm wondering if there’s a better design pattern I should follow. Maybe behavior modules? State machines? Multiple components? How do you structure your complex component logic? Would love to hear what works for others.
Solution:
1 what is your usage case 2 I think composition, it means to keep it half hardcoded / half encapsulated parts...
Jump to solution
15 Replies
Solution
Tester
Tester6mo ago
1 what is your usage case 2 I think composition, it means to keep it half hardcoded / half encapsulated parts
Tester
Tester6mo ago
^ when I was making the weapon system that helped Some parts were hardcoded and some separated across multiple components on the same instance
Mirrox
MirroxOP6mo ago
2 I think composition, it means to keep it half hardcoded / half encapsulated parts
Yes, I'm also thinking of using composition
1 what is your usage case
In the previous project I had a ServerCharacter component, which contained all the logic (takeDamage, loadTrack, etc.). In the current project I need to make an FPS style camera with viewmodel arms
Tester
Tester6mo ago
^ - health component or absolutely separated to service - Camera component - animator component The longer you overthink about it the longer you're not doing it I think Then for each new feature you can implement controller/service - this is insanely scalable from my experience
Mirrox
MirroxOP6mo ago
Yeah that's my problem, I try not to overthink for so long but usually it makes things worse lol
Tester
Tester6mo ago
I've been through it recently 😭 And the final design I ended up on almost everything is half composition half hardcoded The more separated it is sometimes, the better, but if done too much it can make worse E.g. camera is worth separating in a component imo Wheels in the car - is not worth separating
Mirrox
MirroxOP6mo ago
Now I'm thinking about how to better implement the composition 😭 Would it be better to make a field in the class for each component of the composition or to loop through all of them and stuff them into an array? overthinking is killing me :sobbing:
Tester
Tester6mo ago
Dw, it gives ideas Just if you don't try to implement it you will not know what's wrong with the idea sometimes But yeah, I can totally understand you It's better to just have a variable for each Cause it's not limitless amount Imo
Mirrox
MirroxOP6mo ago
maybe..
Tester
Tester6mo ago
Think do you really need to separate something if it's small and used only once or smth?
Mirrox
MirroxOP6mo ago
yeah true
Tester
Tester6mo ago
1 part how I broke out of overthinking of separation is I started using AI code autofilling 😅 , which means I can write way more slop faster ^ the main problem is that you're thinking how long you gonna be writing it for and how much energy will it take from you and esp if it's wrong
Mirrox
MirroxOP6mo ago
Not sure if this is a good practice, but sometimes it helps me to just trashcoding the necessary thing, then refactor the code depending on what is useful and what is not
Tester
Tester6mo ago
Since with AI I can write faster that means I don't have to care about wasting energy if it's "not the right approach" Can you try actually implementing it? It seems hard cause you have to write it and if it's wrong you have to change it, but it's really easy, just start and you'll see If you're worried about reworking it, can you create a branch? It will relieve some of the stress ^ if you thinking of an idea and it seems somewhat valid, start writing it and thinking of a solution at the same time and how it can be improved Again, while writing Let's say if something ask, we could try to brainstorm it :3
Mirrox
MirroxOP6mo ago
I'll probably stick to that variant :blobthanks:

Did you find this page helpful?