- Home /
Getcomponent returns null on ios
Hey all,
Building to ios I get a bunch of null refs, looking into it it turns out variables filled with a getcomponent call return null until the next frame in a ios build.
for instance with:
public Transform someTransform;
void Awake()
{
someTransform = gameObject.transform;
}
someTransform, remains null until the next frame.
I jumped from unity 3 to 2017, so maybe I've missed something? Any ideas as to why this is and what has to be done to access the component right away like the behavior in the editor?
Thanks!
this is definitely a bug. if you upgraded a project you might be better off creating it from scratch unless you want to go through all the upgrade guides. But this shouldn't be happening in a new project
Thx @hexagonius , turns out it's probably due to upgrading and the tag manager getting corrupted. Ill elaborate in my answer, but thanks a lot for helping!
Answer by Jaywalker · Feb 10, 2018 at 11:01 AM
Ok turns out it wasn't every getcomponent, only the getcomponents that use: FindWithTag. Adding a yield just moved the problem to the next frame, which I didn't notice at first.
Looking at the tag manager, I noticed there were 2 (removed) tags. And Unity notified me that they would be removed on the next start of the project. So I imagine that in the build the removed tags messed up the order, resulting in the null refs.
Restarting the project did nothing however, as the "removed" tags were still there. Adding a new tag, then restarting the project fixed that, and now the null refs are gone!