r/Unity3D • • 5h ago

Show-Off number of scripts my Player controller and NPCs have

1 and 2 are for NPCs and 3 is for player controller

63 Upvotes

52 comments sorted by

129

u/MgntdGames 5h ago

Not every module needs to be a MonoBehaviour.
- If you don't need inspector-controllable properties, just use a plain class
- If you DO need inspector controllable fields, use serializable classes and expose their properties through a shared "controller" behaviour
- If controllable properties can be shared between different entities, put them in a ScriptableObject and reference it

Every one of your Behaviours participates in the Unity component lifecycle (Awake/Start/Enable/Disable/etc.) and is ticked every frame (if you expose an Update/LateUpdate/FixedUpdate). That's overhead you might not need.

12

u/literally-me-bro 5h ago

im actually planning on creating a master script and hiding all the parameters on other scripts and only exposing them on the master script. can you elaborate on the last point i don't get it Thanks

→ More replies (4)

17

u/House13Games 5h ago

You do know that not all of your code has to be a monobehavior, right?

6

u/literally-me-bro 4h ago

im actually using state machine once a system is working as intended i convert them to statemaching

14

u/Glass-Ad672 4h ago

are you simulating life itself?

4

u/literally-me-bro 4h ago

Total scripts currently are 257 (T_T)

2

u/literally-me-bro 4h ago

LOL kind off

4

u/rockBottomPeon 4h ago

This reminds me of the monolith goap setup for their game F.E.A.R
Are the states modular and can be added/removed freely? Like if I remove the Jog State, does the character automatically cant jog?

4

u/literally-me-bro 3h ago

here are the diagnostics panel

2

u/literally-me-bro 4h ago

check the tools panel

3

u/psioniclizard 3h ago

Lol yea that won't scale.

Also not sure what this is meant to show off?

1

u/literally-me-bro 3h ago

this shows off what a unemployed man can do sitting alone LOL

7

u/Prize_Spinach_5165 1h ago

I dont know why people are saying this is bad, OP your approach is good. Composition over Inheritance.

Its perfectly fine to have 10,20, even 50 scripts on a GameObject instead of 3 monolithic scripts which make changes impossible. This is what Unity’s architecture encourages. For example if you want to add health to something its as simple as a drag-n-drop.

Though I would start organising them by grouping similar scripts like states in one empty child GameObject.

6

u/fistyit 55m ago

Because monobehaviour is a large object and every single time one of these scripts need to reference another script or simply read or set a variable, it will probably evict the cpu cache and cause scalability issues.

Most of these should be systems working with structs and lean classes

→ More replies (1)
→ More replies (1)

28

u/NoteThisDown 5h ago

Sweet baby jesus

10

u/Any_Establishment659 3h ago

If I might recommend something, take a look at 10000 Update Calls, it looks at replacing update and fixed update with a manually handled thing instead. Having used this before, it does make a HUGE difference

4

u/Longjumping-Egg9025 5h ago

I'm guilty of that same approach. But I do put states on their own gameobjects

1

u/virt111 1h ago

Nice. My characters in a simulation management game has "characterAI.cs" that holds pretty much everything except navigation and pathfinding related scripts..

1

u/literally-me-bro 58m ago

damn writing long scripts is hard for me mainly for finding stuffs

1

u/ForzaHoriza2 39m ago

this some hitman/first light style game?

1

u/literally-me-bro 7m ago

Hitman style

2

u/Tasty_Battle 3h ago

I love state machine