Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Painless conversion from MonoBehaviour to ScriptableObject?

Discussion in 'Editor & General Support' started by SalvoSoftware, Sep 30, 2021.

  1. SalvoSoftware

    SalvoSoftware

    Joined:
    Feb 4, 2013
    Posts:
    9
    I've made a few scripts to represent a Weapon and an Ability.
    I didn't know about ScriptableObjects so I created a WeaponContainer and a AbilityContainer MonoBehaviour which I load from Resources folder depending on the weaponId is saved on persistence.

    It works quite well, but it doesn't seems to be the best way to do stuff, also every time I need to reference any of these I need to navigate into the project folders and drag/drop the prefab into the inspector, and this is getting frustrating! :confused: When I discovered ScriptableObjects I wished I could convert the two MonoBehaviours to ScriptableObjects, but I've already referenced these MonoBehavious in many scenes of the game so it would mean an intense work of writing down every single reference to restore, and every value of the weapons and of the abilities, otherwise I'll loose all the data...

    Have any of you been in a similar situation? Do you know if there's any tag that would let me choose the desired prefab in the inspector without doing drag and drop? Or maybe there's a magic tool that does this work for me :p
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,955
    Yuck... I feel for you. I've been in this exact situation several times, but your desire to switch to SOs is legitimate.

    In the end I bit the bullet and used it as an excuse to refactor all the little tiny things that had been bugging me before, and basically rewrote everything using ScriptableObjects.

    But I did it system by system, not all-at-once. And in fact in one game I stood up a separate system alongside the Prefab-based system and kept both of them alive. Someday I might tear down the Prefabs and make equivalent SOs, but... maybe not!

    ALSO: don't even consider doing this without proper source control to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  3. SalvoSoftware

    SalvoSoftware

    Joined:
    Feb 4, 2013
    Posts:
    9
    Wow this is great... I use git all the time in my job with Java, but I had no idea it could be used on Unity!

    My story teaches it's important to do research on technologies before starting a project, as well as analysis, not just searching for stuff in the moment you need them :D
     
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,955
    But be careful: I cannot tell you how many times I see people on here asking questions like "Should I use Prefabs or ScriptableObjects?" and getting all worried about it and then having analysis paralysis and never starting anything.

    Far more important than how you do it, it is critical that you actually GO DO it, and you have done this!

    There are an infinite number of possible engineering solutions you can create, and if you don't try any ofthem because you're unsure which to do, you're no different than that weirdo at the party who says "Oh you make games? I have a GREAT GAME IDEA!" Of course as you know, game ideas have zero value. It's the created game that has value. :)