- Home /
Animation not rendered when object is close to one another
Hi guys, first thing first. I have this code:
using UnityEngine;
using System.Collections;
public class SpawnActor : MonoBehaviour {
public GameObject actorPrefab;
private float spawnTime = 0.5f; //0.5 secs to spawn each
private float spawnCounter = 0.0f;
private int actorCounter = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
spawnCounter += Time.deltaTime;
if (spawnCounter > spawnTime)
{
spawnCounter -= spawnTime;
Spawn ();
}
}
void Spawn()
{
GameObject actor = (GameObject) Instantiate(actorPrefab);
actor.name = actor.name + "_" + (++actorCounter).ToString("D3");
actor.transform.position = Vector3.zero;
actor.transform.rotation = Quaternion.identity;
actor.animation.Play("Take 001");
StartCoroutine(DeletionCoroutine(actor, actor.animation["Take 001"].length));
}
IEnumerator DeletionCoroutine(GameObject actor, float time)
{
yield return new WaitForSeconds(time);
Debug.Log ("Actor to be deleted: " + actor.name);
Destroy(actor);
}
}
This is just a simple spawning script which will create a gameobject every 0.5 secs, play a pre-determined animation a-la cutscenes (just a simple walking forwards a few steps actually), and then deleted it at the end of the animation.
Now the problem is, every now and then, a few of the objects will be culled and not rendered at all (maybe because the time interval is too short and the objects are close to one another?). The reason I know that it is culled rather than destroyed was because I have this line in the Spawn() function:
actor.name = actor.name + "_" + (++actorCounter).ToString("D3");
And this line in the DeletionCoroutine() function:
Debug.Log ("Actor to be deleted: "+ actor.name);
And the order of the actor was actually correct, so I assume the order of the deletion itself must have been correct also.
Now the question, why did the object not rendered? How do I solve this? BTW, I've tried the "Always Rendered" in the animation's culling type to no avail.
Thanks in advance.
EDIT: I forgot some more info, if that will be useful. The GameObject doesn't have a collider at all. And actuallly I forgot to add one more line in the Spawn() function. It actually has this: actor.animation["Take 001"].speed = 2.0f;. Or in a way, the animation is played at twice the speed.
No answer yet? Oh well, I just added some delays for the spawning for now so they won't get spawned as close to one another. I hope it solved the problem for the time being.
Answer by Balin Ebergy · Feb 03, 2013 at 03:47 AM
Actually it may not because of the spawning time yet the playing time. I encountered the same problem with 3.5.6f4 and tried your solution - not work :(
After some hard works I solved the problem by applying some random delay (about 0 to 0.1s) to the objects and it works fine now. I thought it may be some bugs in Unity. Hope it will be useful for others.
Sorry, for the delay. I've been postponing the development of the game and busy with other stuffs. Thanks for the reply. $$anonymous$$aybe I'll try your solution when I'm working with it again. I'll accept your answer if I can try it myself. Again, thanks a lot.
Your answer
Follow this Question
Related Questions
Image effects do not work when rendering with multiple cameras 0 Answers
Can the Cull option in shader improve perfomances ? 2 Answers
[Solution in answers] Skinned Mesh Renderer only appears if it's visible in the Scene window 4 Answers
How to render a cinematic or a cutscene in Unity? 0 Answers
How can I solve animating objects rendering behind static? 0 Answers