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 How to load prefabs to config via ID?

Discussion in 'Prefabs' started by sensorbtf, Sep 30, 2022.

  1. sensorbtf

    sensorbtf

    Joined:
    Mar 15, 2022
    Posts:
    5
    Hi,

    I managed to bound my Unity-Project configs witwh Excel to make some sort of database. Sadly I found out that doing this with prefabs is too hard for me knownledge.

    I Wonder if someone know's how to make a system in Unity that will get use of ID's pasted from excel right into Scriptable Objects and add ealier done prefabs to SO just by interpreting ID's that I passed to tchem?

    Thanks.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,191
    I did make a straight hook for Excel / CSV data. Specifically for Excel I wrote a macro that, whenever I save, it also exports all worksheets as CSV files straight into my project. In the project I had a custom importer or rather I was monitoring the importer events and processed the CSV files, turning them into a SQLite database or just a scriptable object including code generation (but only if the table layout changed).

    From there it's just a matter of determining what each row means, typically rows have either sequentially or manually numbered IDs and those could be assigned to a specific prefab, so that the prefab scripts know which row of the data to load and use.

    You can also make it so that a prefab has an assigned ID and on import into the SO it looks up all scripts identifying prefabs by ID and picks the right one.
     
  3. sensorbtf

    sensorbtf

    Joined:
    Mar 15, 2022
    Posts:
    5
    Hi, thanks for answering! I wonder how can I assign an ID to prefab and pass it into SO while creating it? Could you please elaborate more on that?

     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,191
    You'd just need a script, ie a MonoBehaviour with a public int Id field where you enter the prefab's id. You could also name the prefabs with numbered prefixes/suffixes if you prefer.
     
  5. sensorbtf

    sensorbtf

    Joined:
    Mar 15, 2022
    Posts:
    5
    Thanks! Got it working right now.