C
C#2y ago
eduardoA

❔ snippet help

In unity, is always s good practice to null check component. I made this
<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
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName
it dosent close the if. it dosent put all of the debug statement. it dosent put in $Component Nam$ so I can edit it
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server