Question by
SkandYxyz · Jan 29, 2016 at 08:51 PM ·
instantiateprefabevent
Event called on prefab instantiate
Hi!
I ask myself if there is any event called, when a prefab is instantiated, so i can call a function.
best, Andre
Comment
Answer by milleniu · Jan 29, 2016 at 10:42 PM
When you instantiate a prefab the awake and start function are called. For example if you put this on your prefab :
using UnityEngine;
using System.Collections;
public class Hello : MonoBehaviour {
void Awake () {
Debug.print("Awake");
}
void Start () {
Debug.print("Start");
}
}
In the console you will see :
Awake
Start
In the case you want to set a parameter from the spawner to the spawned object you could use SendMessage like this :
void Spawn () {
Transform target = Instantiate(prefab, transform.position, Quaternion.identity) as Transform;
target.SendMessage("Initialisation" /*, your param*/);
}
not an answer. If there is no built-in mechanics - answer must be "No"