Attaching Objects using script,not by Dragging?

I creat an instance of type GameObject in script. like
public GameObject NewInstance;

unity creats an empty tab in inspector with name: New Instance, and i have to attach it a GameObject by dragging or clicking small circle and selecting.

My Question is it Possible to assign the GameObject to variable NewInstance from C# script directly and not doing it by dragging in Inpector.
Thanks.

If its just an object or component in the scene, you can use one of the find methods such as GameObject.Find (Unity - Scripting API: GameObject.Find) to get the reference in the “Start” or “Awake” or “OnEnable” method in the monobehaviour :slight_smile: If its an asset in the project rather than the scene, then its much much more of a pain.

This is because you have to provide proper full path information, file type etc and the API to do such is a bit of a pain to use compared to a single line find function.

Thanks , You Solved My Problem.