- Home /
can you make a prefab but without a model?
is it possible to create prefab that contains only script, and can be paced onto any 3d object , then this will have all the scripts. other wise its a case of insert the asset (model) then attach all the scripts to that model . create a prefab from that . but has to be done time and again .
Hello. Did you find any suggestions useful? Please post a comment or mark an answer, for future reference by other people searching this 'site.
Answer by AlucardJay · Jul 29, 2012 at 07:17 PM
Create an Empty GameObject, then you can put that to a prefab.
In Unity, GameObject > Create Empty.
However, If you want to then attach a 3D object to it, you'll have to make the Prefab the parent or child of that object.
Answer by Xicer · Jul 29, 2012 at 08:16 PM
I think you can do that by placing all the scripts on an empty gameobject. make that gameobject into a prefab, then placing the prefab onto anything that you like.
But you must be careful what scripts you place in the prefab taking into account the variables it has and names it has stored.
Answer by ScroodgeM · Jul 29, 2012 at 07:31 PM
i don't know way to easy move configured component from one object to another with saving target's configured components... but...
i found an easy way to create a preconfigured components on gameobjects. script below makes a menu with fast adding preconfigured rigidbody to object. you can use this way to add any preconfigured component. also, you can do it in runtime (just use method's content in runtime script)
also, don't forget that you can set default values for monobehaviours in script. then script will add with these default values.
using UnityEditor; using UnityEngine; using System.Collections; public class FastMenu : MonoBehaviour {
[MenuItem("UnityAnswers/Add Preconfigured Rigidbody")]
static void AddPreconfiguredRigidbody()
{
GameObject go = Selection.activeGameObject;
if (go)
{
Rigidbody rb = go.GetComponent<Rigidbody>();
if (!rb) { rb = go.AddComponent<Rigidbody>(); }
rb.mass = 100;
rb.drag = 0.5f;
rb.angularDrag = 0.5f;
rb.constraints = RigidbodyConstraints.FreezeRotation;
}
}
}