Not instantiating prefab in the right place after 2017 update

This is the code I’m using:

    //Creates a Matrix with sizexsize
    Transform canvas = GameObject.Find("Canvas").transform;
    matrix = new GameObject[size, size];
    float tileSize = 30.0f;
    float corrector = tileSize * size / 2;
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j++)
        {
            float tempX = i * tileSize + Screen.width / 2 - corrector;
            float tempY = j * tileSize + Screen.height / 2 - corrector;
            matrix[i,j] = (GameObject)Instantiate(prefabTile, 
                           new Vector3(tempX, tempY, 0),
                           Quaternion.identity, canvas);
            //CHECK: For some reasons all the gameObjects are getting
            //instantiated in the same spot ( the middle of the canvas )
            print(matrix[i, j].transform.position);
            matrix[i, j].name = string.Format("[{0},{1}]", i, j);
            //This next line solves the problem
            matrix[i, j].transform.position = new Vector3(tempX, tempY, 0);
        }
    }

I’m trying to spawn different button objects set in a panel form in canvas. Before the update ( from 5.6 to 2017.3) it worked as expected. After the update all the prefabs, which are mainly unity buttons, instantiated in the middle of the canvas. I checked that the position vector I was passing was correct and it is. To solve this problem I have to set the position again after the instantiation with the same exact values I passed on to the instantiate function.

I was able to find a momentary solution for this but I’d like to know why this might be happening to have a better understanding.

Thank you in advance!

Your code looks fine, if it is breaking after an update I would suggest deleting the class and creating a new one.

Any Ideas???

I recently updated another project from 5.6 to 2017 and something similar happened. Before the update the bullet would have a force applied in the direction of the mouse cursor, but for some reason now it’s firing up all the time. It seems like the rigidbody.AddRelativeForce is just acting like rigifbody.AddForce.

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) 
    mousePosition = hit.point;
GameObject bulletGO =(GameObject)Instantiate(bulletPrefab,
transform.position, 
Quaternion.identity);
bulletGO.transform.LookAt (mousePosition);
Rigidbody bulletRB = bulletGO.GetComponent<Rigidbody> ();
bulletRB.AddRelativeForce(Vector3.forward*1000);