C# creating a Class, having objects as member variables? I think the objects are garbage collecte
Posted
by Bryan
on Stack Overflow
See other posts from Stack Overflow
or by Bryan
Published on 2010-04-05T20:08:27Z
Indexed on
2010/04/05
20:13 UTC
Read the original article
Hit count: 288
So I have a class that has the following member variables. I have get and set functions for every piece of data in this class.
public class NavigationMesh
{
public Vector3 node;
int weight;
bool isWall;
bool hasTreasure;
public NavigationMesh(int x, int y, int z, bool setWall, bool setTreasure)
{
//default constructor
//Console.WriteLine(x + " " + y + " " + z);
node = new Vector3(x, y, z);
//Console.WriteLine(node.X + " " + node.Y + " " + node.Z);
isWall = setWall;
hasTreasure = setTreasure;
weight = 1;
}// end constructor
public float getX()
{
Console.WriteLine(node.X);
return node.X;
}
public float getY()
{
Console.WriteLine(node.Y);
return node.Y;
}
public float getZ()
{
Console.WriteLine(node.Z);
return node.Z;
}
public bool getWall()
{
return isWall;
}
public void setWall(bool item)
{
isWall = item;
}
public bool getTreasure()
{
return hasTreasure;
}
public void setTreasure(bool item)
{
hasTreasure = item;
}
public int getWeight()
{
return weight;
}
}// end class
In another class, I have a 2-Dim array that looks like this
NavigationMesh[,] mesh;
mesh = new NavigationMesh[502,502];
I use a double for loop to assign this, my problem is I cannot get the data I need out of the Vector3 node object after I create this object in my array with my "getters".
I've tried making the Vector3 a static variable, however I think it refers to the last instance of the object. How do I keep all of these object in memory? I think there being garbage collected. Any thoughts?
© Stack Overflow or respective owner