So I was yesterday investing trough the ScriptableObject stuff and their benefit on memory allocation and had a doubt about a pooling system I made.
Here is how I have things setted up, I have a class that only contains general information including an array of rects that are used for an uv animation system. What I do is to create those classes once at runtime if they are needed in the scene ordering them in a dictionary, then the components that needs those classes will search trough the dictionary and if the class corrispondign with the key is found then is applied.
Now what I don’t know if is by referencing those classes I’m actually duplicating them, I only need to read the content of the classes.
Example:
This is how I get the class reference, if there isn’t one corrisponding at the given id, then create it.
static private UVRect m_uvrect;
static private Dictionary<string, UVRect> uvrect = new Dictionary<string, UVRect>();
static public UVRect GetUVRectPool (string id) {
PoolInit ();
if(uvrect.TryGetValue(id, out m_uvrect)) {
return m_uvrect;
}
else
{
m_uvrectl= new UVRect(id);
uvrect.Add(id, m_uvrect);
return m_uvrect;
}
}
Then this is how I call it from another component that requires it:
public UVRect rectRef;
rectRef = Pool.GetUVRectPool("id");
The thing I’m not sure is when I call it, am I actually referencing it or duplicating the class?