Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
This is the kind of mindset and thinking process you need to bring to this problem:
This tells me that entryTransform exists and is being cloned. That object has three children posText, scoreText & nameText that is what the .Find is trying to find. But there are two sets of each, the template is being deactivated per the void awake method, and its clones are being instantiated correctly.
The children have text components called posText, scoreText & nameText so there issue must be around there?
The (entryTransform.Find(“posText”) returns the null
Yes, child gameobjects called posText, scoreText & nameText are all instantiated as the entryTransform’s children per the prior images uploaded
Yes, the entryTransform is a clone of the entryTemplate, placed into the entryContainer per the below line Transform entryTransform = Instantiate(entryTemplate, entryContainer);
Make a piece of code that lists all the children’s names right before you try to Find() them
for (int i = 0; i < TR.childCount; i++)
{
Debug.Log( TR.GetChild(i).name);
}
PROVE to yourself that it is there.
(Replace TR with whatever Transform you’re searching)
You have GOT to be the mad scientist and prove to yourself at each stage (via a completely different mechanism) that what you are doing is valid. Otherwise you’ll spin forever thinking “But this should be valid!” when in fact it isn’t.
Glad EdoExpression moved this here from the Input System forum. Kurt-Dekker is giving you good advice. It’s pretty much the same advice I gave you in the Input System forum. Unfortunately, you kind of ignored it. I said you should try running this:
But, for some reason, you ran a much longer, oddly edited version instead (see picture).
I told you bugs like this are pretty easy to solve. Kurt-Dekker said, “You should NEVER spend ages looking for this.” We’re both right. These are easy problems to solve if you use the suggestions you are getting. Kind of up to you if you do, but that’s how you find them.
Thanks - I’m up for the investigative work!! Attached is the result of the code below:
for (int ii = 0; ii < entryTransform.childCount; i++)
{
Debug.Log( entryTransform.GetChild(i).name);
}
I had to replace i with ii because I got an error on visual studios saying “CS0135 - A local or parameter named ‘i’ cannot be declared because the name is used in an enclosing local scope to define a local parameter”.
Interestingly, the error below states that Transform child is out of Bounds, clicking on the offending line leads to
Thank you for your patience. I get an error saying “CS0103 The name ‘rankString’ does not exist in the current context”. Hence, i edited the scrip to try and include the definition of rankString. However using the principles you provided, i tested the following code:
just pointing out that you’re using i instead of ii both in the GetChild(i) and in the loop statement incrementor (int ii = 0; ii < entryTransform.childCount; i++)
for (int ii = 0; ii < entryTransform.childCount; i++)
{
Debug.Log(entryTransform.GetChild(ii).name);
}
{/CODE]
if i remove the above, it works fine. What could cause that?