Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

How to Add Comments/Notes to a GameObject in Unity3D

5.00/5 (2 votes)
2 Oct 2017CPOL1 min read 30.4K  
This short tip teaches you how to comment a gameObject in Unity game engine for documentation purposes.

Introduction

For documenting your Unity project, you may want to add a note (e.g., this gameObject manages the gun inventory, etc.) to your gameObject in Unity Editor, but currently there is no way to do so. In this short article, we show you a simple and flexible tip to add a note to any gameObject in Editor.

Explanation

In order to add a note to a gameObject in Hierarchies window:

  1. Create a script called "ThisIsComment". Remove everything from the script and copy the following code to it:
    C#
    using UnityEngine;
    /// <summary>
    /// Attach this script to any gameObject for which you want to put a note.
    /// </summary>
    public class ThisIsComment : MonoBehaviour
    {
        [TextArea]
        public string Notes = "Comment Here."; // Do not place your note/comment here. 
                                               // Enter your note in the Unity Editor.
    }
  2. Attach this script to all of the gameObjects to which you want to add note (you can drag this script to the gameObjects or to use "Add Component" button in the corresponding Inspector window). Here is an example:

    Image 1

    Note: Do not change the content of the script. To add your note, go to the Unity Editor and write your note there (not in the script!).

    Obviously, each gameObject can have a different note with this method.

  3. (Optional): To make your note stand out from the other components in the Inspector window, move the "ThisIsComment" script up. To do so, click on the script name and drag it below the Transform component.

    Note: After moving the component up, Unity might warn you that "This action will lose the prefab connection. Are you sure you want to continue?". Don't worry. Select "Continue" and then click on the "Apply" button on the top-right of the Inspector in order to apply this change to its prefab.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)