May i ask why you are using Find() to find an object you just created a few lines above? You literally have the reference right there, and Find (and all its variations) are very slow and should always be prevented outside of rapid prototyping.
Not to mention that you do not use _meshData for anything at all afterwards.
As for your problem, i’m pretty sure your variables, such as stored_GUID, are static, as you are accessing them directly from the type Mesh_Data. Static variables are bound to the type itself, not the instance. Thus if you change it, you change the one and only representation of those values that is in memory.
You probably want these variables to be public (non-static) instead, and then change the variable values of the found _meshData instance (which you can get by writing NewCanvas.GetComponent…instead of using Find).
So it would be _meshData.stored_GUID = xyz.
I am accessing the script “Mesh_Data” it doesn’t work any other way.
Here is the Mesh_Data script side
public class Mesh_Data : MonoBehaviour
{
public static string stored_GUID;
public static int stored_ElementID;
public static string stored_Name;
public static string stored_AssetTag;
public static string stored_Type;
public static string stored_Layer;
public static string stored_Location;
All the fields in your Mesh_Data class contain the static modifier.
The static modifier basically means that the field will only have a singlevalue shared by all objects, instead of each component having their own individual value for the field. When using the static keyword you have to use the type instead of a specific component returned by GetComponent to access the fields.
So to get rid of the error you just need to remove the static keyword from all the Mesh_Data fields. Each component would then have their own Mesh_Data values, which I think is what you want.
As i said before, and as SisusCo also stated, if something is static, then it is bound to the type, not any instance of that type. Thus only one representation of these variables exists in memory. There can only be one value for these variables. It simply does not exist more than once. So to speak, all instances share this one value. They do not have their own values.
If you remove static, you then need to reference the instance instead of the type. So instead of Mesh_Data.variableName you would access the variable through _meshData.variableName. So do both, not just one. Change it to non-static and use the instance reference. This should fix your error.
Honestly tho, you should definitely look into the basics of object oriented programming, since you have a major misunderstanding / knowledge gap rhere. After you understand how objects work, static (and why your approach does not work) should become more clear to you as well.
Edit: Also please refrain from multi-posting as it gets messy really quickly. There is an edit function you can use to your hearts content, so you dont need to post 4 times in a row.
Removing the static modifiers should be the right solution here, so if you’re still seeing errors after removing them the problem should lie somewhere else.
But I am doing this same thing with another set of data and it works. Could it be working because I attach the script to the object after the object is instantiated?
What the…
Sorry for not only solving your problem with my very first post, but also telling you what you may look into if these kind of things trouble you - or telling you that multiposting is against the rules of the forum (or rather all forums). Sorry for all my bs, others have been very grateful for it. I will refrain from ever bothering (helping) you in the future lol.