Is it possible to broadcast to all objects in scene?

Is there a way to send a broadcast to all gameobjects in a scene (without requesting all gameobjects with findObjectsOfType and send it to them individually)?

It would be good enough if there's a way to iterate through the root GameObjects in the scene, then I could just use Broadcast on these gameobjects.

It seems there isn't, so as performance isn't a real issue for me as I only use to call it when starting and ending a level, this is my solution:

public static void BroadcastAll(string fun, System.Object msg) {
    GameObject[] gos = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));
    foreach (GameObject go in gos) {
        if (go && go.transform.parent == null) {
            go.gameObject.BroadcastMessage(fun, msg, SendMessageOptions.DontRequireReceiver);
        }
    }
}

Don't know if I win anything with broadcasting to root objects instead of just use SendMessage on all gameobjects returned, but it works.

Really simple solution is to make everything in your scene a child of a single GameObject (call it world if you like). Then from this 'world' GameObject you can broadcast to all children:

gameObject.BroadcastMessage("ReceiverFunction", msg)

and place a simple script in every child you wish to receive the message:

function ReceiverFunction(msg)
{
    //do something with msg
}

There isn't a way to do this directly. The best thing I can think of is to add a tag to all root objects. You could then get them all with FindGameObjectsWithTag and broadcast to each of them.

You could always climb the tree to get the root and broadcast from there. This has worked for me:

Transform root = this.transform;
while (root.parent != null) {
	root = root.parent;
}

root.BroadcastMessage("MyMessage");

you should use events instead https://unity3d.com/learn/tutorials/modules/intermediate/scripting/events

It seems like it might be possible to use the new (5.3) Scene Manager to access all root objects and BroadcastMessage() from there.

foreach (var item in SceneManager.GetActiveScene().GetRootGameObjects()) 
{
    item.BroadcastMessage("OnLevelStart", SendMessageOptions.DontRequireReceiver);
}

Just had this issue and figured out another solution.

Attach the gameobject with whatever you wanna access and use get component to access the script. then change a public bool or float to what you want and allow the code to use these bools or floats to change things in the code:

public class Example1 : MonoBehaviour
    {
        public GameObject Player;
    
        void Update()
        {
            if (Input.GetKey(KeyCode.W))
                Player.GetComponent<Example2>().GoForawrd = true;
        {
    }
    
    public class Example2 : MonoBehaviour
    {
        public bool GoForward = false;
    
        void Update()
        {
            if (GoForward)
                transform.position.x += 0.5f;
        }
    }