Changing InterpolateOptions within Script

Currently, I have a script that adds the component through the script. But im confused on how I set the Interpolate type through a script.

(); physicalRightController.AddComponent<PhotonTransformView>(); physicalRightController.GetComponent<PhotonTransformView>().m_PositionModel.SynchronizeEnabled = true; physicalRightController.GetComponent<PhotonTransformView>().m_PositionModel.InterpolateOption = InterpolateOptions.Lerp;">

This is currently how I thought it would work.

Comments

  • Jakeco19
    Jakeco19
    edited August 2018
    The Upper Script is inside this IF statement.

    if (physicalLeftSetup == false && physicalLeftController != null)
    {
    Destroy(physicalLeftController.transform.Find("Hand(Clone)").gameObject.GetComponent());
    Destroy(physicalLeftController.transform.Find("CustomColliders").gameObject.GetComponent());
    Destroy(physicalLeftController.transform.Find("CustomColliders").gameObject.GetComponent());
    Destroy(physicalLeftController.transform.Find("CustomColliders").gameObject.GetComponent());

    physicalRightController.AddComponent();
    physicalRightController.AddComponent();
    physicalRightController.GetComponent().m_PositionModel.SynchronizeEnabled = true;
    physicalRightController.GetComponent().m_PositionModel.InterpolateOption = InterpolateOptions.Lerp;
    physicalLeftSetup = true;
    }
  • Hi @Jakeco19,

    you should avoid adding observed components at runtime. It hasn't been designed for such use cases, because you would have to do those changes on all clients which you would have to synchronize somehow. Therefore the recommendation still is, to set up these objects properly in the Unity Editor. If you for some reason need to start and stop synchronization, you can for example try to add a boolean value to the PhotonTransformView component which controls processing the OnPhotonSerializeView function, for example: if (!doSomething) return; or try to implement a custom OnPhotonSerializeView solution.

    Do you have a use case and can explain why you want to attach those components dynamically at runtime?