Let’s say I make a projectile prefab. The prefab gets instantiated in code. It has all kinds of components attached to it with all kinds of tweaked values. Now I want to have another prefab with all the same things, but I just need to change one measly value, such as speed. Is there any way to do this without just creating a duplicate of the original prefab? (which would suck because my new prefab would not get changes made to the original).
Example: Create a prefab called Bullet A, with a script with properties Speed and Damage. Now I want an additional type of bullet (prefab Bullet B) that I can fire, to be just like Bullet A, but with just Damage changed. AND I want it so if I change Speed in Bullet A, that change will also appear in Bullet B because Bullet B does not explicitly overwrite Speed.
when you instantiate the prefab assign it to a variable and then you can easily access values in its components.
for example in c#:
GameObject theInstatiatedObject = (GameObject)Instantiate(thePrefab);
NameOfScriptAttachedToPrefab nameOfScriptAttachedToPrefab = theInstatiatedObject.GetComponent<NameOfScriptAttachedToPrefab>();
nameOfScriptAttachedToPrefab.ValueYouWantToChange = 1.0f;
There is a very simple and accessible manner to do this which is based in object oriented programming.
Basically you create a base class 'projectile' and then you create all your subclassess which derive from projectile, for example 'bullet', 'rocket', 'cannonball', etc.
Each of those will expose their specific variables and functions, or will override the 'virtual' or 'protected' methods declared in the base class,
with particular attention to PUBLIC VALUES
for example, you can assign BULLET to two different prefabs, and change the public variable
CALIBER and DAMAGERANGE to create a 5.56 or a 7.62.
Again, these attributes need not set at runtime, but you can very intelligently make them exposed with public variables in your code. You set them in a prefab and voila. Thanks to inheritance you can even make a 5.56 gun fire a 7.62 thanks to inheritance.
I’m confused what your asking. You seem to contradict yourself. You want a prefab of a prefab… So why not create a projectile prefab, then create an instance , and place that instance into another prefab…
If that’s what your asking yes it can be done.
for instance:
Arrow- Damage 25, Speed 60-
Bullet- Damage 50 Speed- 100-
The script you apply to the prefab will be added at it’s default values, for each projectile you will have to tweak it manually but once you save the “tweaked” instance in prefab form, it has inherited everything the first instance had, and saves your changes along with it.
This may not be exactly what you had in mind, but it achieves exactly the result you desire:
http://cardboardkeep.com/dev-blog-inheritance-in-unity-3d/