Making a shortcut for checking null component in unity
Evetime I create a new component in unity, I something like
So I created a shortcut
but when I use it, I get this
this is not what I want, where is my message? and why there is nothing here for me to edit? and hi it dosent close the if
if (!TryGetComponent(out _rb2D)) {
Debug.LogError($"There is no rigidbody component in the {transform.name}");
}if (!TryGetComponent(out _rb2D)) {
Debug.LogError($"There is no rigidbody component in the {transform.name}");
}So I created a shortcut
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity null check components</Title>
<Shortcut>ucnc</Shortcut>
<Description>This code snippet, will allow you to check you component, to see if they are null</Description>
<Author>Eduardo Gomez</Author>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
if(!TryGetComponent(out $ComponentName$))
{
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
}
]]>
</Code>
<Declarations>
<Literal>
<ID>ComponentName</ID>
<ToolTip>The component name that you want to check for null</ToolTip>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets><CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity null check components</Title>
<Shortcut>ucnc</Shortcut>
<Description>This code snippet, will allow you to check you component, to see if they are null</Description>
<Author>Eduardo Gomez</Author>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
if(!TryGetComponent(out $ComponentName$))
{
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
}
]]>
</Code>
<Declarations>
<Literal>
<ID>ComponentName</ID>
<ToolTip>The component name that you want to check for null</ToolTip>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets>but when I use it, I get this
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName if (!TryGetComponent(out )) {
Debug.LogError(ComponentNamethis is not what I want, where is my
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}"); Debug.LogError($"There is no $ComponentName$ component in your {transform.name}"); if (!TryGetComponent(out )) { if (!TryGetComponent(out )) {