Regarding Unity's ability to recognize references to help in the player optimization


I’m trying to make myself a good practices guideline to work with unity. But I’m still a noob, So i’m searching for your help

I want to stop using the GameObject.Find, I’m trying to find all the ways posible for me to stop using it.

I think that a game object doesnt need to have a dependecy on another game object so in order to reduce this, I need to stop using gameObject.Find and reduce the number of gameobject references I expose in the inspector.

For this, I wanted to use a event driven methodology of communication between the GameObjects. ( this is my thinking, if someone has a better suggestion or critic regarding this please let me hear you. but this is not my question )

Ok, seems neat, but today reading about the resources folder I found this:

In Unity you usually don’t use path names to access assets, instead you expose a reference to an asset by declaring a member-variable, and then assign it in the inspector. When using this technique Unity can automatically calculate which assets are used when building a player. This radically minimizes the size of your players to the assets that you actually use in the built game. When you place assets in “Resources” folders this can not be done, thus all assets in the “Resources” folders will be included in a build.

So if I understand well, setting the assets in the inspector helps unity to achieve optimization by recognizing which assets are beign used and which not.

If I use GameObject.Find does unity still calculates which assets to build?

And if I recur to an event driven methodology, where a game object only listens and dispatches events that other Gameobjects will process, then will I loose this unity’s special ability to optimize the assets building?

I dont know if my question is kind of silly, maybe unity handles the assets different from the GameObjects, please correct me if is like this.


All this says is IF YOU CAN

instead of using resources.load(“object”)


public gameobject Myobject;

then go into the unity editor and drop the appropriate game object into there

Thats not always possible. Mostly its not possible if the game object doesn’t exist yet.

For example if you have a script that takes input and literally combines that to make a whole new object. Then it cant load the object because the object didnt exist UNTIL you pressed play.

so if your going to use resources.load(“”) dont.
Unless the object is generated by the game

However if the object is something that still exists when the game ends. Like a bullet or a gun or soemthing. Don’t do resources.load(“gun”)

instead at the top of the script type

public gameobject mygun



then go ahead and in the inspector drag the game object from wherever it is to the empty slot in the inspector.