Lightweight Game Object

Hi! My name is Igor, and I’ve been developing games on Unity for 5 years


Over time, my approaches to game development architecture have changed, and I realized that one of the most flexible approaches to developing complex characters is to write small scripts, and then assemble mechanics from them as a constructor. The problem is that in order to develop game mechanics flexibly and scalably, you need to use a lot of GameObjects and MonoBehaviours, so when using this approach, you need to constantly think about memory optimization

I’d like to be able to use an alternative lightweight version of GameObject in the future without the Transform component with the ability to add various lightweight components


The question is, can I make my “Lightweight Object” class inherited from UnityEngine.Object and add it to the scene?


!(https://user-images.githubusercontent.com/22048950/207052467-fb24b3c2-2051-47a8-a320-38d8a9df77f7.png)

No offence but it sounds like you are improperly segregating your work into arbitrarily small chunks instead by responsibilities.


Probably as a result of your code having become a big pile of spaghetti in the past


I would probably suggest that loose spaghetti is still spaghetti and single responsibility principal taken to the extreme is just as bad as improper coupling with conflated concerns.


Your GameObjects should be entities in your game that need to interact with your scene/ Unitys API.


You dont need to manage your game state using GameObjects at all. You can do all of the game logic entirely in pure C# with POCOs (plain old C# objects).


They are light, you can manage them any way you want and they don’t have the overhead of needing to be added to the scene

Hey there,

as far as i’m aware: No.

In general I think you can always see it like this: With being more flexible and more generic a system will always create a slight overhead as you shift the work that you’d have to do manually onto your computer.

The better question i think should be: Do you really need this? Is this the optimization that is missing for your game to work? In my experience this is rarely the case. Most other optimizations you can do in your scripts mostly heavily outweigh the bonus you gain from these “lightweight” objects.
Did you check the profiler to see what slows you down?

Honest question from my side: what would you strip from the GameObject if there was the option? Do you really think the improvement from this would be noticable in any way?