Hi! I'm trying to add a NetworkView component to an object at runtime. Let me give you some background first: I'm trying to share a camera's transform across the network. In order to do that, I created a prefab that contains a camera (and which doesn't own a NetworkView component), instantiate it with Network.Instantiate and add a NetworkView component at runtime. Here's the code:
Network.Instantiate(AstronautCamera, AstronautCamera.transform.position, AstronautCamera.transform.rotation, 0);
GameObject AstronautCameraInstance = GameObject.FindWithTag("AstronautCamera");
AstronautCameraInstance.AddComponent(typeof(NetworkView));
AstronautCameraInstance.networkView.observed = AstronautCameraInstance.transform;
AstronautCameraInstance.networkView.stateSynchronization = NetworkStateSynchronization.ReliableDeltaCompressed;
NetworkViewID viewID = Network.AllocateViewID();
AstronautCameraInstance.networkView.viewID = viewID;
The code above compiles and executes fine, but it's not doing what I expect it to do (i.e., when running in networked mode, the camera's transform doesn't get transferred across to the other hosts). Notice that assigning a NetworkView component to the prefab in the editor and instantiating the prefab using Network.Instantiate works fine, but I really need to do it by code.
Do you have any suggestions? Thanks in advance for your input!
--Nacho