Can you add metadata to gameobjects?

Can you add your own instance based user defined attributes or metadata to gameobject instances in the model on the fly? Meaning let’s say I have 4 cubes in the model. I want to be able to allow the user to set an attribute named profile on each of the different cubes in the model with different values

gameobject1.Profile = “W12X14”;

gameobject2.Profile = “W16X26”;

gameobject3.Profile = “W21X44”;

gameobject4.Profile = “W18X35”;

This Profile property has nothing to do with the geometry of the cube gameobject itself. It is just a metadata tag associated to an instance of a gameobject in the model.

I’d like to be able to then iterate through the objects in the model, lookup that metadata attribute and then export it to an xml/json/text file.

Anyone have any good resources or directions they can point me on this?

Simple, create a data holding script:

public class ProfileData : MonoBehaviour
    public string Profile;

Then you can require it from your objects with :

var data = cube.GetComponent<ProfileData>();

data.Profile = "W18X35";

Maybe this will work:

  • drag an object to the scene
  • attach a new script to it
  • declare public variables in this script (for storing the metadata)
  • drag this object from the scene to the project panel in order to make a prefab
  • delete the object from the scene

From now, you will be able to drag instances of the prefab to the scene and each of them will have this public variables defined in the script, don’t know if it’s what you are trying to achieve.