playMaker

Author Topic: [Photon] How to set Observed Component at runtime?  (Read 2136 times)

mekjal

  • Playmaker Newbie
  • *
  • Posts: 17
[Photon] How to set Observed Component at runtime?
« on: June 02, 2018, 05:09:28 PM »
I need to set an Observed Component during runtime. 

Here's my set up:

1) I pick an object in the scene at random
2) I add ScriptToBeObserved to the object
3) I add PhotonView to the object
4) I Set Property of the PhotonView in photonView.ObservedComponents.Item with the component value of ScriptToBeObserved

When I run, I get a null reference exception:
NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.ReflectionUtils.SetMemberValue (System.Reflection.MemberInfo[] memberInfo, System.Object target, System.Object value) (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ReflectionUtils.cs:351)
HutongGames.PlayMaker.FsmProperty.SetValue () (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmProperty.cs:366)
HutongGames.PlayMaker.Actions.SetProperty.OnEnter () (at Assets/PlayMaker/Actions/UnityObject/SetProperty.cs:26)
HutongGames.PlayMaker.FsmState.ActivateActions (Int32 startIndex) (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState.OnEnter () (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state) (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2695)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState) (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm.UpdateStateChanges () (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2570)
HutongGames.PlayMaker.Fsm.UpdateState (HutongGames.PlayMaker.FsmState state) (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2711)
HutongGames.PlayMaker.Fsm.Update () (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1934)
PlayMakerFSM.Update () (at C:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:539)

Image of Adding Component of type PhotonView:
https://i.gyazo.com/b994cfaa3a18cbb27a5f215688b73bb8.png

Image of Set Property of PhotonView:
https://i.gyazo.com/1bb75e78128e0c0172a447f57bc8b58e.png

Image of the Object I'm setting to the ObservedComponents.Item:
https://gyazo.com/dbacc9098f816f7e373fe0eac3f74b33

I've searched through all the forums and haven't found any solution to this.

Any ideas?

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: [Photon] How to set Observed Component at runtime?
« Reply #1 on: July 30, 2018, 06:13:34 AM »
Hi,

 sorry for the delay.

 Did you reach a solution for this?
 
You seem to not be using PlayMaker for your data to be synched, why not using directly an FsmVariable inside an FSM? Have you checked the demoworker sample all done in PlayMaker? it features fsmvariable network synchronisation

Bye,

 Jean