Component without gameObject


I wonder if it would be possible to create a component, say a Transform, without a gameObject.

Something like

public Transform _transform = new Transform () ;

So that it would only exists within the MonoBehaviour that declares it
When I try, I get the following error message :
UnityEngine.Transform.Transform()’ is inaccessible due to its protection level

It is impossible to create a transform without a game object. I it impossible to create a game object without a transform.

If you need to dynamically create a transform, you can do something like:

public Transform _transform = new GameObject().transform;

You can also define your own classes not derived from Monobehaviour. You deal with these classes like you would classes outside of Unity (i.e use ‘new’ to create and use a constructor (not Start() to initialize).

Usually the protection level means that it needs to be static. Try:

public static Transform _transform = new Transform () ;