- Home /
Local Variable Lost in Ifs
I have this method inside my Bodypart class:
public GameObject PartShape(string pname)
{
GameObject pshape;
if (pname == "Bulb")
pshape = Resources.Load ("p_bulb") as GameObject;
else if (pname == "Wedge")
pshape = Resources.Load ("p_wedge") as GameObject;
else if (pname == "Segment")
pshape = Resources.Load ("p_segment") as GameObject;
else if (pname == "Limb")
pshape = Resources.Load ("p_limb") as GameObject;
else
pshape = GameObject.CreatePrimitive (PrimitiveType.Plane);
return pshape;
}
It should define the bodypart prefab to use based on the name passed to Bodypart at instantiation. In a seperate Testing script I simply instantiate Bodypart and do some Debug.Logging. I've found that all the variables of Bodypart get set to what I pass into it, including partName. However by debugging partShape I get Null.
Question: Given the above function, used in the form "partShape = PartShape(partName);" inside Bodypart, why does it return Null?
Thanks in advance.
Is it null in every case? Resources.Load("p_limb") will look in the Assets/Resources folder for anything called "p_limb". You'll get null if it can't find any of these so the first thing to do is pinpoint which resource it's failing to find. If it's not finding any then the first thing to do is get it successfully finding SO$$anonymous$$ETHING.
I only have p_bulb for now for testing, but I'll double check all that when I get home. Thanks for the quick reply!
I had an extra few $$anonymous$$utes so I reviewed this. Turns out the prefab was made, but not in Resources. Derp. I will have to learn to not rule any possibilities out when finding problems.
Sorry I wasted your time, but thank you!
Edit: Would Checkbox/Thumb Up but it's a comment not a reply.
No time wasted! co$$anonymous$$g here and thinking about other people's problems for a few $$anonymous$$utes is a great way to get fresh perspective on your own.
Answer by ClanDestiny · Jan 30, 2015 at 05:53 PM
smoggach wrote
"Is it null in every case? Resources.Load("p_limb") will look in the Assets/Resources folder for anything called "p_limb". You'll get null if it can't find any of these so the first thing to do is pinpoint which resource it's failing to find. If it's not finding any then the first thing to do is get it successfully finding SOMETHING."
Sorted!