This might be a stupid question, but how does one go about creating a specific layout of GameObject tiles and saving it as an array, and then instantiating it at run time? I am trying to create ‘modules’ in my game composed of wall, corner, floor pieces in a specific arrangement and then instantiating them. If it was a regular variable obviously I would set the value (or drag and drop) in the inspector, but since it is a 2D array it can’t be displayed in the inspector. I don’t want to have to make a unique script for every ‘module’ which just states the layout of the tiles.
Once again, this might be a stupid question but I’m new to this and I can’t figure out how to do it!
To answer your array in the inspector issue, use a fixed array. Ie
GameObject[ ] arrayOfGameobejcts;
You’re right, the inspector won’t visualize 2D arrays by default. You can sort of work around that by making an array of a class that contains a serializable array, but from the sounds of it that would not be ideal for your use case.
If your goal is to reduce the scripting necessary to create your collections, but not necessarily the scripting required to allow you to do it, then your best bet would be to create a ScriptableObject
that contains a datatype for which you’ve created a custom PropertyDrawer
. If done correctly, then creating your collections would only require creating an instance of your ScriptableObject
and filling in the fields. Additionally, depending on your specifics, the ScriptableObject
might not be necessary at all.