docs.unity3d.com
    Show / Hide Table of Contents

    Add the RenamedFrom attribute to a C# script

    To use nodes generated from a custom C# script in a project after you rename a member, class, struct, type, or enum, add the [RenamedFrom] attribute to the relevant API element in the script file. For more information on the [RenamedFrom] attribute, see Refactor a C# script with Visual Scripting.

    To add the attribute to a C# script:

    1. Go to Window > General > Project, or press Ctrl+5 (macOS: Cmd+5) to open the Project window.

    2. In the Project window, double-click the C# script file you want to refactor. Unity opens the file in the program you specified in your preferences, under External Script Editor.

      NOTE

      For more information on script editors in Unity, see Integrated development environment (IDE) support in the Unity User Manual.

    3. In your external editor, do the following:

      1. Add the [RenamedFrom] attribute above the definition of the part of the script you want to rename.

      2. Add the element's old name as a string to the [RenamedFrom] attribute, as its parameter. For example:

      3. 
        using UnityEngine; 
        using Unity.VisualScripting; 
        
        [RenamedFrom("Character")]
        public class Player : MonoBehaviour
        {
            [RenamedFrom("InflictDamage")]
            public void TakeDamage(int damage)
            {
                //...
            }
        }
        
    4. Save your script file.

    5. Return to the Unity Editor.

    6. Follow the process described in Configure project settings to regenerate your Node Library.

    Note

    If you change the namespace or namespaces used in your script, you must include the old namespace or namespaces to use the [RenamedFrom] attribute.

    Next steps

    Unity recommends that you leave the attribute in the script file, even after a successful recompile. Nodes that use your C# script no longer have errors related to a missing member, class, struct, type, or enum.

    Additional resources

    • Refactor a C# script with Visual Scripting
    • Configure project settings
    • Add or remove types from your Type Options
    • Custom C# nodes
    • Custom events
    In This Article
    • Next steps
    • Additional resources
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023