Data structure question

Just wondering what people thought about using a scriptableObject to store a static string list of environment prop name that will be using by a terrainManger/poolingManager at run time to randomly popular tiles with props.The tiles will repeat but props should have different positions. Also worth mentioning the ScriptableObject class inherites through different bio domes eg desert/forrest/city

Thanks in advance

Do they ever change? If not just make a class full of constant string values. This is a fairly common pattern.

public class EnvironmentConstants
{
    public const string SomeValue = "A Prop";
}

Debug.Log(EnvironmentConstants.SomeValue);
2 Likes

Thanks for reply , what do you think of static lists

No they wont change , what do you think about a stic list , for convenience when pooling

I think KelsoMRK was clear in what he thinks.

He said… if the values won’t change, why not just make them constants?

You know… constant - unchanging.

No need for pooling.

Yes, static makes sense

Not static - constant. :slight_smile:

1 Like

Yes, my bad, late here, constant is static by default.

If by “static” you mean globally accessible then yes…sort of. Nothing stops you from having a private const in which case it’s scoped just like any other variable. The key difference in const is that the compiler basicaly does a “find-replace” at compile time. Also, static does not imply read only (that’s what readonly is for) whereas you cannot assign back to a const value.

I am not an expert in c#, but to me static readonly is similar to const, with the difference that as you said const is replaced by compiler whereas static readonly would be a reference still (and would work with other than strings, Int, etc…) - am I getting this right?

const works with any primitive value type and must be provided a value when declared. readonly basically gives you “one shot” to provide a value - either in the declaration or the constructor. Once a value is assigned a new one cannot be assigned.

And yes, static readonly would still refer to the value in memory but with value types you’d get a “copy” of the value back anyway.

static readonly list then :slight_smile: … really this is just a container for the pool manager that will create the GameObjects from a name.

Thanks heaps guys was really helpfull

Good lord, no. That’s the opposite of what I said :slight_smile:

Why do you want a static readonly list? Why do you want a list at all?

1 Like

lol , sorry I was jk. Im going with public const string … thanks heaps for the help really appreciate it

I legitimately spit up my pop and laughed.

2 Likes

Just a hint: whenever your structure can only be described with long run on sentences you are doing something wrong.

Simple structures are almost always the best.

Digging deeper into this it seems like I need to traverse over the data inside this ScriptableObject. I don’t really want to implement an iterable class. Maybe I need to abandon the ScriptableObject

Currently I have :
A ScriptableObject Class containing all names of the models the PoolingManager needs to create a set amount of instances from. Usually I would implement a reference to a struct array to keep it clean and efficient(C++).

Rethinking it should I just have a single instance with a list of gameObject for the PoolManager to use. Maybe Im overthinking this whole thing lol.

Also new to C# and scriptable object. Bread and butter is C++ so apologies for any excessive questions

Thanks

If you’re using a ScriptableObject to keep everything in the Editor then yeah a list of prefabs for all the models makes the most sense.

Cool ok , thanks KelsoMRk, Appreciate it