- Home /
See me last comment.
FieldInfo.GetValue with GameObject field
Using FieldInfo.GetValue with GameObject field doesn't work.
Code always gives null result:
public GameObject someVar;
...
GameObject go = fieldInfo.GetValue(parentScript) as GameObject;
While the same with any Component works fine:
public Transform someVar;
...
Transform tr = fieldInfo.GetValue(parentScript) as Transform;
Why could it be? Is it possible to get GameObject variable through reflection?
Thanks
What's the simplest example you can post that reproduces the problem? As it stands, there's obviously some other code that you're not showing. What is parentScript
? How did you get fieldInfo
?
fieldInfo.GetValue(parentScript).gameObject wont work?
or
(GameObject)fieldInfo.GetValue(parentScript)
?
I haven't messed with that. Just the first thing that came to $$anonymous$$d.
Thank you all for the response! I've made a sample project from scratch and the problem appeared to be in the other thing. In the code I've been checking:
if (fieldInfo.GetValue(parentScript) != null)
And it was NOT null. Even if the variable was empty! It is something new for me. Anyway the question is closed. Thank you once again )