- Home /
Implementing a 2D array as a field on a ScriptableObject?
Some quick background: I'm making a 2D game, and I'm storing abilities as ScriptableObjects for ease of implementation.
I'm looking to implement a 2D array (or at least something functionally similar) as a field for my ability ScriptableObject:
I'm still new to programming, so I've mostly been looking up tutorials on various concepts that I'm unfamiliar with, and I followed this tutorial to create a script that has a 2D array of bools that would be functionally similar to what I was looking for (Panel oirign would be a seperate field that I would set manually, the bools would just determine which panels were hit): https://www.youtube.com/watch?v=uoHc-Lz9Lsc
My plan was to make a script like that (but 3x8) and attach it to each ability similar to how I attach the prefab for the FX. My thought was that if I were to do that, each ability would have its own instance of that script, and as such its own array of panels that were marked as "true" that I could reference. However, I seem to be unable to attach the script to my ScriptableObject at all. I called the class RangeResolver
(what the tutorial video used "TestScript" for) and tried setting a public RangeResolver attackRange
field in my ability ScriptableObject, but I cannot drag or select a script onto that field in the inspector.
I'm completely at a loss on how to proceed. If anyone has any ideas on how I can implement a 2D Array on a ScriptableObject as a field and how I can access the information in said array, I would be super grateful!
Answer by SolAureus · May 17, 2016 at 02:54 PM
So the solution to using the 2d bool array from the tutorial ended up being much simpler than I thought it would be. In the tutorial, the user created a TestScript.cs
that only had 1 field which called the ArrayLayout
class, which is where they defined the array of arrays that was used for their 2D array. I was attempting to call the actual TestScript
class instead of the ArrayLayout
class itself, so by calling public ArrayLayout attackRange
, it worked exactly in the manner that I had hoped, at least for the bool array. I'm going to go with a manual setting of the origin panel and the bool array as the highlighted panels as my solution.