In regard to string references

So woud a string reference check in regards to checking which defender the fox is colliding with be alright? When the challenge was given at the start of the video my brain instantly went to “Oh well if we just check if the name of the game object is ‘Gravestone(Clone)’ then trigger the jump animation” and it worked fine. I know string references usually aren’t the best solution to problems since the name of things can change during game development but it worked when I tested it (was gonna share a screenshot but I deleted it once the “correct” answer was given). I guess a more general way to phrase this question is it okay to sometimes code in a not so optimal if it gets you the desired results?

Hi,

Welcome to our community! :slight_smile:

In many cases, there are multiple ways to make something work in Unity, so I’m not surprised that you found an alternative solution. You are right about the flaws of string comparisons, so you want to avoid them, especially if you cannot affect the output. It might be that Unity instantiates clones as “Gravestone (Clone)” in the next update. If your code looks for “Gavestone(Clone)”, your game will not work anymore.

Long story short, yes, it it absolutely fine to develop your own solutions even if they are not as good as Rick’s. If you get problems due to your alternative solution, fix them. That’s what programmers do.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms