Can I use scene objects in VS directly?

Hi @ZeronPallas,

Welcome to our community! :slight_smile:

Theoretically, you could do almost everything in code. You could create new game objects via code, add a component via code and give the game object a position via code.

The problem is: Your code will become fairly complex. The purpose of the Unity editor is to make the programming part less complex.

This won’t work. Unity internally creates a bunch of things behind the scenes when we create a game object. Furthermore, we cannot reference any objects at the top of the class in C#. The only exception is referencing an object by calling a constructor.

An approach which is generally considered as bad practice but which comes close to your idea is finding a game object via its name:

private Text textComponent;

void Start()
{
     textComponent = GameObject.Find("Name of my game object").GetComponent<Text>();
}

Our “starting state” does not exist in our scene. We would have to access the files. It’s not difficult but requires hard-coded strings as well.

In my personal opinion, it is better to get used to the Unity editor instead of typing a lot of code to get the same things done which we do within 2 seconds. We mainly use this game engine and its editor to save us time so we can create more complex games.

In the end, it is a matter of personal preference, though. Do what you feel is best for you. :slight_smile:


See also: