Question by
jcroderman · Apr 03, 2018 at 02:39 PM ·
instantiateupdatefixedupdate
Instantiation Breaks Update Function
Whenever I call instantiate in my code, the FixedUpdate function stops running every frame. After doing some isolating, I managed to find out that the issue seems to be stemming from the use of transform.position in instantiate. I replaced transform.position to "new Vector3(0, 0, 0)" and the FixedUpdate function worked fine. Any ideas as to why this is?
void FixedUpdate()
{
if (timeSinceLastCannonUp != 0)
timeSinceLastCannonUp--;
ShootCannonBall(true);
}
void ShootCannonBall(bool dirUp)
{
if (timeSinceLastCannonUp == 0)
{
GameObject ball = Instantiate(cannonball, transform.position, Quaternion.identity);
(ball.GetComponent<Cannonball>() as Cannonball).SetParams(false, dirUp, rb2d.velocity.x);
ball.transform.SetParent(LevelManager.instance.cannonballs);
timeSinceLastCannonUp = 200;
}
}
Comment