- Home /
BroadcastMessage to Instantiated Object
I am trying to set the target of an instantiated camera to an instantiated cube. The Instantiating works fine, but for some reason it doesn't recognize the objects when I try to access them. I tried sending a broadcast message to a none instantiated object from the same function and it worked. So now I am just trying to get it to say hello and make it just respond. Here is my code for the spawn:
function spawnPlayer() {
var thePlayer = Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
var theCamera = Network.Instantiate(cameraPrefab, spawnObject.position, Quaternion.identity, 0);
Debug.Log(thePlayer);
theCamera.BroadcastMessage("new_Target", "hello");
//theCamera.BroadcastMessage("new_Target", thePlayer);
}
here is my code for the receiving object:
function newTarget(obj) {
Debug.Log(obj);
//target = obj; This is where the target would be set if it were uncommented
}
and here is my error:
BroadcastMessage new_Target has no receiver!
UnityEngine.GameObject:BroadcastMessage(String, Object)
NetworkManager:spawnPlayer() (at Assets/scripts/NetworkManager.js:55)
NetworkManager:OnServerInitialized() (at Assets/scripts/NetworkManager.js:63)
UnityEngine.Network:InitializeServer(Int32, Int32, Boolean)
NetworkManager:startServer() (at Assets/scripts/NetworkManager.js:28)
NetworkManager:OnGUI() (at Assets/scripts/NetworkManager.js:84)
Thanks in advance!
Answer by FXBaconGames · Aug 23, 2014 at 07:22 PM
I'm so stupid. I had a typo in the name of the function it should have been this:
theCamera.BroadcastMessage("newTarget", "hello");
Your answer
![](https://koobas.hobune.stream/wayback/20220613161338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PhotonNetwork.Instantiate 2 problems. 3 Answers
Passing random values to a client. 0 Answers
Can't reference network instantiated Game Object 0 Answers
Multiplayer spawning error 1 Answer
Networking Synchronize Problem. 0 Answers