Best Practice for Script Attachment

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Galactasm

Hello,

I was wondering where the most appropriate place to attach the script is. If you have a player scene, and you import it into your level scene. Should you attach the script that controls the player in the level scene or should you attach the script in the player scene? Or does it matter?

:bust_in_silhouette: Reply From: jgodfrey

Ideally, you should try to make your scenes as autonomous as possible. That is, they should be able to function independently of other scenes. With that architecture, you can test individual scenes without the complication added by other scenes.

So, to your question specifically, I’d say the player control script should go in the Player scene. Again, ideally, that should allow you to test your player independently.

That said, like lots of things in software development, that’s a guideline, not a requirement. Just keep it in mind and stick to it when/where you can.