hello to everyone in my scene I made a script to generate random objects falling from top to bottom. The problem is that when generating objects is a small step delay that the game freezes for 1 millisecond. How can I remove the snap?
pls show the script
1ms? a frame has ~15ms, so even if you dont own a 1000Hz-screen?! you cant perceive 1ms anyway.
how long is the delay, what are these objects you instantiate?
ther is script
function Creation(tempo){
while(true){
var instanza : GameObject;
instanza = Instantiate (chrismasBall, transform.position, Quaternion.identity);
instanza.AddComponent(Rigidbody);
instanza.transform.position.x = Random.Range(10,-10);
instanza.transform.position.z = 2;
instanza.transform.position.y = 12;
Destroy(instanza, 3);
yield WaitForSeconds(tempo);
}
}
this script instantiate a simple sphere. these beads change color every second but slows down the color change. To be sure I added a particle system to the main room and you notice the delay even of particles in the generated
-so you perceive the delay as a short freeze?
-and it happens everytime a ball is created?
i am not sure but the problem could lie:
-in the game object instantiation
-in the color changing script
-maybe you already have a rigidbody on the object
-try to use one call instead of 3 instanza.transform.position = Vector3 (Random.Range(10,-10), 2, 12);
try to comment out one line at a time and watch if the lag(delay) disappears
also, -how ofter do you call Creation()? what time parameter?
if you prepare your object before hand (including the rigidbody) it should be faster, but I don’t think this would cause a noticeable hiccup.
I hope you aren’t calling create every frame (in an update for example).