- Home /
Are message broadcasts instant?
Simple question but a very important question, Exactly as the title says. Does component.broadcast yield instant results or does it have to wait a frame? I want to broadcast a message to all the components parented to a parent GameObject. What for, isn't entirely relevant but its for a saving system.
this could easily be tested within 2$$anonymous$$utes... create a new scene, broadcast something and check Time.frameCount
Answer by SharpEdge · Jun 27, 2014 at 02:45 PM
Yes it's broadcasted instantly:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void Awake() {
Debug.Log("Awake");
}
void OnEnable() {
Debug.Log ("Enable");
}
void OnDisable() {
Debug.Log ("Disable");
}
// Use this for initialization
void Start () {
Debug.Log("Start");
Debug.Log("Broadcast 1 send time: " + Time.frameCount);
this.SendMessage("messageTest", 1);
}
// Update is called once per frame
void Update () {
Debug.Log("Update time: " + Time.frameCount);
Debug.Log("Broadcast 2 send time: " + Time.frameCount);
this.SendMessage("messageTest", 2);
}
private void messageTest(int id)
{
Debug.Log("Broadcast " + id + " receive time: " + Time.frameCount);
}
}
Result (in order of execution):
Broadcast 1 send time: 1
Broadcast 1 receive time: 1
Update time: 1
Broadcast 2 send time: 1
Broadcast 2 receive time: 1
Update time: 2
...
Your answer
Follow this Question
Related Questions
BroadcastMessage Null Reference Exception Problem 1 Answer
Broadcast message 1 Answer
2D Animation does not start 1 Answer
"Send Message Has No Receiver" On Button Click 1 Answer
Add only ONE component at runtime? 2 Answers