- Home /
Setting unique data on a gameobject?
Hey,
So I'm wondering if Unity gameobject's have the option to set data on them. I'm imagining a way similar to that of box2D where every object has a UserData object that can is a basic object type and can have any value set on it.
So something like myGameObject.Data.uniqueValue = 10000
It seems like this isn't possible and I'd need to give the gameobject a script component and set the value for that component directly but just wondering anyway.
Thanks
Are you talking about a unique ID? If yes, use Object.GetInstanceID()
, but is read-only.
I've ended up going with addin a script component and setting a var.
I basically needed to set this var from a controller script and was wondering if it was possible to store data on a game object without creating a script, getting the script component then setting the var. seemed long winded but if its not possible then ill just stick with my current method
Answer by whydoidoit · May 05, 2013 at 02:55 PM
There isn't a generic data parameter available on all GameObjects.
So you could use a generic script component if you want simulate that, and add it to everything you wanted to set the value on. It's lower performance that having the correctly typed value from a known specific script though. I might be able to offer more advice if you let me know what you are trying to achieve with this approach?