Improbable Icon

Forums

Unity GDK - Scripting Approach for Monobehaviour Lifecycle

unity-gdk

#1

Hi all,

I’m looking for a bit of feedback on working with the Unity GDK (it’s great btw).

So, I understand that the GDK manages the monobehaviour lifecycle for me, meaning I shouldn’t enable or disable scripts myself. However, I’m used to having discrete behaviours within different scripts and I’m wondering if anyone has any advice on working within this new framework?

For example, looking at the FPS Starter Project, there are scripts on the player prefab that are managed by the GDK. FPS Driver being one. If I wanted to add a third person view to this player prefab, usually I would disable the FPS Driver and enable a third person view version of it. That way I don’t end up with a messy driver script that has both options within one monobehaviour. This is more difficult if I don’t manage the monobehaviour lifecycle though. How are others doing it?

So, yes, short and sweet… any tips?

Thanks,
Paul


#3

Hi Paul,

One thing that might work is to move your Readers & Writers into a separate component, leaving you free to enable / disable your components yourself. You’d just have to make sure that the driver is enabled before calling any methods on it.

Looking further ahead, this is something we’re looking at improving on (maybe with some kind of subscription model instead…) since it does make a few workflows difficult. Watch this space!

M


#4

Hi MattY,

Thank you for your reply and your suggestion… I don’t know why I didn’t think of it as it’s a simple solution and works quite well :slight_smile:

Cheers,
Paul


#5

This is a great community for tech conversations. It’s nice to see.:grinning: