- Home /
unity3d can't create instantiated reference in awake
I'm dealing with an annoying bug that occurs randomly. Once it occurs, it will stay this way until i delete and recreate the object the script is attached to.
The Script is called AnimatedTexture.cs. It awake function looks like this
MeshFilter myMeshFilter;
Mesh myMesh;
Awake()
{
myMesh = myMeshFilter.mesh;
}
Many Game Objects in the scene have this script attached to them. When Unity is in play mode, selecting a game object with this script attached shows the mesh filter is referenced to an instantiated copy.
So the bug is, sometimes, the mesh doesn't get assigned and the meshFilter is not using an instantiated copy.
Could this be a script execution order issue?
Have you tried putting that in Start? The script should be loaded with all its internal references on Awake, but you never know...
I can't do that. Im reserving start() for code that depends on code initialised/set up in Awake();
Then put the code from awake before the code already in start
@whydoidoit isn't it true that when you assign to a variable a reference of, in this case, a mesh of a meshfilter, a new instance of meshFilter is automatically created?