A game about forced loneliness, made by TACStudios
1# Add the RenamedFrom attribute to a C# script
2
3To 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](vs-refactoring.md).
4
5To add the attribute to a C# script:
6
7<ol>
8<li><p>[!include[open-project-window](./snippets/vs-open-project-window.md)]</p></li>
9<li><p>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 <strong>External Script Editor</strong>.</p>
10<div class="NOTE"><h5>NOTE</h5><p>For more information on script editors in Unity, see <a href="https://docs.unity3d.com/Manual/ScriptingToolsIDEs.html">Integrated development environment (IDE) support</a> in the Unity User Manual.</p></div>
11</li>
12<li><p>In your external editor, do the following:</p>
13<ol type="a">
14<li><p>Add the <code>[RenamedFrom]</code> attribute above the definition of the part of the script you want to rename.</p></li>
15<li><p>Add the element's old name as a string to the <code>[RenamedFrom]</code> attribute, as its parameter. For example:</p></li>
16<pre><code class="lang-C#">
17using UnityEngine;
18using Unity.VisualScripting;
19
20[RenamedFrom("Character")]
21public class Player : MonoBehaviour
22{
23 [RenamedFrom("InflictDamage")]
24 public void TakeDamage(int damage)
25 {
26 //...
27 }
28}
29</code></pre>
30</ol></li>
31<li><p>[!include[save-script](./snippets/vs-save-script.md)]</p></li>
32<li><p>[!include[return-unity](./snippets/vs-return-unity.md)]</p></li>
33<li><p>[!include[regen-node-library](./snippets/vs-regen-node-library.md)]</p></li>
34</ol>
35
36> [!NOTE]
37> If you change the namespace or namespaces used in your script, you must include the old namespace or namespaces to use the `[RenamedFrom]` attribute.
38
39## Next steps
40
41Unity 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.
42
43## Additional resources
44
45- [Refactor a C# script with Visual Scripting](vs-refactor-add-attribute.md)
46- [Configure project settings](vs-configuration.md)
47- [Add or remove types from your Type Options](vs-add-remove-type-options.md)
48- [Custom C# nodes](vs-create-custom-node.md)
49- [Custom events](vs-custom-events.md)