Apparently Start() is no longer performed first…
In my main script I have this:
function ShowValidity()
{
var targetArea : Rect = GetGridArea();
var i : int = 0;
Debug.Log("Showing Validity for " + targetArea );
for (var x : int = targetArea.x; x <= targetArea.width; x++)
for (var y : int = targetArea.y; y <= targetArea.height; y++)
{
var GB : GridBlock = grid.Grid[x,y].GetComponent(GridBlock);
posMarkers[i++] = Instantiate(Marker, GB.transform.position+ Vector3(0,0.01,0), Quaternion.identity);
posMarkers[i-1].transform.localScale = Vector3(grid.blockWidth, 1, grid.blockHeight);
posMarkers[i-1].gameObject.SendMessage("SetTexOffset", validPlacement ? 2 : 3);
}
}
In my prefab I have this:
function Start()
{
var m : Material = cursor.renderer.material;
m.mainTextureScale = Vector2(0.5, 0.5);
m.mainTexture = cursorTex;
if (tex == 0)
{
cursor.renderer.material.mainTextureOffset = Vector2(0.0,0.5);
Debug.Log("offset set to " + cursor.renderer.material.mainTextureOffset + " During init");
}
}
function SetTexOffset(to : int)
{
switch (to)
{
case 1: cursor.renderer.material.mainTextureOffset = Vector2(0.5,0.5); break;
case 2: cursor.renderer.material.mainTextureOffset = Vector2(0.0,0.0); break;
case 3: cursor.renderer.material.mainTextureOffset = Vector2(0.5,0.0); break;
default: cursor.renderer.material.mainTextureOffset = Vector2(0.0,0.5); break;
}
Debug.Log("offset set to " + cursor.renderer.material.mainTextureOffset + " thanks to option " + to);
}
Just check the screenshot for the result this produces… Seems SendMessage is executed before Start()…
This is of course problem 2 I am having with this particular cursor. The first being that if I Instantiate the mesh inside the prefab, only the mesh instantiates, not the entire Prefab! Since when is THIS the case that only a portion of a prefab is instantiated? Has this always been so and it only took me 5 years to run into this event?
The prefab was created by taking an empty game object and dropping a mesh into it. I then added a script to the gameObject and created the prefab from that. Now, if I drag the mesh to my other script and tell it to instantiate that, the parent with the behaviour script doesn’t get instantiated so the default texture assignment doesn’t happen. On the other hand, if I instantiate the parent object then I have to follow that up with a “find the child object inside the instantiated object” before I can continue but I don’t like hardcoding “Find” statements with names of objects. Components are okay but not child gameObjects… That feels like a hack to me plus if I want to create more prefabs like this I will have to adapt the code per object. So instead I just send a message to the parent object and trust the message to reach the intended object. This it does, but it does so before the Start() function is called…
Just tonight I had a problem where I ran a game in the editor and it worked just fine. Then I built the project and tried playing it and nothing appeared onscreen…
This after yesterday’s issue with a scene with no camera attached, just OnGUI calls resulting in fast moving animated coloured noise on every pixel not covered by an OnGUI call…
This followed by a recent discovery that the web player’s loading screen when running online, this works perfectly on Safari on my iMac but in Safari for Windows and IE for Windows both, instead of the loading graphic overlapping the prior image, instead it just scales the previous image down while the other one gets scaled up resulting in the black “Loading…” and the blue “Loading…” images appearing next to each other…
Oh I pray for 3.4.1 to be released soon as 3.4 is truly the first version of Unity that I have wanted to uninstall since 1.5!