Hi I have this nasty problem.
I assigned prefab in Inspector, later instantiate this prefab.
This was working perfectly fine, but once some bug occurred Unity closed.
Since then the prefab is not “exported” to Android.
It is null on android (despite of being just assigned to serialized field in inspector).
I tried multiple times to assign it in inspector, or make a copy and assign.
The type is GameObject, I check it in Awake just to figure out what’s wrong.
It works in Editor but on the phone it is null in awake.
Ok after 10h of trying I have fount a workaround.
Reimporting assets didn’t work.
Below steps fixed the issue.
(Make a copy of your project folder before trying).
- I turned off Unity.
- Changed the
Assets folder name to Assets2 - I created empty folder called Assets. I
opened the project. - Project opened
with the empty scene (as the original
scene was inside Assets). - I closed Unity.
- I deleted empty folder called
Assets and changed my Assets2 folder
name back to Assets. - I opened the
Unity again. It took long time for
Unity to open as it re-imported all
assets again. - The issue was fixed.
Seems this workaround does a bit more work then re-import assets command.
I would call it deep re-import.
almost sounds like a prefab was not updated or something. For instance, if you have a whole panel made as a prefab and it had a script. sometimes if you forget to update the prefab in assets to a change in your scene you are building. and you game creates a new instance if one doesn’t exist for some reason like you destroyed it and re instantiated it via said prefab then this null reff would occur. hard to say without seeing your whole project but hey.