playMaker

Author Topic: Save/Load - Make MainCamera persist and not duplicate  (Read 1451 times)

dubnug

  • Playmaker Newbie
  • *
  • Posts: 22
    • View Profile
Save/Load - Make MainCamera persist and not duplicate
« on: January 23, 2014, 03:57:44 AM »
Hey guys,

I'm working on getting saving and loading working in my game (using whydoidoit's Serializer, but that may not matter in this case), and I'm running into a problem.

I can't have the camera duplicate itself when a saved level is loaded, or at any instance have two of the same camera in scene. To combat this, I made my camera a prefab [and removed it from the scene] and have a Manager game object with an FSM on it to check if it exists in scene - if it doesn't exist, it'll create one. If it does exist, it'll destroy itself.

My problem is that other objects reference scripts on my camera object (that do need to be on the camera) and I'm getting Null References on said objects that are trying to reference the camera components at runtime.

Is there a way to easily delay OnStart calls from those other game objects so I can avoid this issue? I'd like to avoid Coroutines if possible.

OR

Is there a good way to make sure the 'check if exists then create/destroy' FSM runs first thing? I've heard about creating sort of "empty" scenes to load into first before the scene in question, but I don't know much about that or if it pertains.

I really look forward to any advice! I'd be very grateful.
« Last Edit: January 23, 2014, 04:02:41 AM by dubnug »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15459
  • Official Playmaker Support
    • View Profile
Re: Save/Load - Make MainCamera persist and not duplicate
« Reply #1 on: January 24, 2014, 06:20:19 AM »
Hi,

 no you can't really assure the order of execution so well.

 I would suggest you find a way to get to the reference of the camera that is done at runtime not within the editor ( drag and drop).

typically, by sending a event ( broadcast) from the camer itself, OR saving the camera in a global variable and have the camera manager always setting this global and you detect you have to create an instance. This way all scenes and during playback this will always work.

bye,

 Jean