I am a big fan of Unity's Prefab and GameObject model. Basically how it works is that you can assign GameObjects or Prefabs (which are GameObjects that are not in the world, but fully prepared to be spawned whenever needed, such as bullets) to properties on scripts, and scripts can then use those properties just like (in theory) you could do that with ObjectValue instances.
For example - Here is how I would want to create a turret in Roblox:
Create a
Turretmodel with aShootscriptAdd an
ObjectValuecalledBullettoTurretPrepare the
Bulletmodel, put it inServerStorage, and assign to theTurret'sBulletObjectValueIn the
Shootscript, use whateverBulletmodel is referenced in thatObjectValuefor shooting
This has a range of advantages. Most importantly: One script can support any amount of bullets without requiring any changes to the code.
However, in reality, when I clone my turret, I have to re-assign all ObjectValues manually. That is especially annoying when there are many different ObjectValues on the same object.
What's worse is that ObjectValue cannot be used at all with any object that is spawned/created by script (because it would immediately be invalidated). For example, right now, I am working on a simple pick-up system where tens of pick-ups are randomly spawned on the map, but different pick-up "templates" are supposed to contain different items/objects, with different scripts/effects.
I want to avoid hard-coding of the referenced objects at any price. I can imagine several work-arounds, including:
Use a
ModuleScriptinstead ofObjectValuethat returns the hard-coded object reference of choice. Any script references to the object could just be changed fromX.Valuetorequire(X). Changing the referenced object would require code changes (which is bad), but due to the simplicity of the script, it would not be too error-prone.Use a
StringValuewhere we'd reference an object by it's full name in theDataModelhierarchy. In this case, any script references would require an extra function that decodes and looks up objects by full path in the hierarchy (since the path of an object should contain full names in dot notation, such asServerStorage.NPCs.WeakHobo). Changing object references would not require code changes, so that's a plus.There is somehow a way to successfully clone
ObjectValues???
My question is two-fold:
Why can
ObjectValuesValueproperty not be cloned (assuming a shallow clone, just keep the reference to the original; should not be too hard)? and:Is there a better option here?
PS: (Not sure if anyone cares, but...) Unity is rather smart about this. When copying, all Prefab and non-local GameObject references are kept as-is. However, if you reference an object that is a descendant of the object being copied, it will update the reference to match the newly instantiated copy of the descendant instead.

3 comments
Sorry, only recently came back to this stuff. So yeah, I just came across this very problem: You cannot copy+paste ObjectValues, which is a bit of a b*tch.... I wonder what a good work-around is to easily copy a configuration containing ObjectValues then?
It has been filed as a bug here: https://devforum.roblox.com/t/value-property-of-objectvalue-not-preserved-when-copying-and-pasting/87389
About the original issue: Yeah, it must have been fixed. I found, a lot of things have improved since then, so that's good news!