weijia_yu
weijia_yu

Reputation: 1015

Unity3D trying to understand Monoscript

I am trying to understand what does Monoscript do, according to Unity tutorial

It is important to understand that a MonoBehaviour has a reference to a MonoScript, and MonoScripts simply contain the information needed to locate a specific script class. Neither type of Object contains the executable code of script class.

A MonoScript contains three strings: an assembly name, a class name, and a namespace.

Does that mean, during build, for example, every c# classes inherited from MonoBehaviour will have a MonoScript pointing to a corresponding position in Assembly-CSharp.dll ?

Upvotes: 4

Views: 6494

Answers (1)

Overbyte
Overbyte

Reputation: 136

It appears so. Note that it applies to ScriptableObjects as well: https://docs.unity3d.com/ScriptReference/MonoScript.html?_ga=2.112551556.1460905390.1600095105-379318471.1582836001

Remember there are some other assemblies than just the one you mentioned, for example the "first pass" and "Editor" varieties. Also from Unity's documentation:

"A MonoBehaviour provides a wrapper that links to a MonoScript. A MonoScript is an internal data type that Unity uses to hold a reference to a specific scripting class within a specific assembly and namespace. The MonoScript does not contain any actual executable code."

This sounds very much like what you said. This excerpt may be found here: https://learn.unity.com/tutorial/assets-resources-and-assetbundles#5c7f8528edbc2a002053b5a6. You likely will need an account to access it.

Upvotes: 2

Related Questions