- Home /
Prefab connected to empty gameobject with scripts, empty moves, prefab doesnt?
Hey, So, I have a prefab with a particle effect, which is connected to an Empty game object with scripts.
The script is a "damage" script, which shouldn't matter, but the other script is a move script...
Looks like:
var speed = 1; function Update () {
var dir = Vector3.up;
var relative = transform.TransformDirection(dir);
transform.position += relative * -speed * Time.deltaTime;
if(transform.childCount == 0)
{
Destroy(gameObject);
}
}
What this does, is move the empty game object, but NOT the prefab that's a child to the empty game object...
Then, once the particle system runs out, it kills the empty gameobject too.
Problem is, the empty game object moves, but the child (The particle system prefab) does not..
So, question: How do you get it so that the child moves too?
Answer by boymeetsrobot · Dec 13, 2010 at 08:37 PM
Hey you need to set the transform of the prefab to the parent (empty) gameObject something like myPrefab.transform.parent = transform;
Answer by skovacs1 · Dec 13, 2010 at 09:13 PM
Your description is a bit confused:
In the Project view, you see a list of things. Pretty much everything listed here, except for folders is a "pre-fab" in a sense. The typical reference in Unity is to prefab GameObjects (indicated with the blue cube that has a piece of paper on the bottom-right).
In your Hierarchy view, the objects are instances. These instances may refer to the prefabs, but they are not the same thing. If you change a prefab, all linked instances that do not override the pre-fab will change. If you change an instance of a prefab, only that instance will change.
If I understand your situation, you should have a hierarchy like so:
Empty GameObject
Particle System Prefab Instance
Empty GameObject has the posted script attached and moves.
Empty GameObject moves, but Particle System Prefab Instance does not? If this is the case, I can only assume that your hierarchy does not look like the above unless you've got some collisions or something getting in your way.
What boymeetsrobot was referring to was that in code, if you have instantiated your prefab as Particle System Prefab Instance, it will not be the child of Empty GameObject until you tell it to be with code like:
var prefabInstance : GameObject = Instantiate(prefab, transform.position,
transform.rotation);
prefabInstance.transform.parent = transform;
Still not getting it... I'll make a video and ask in another question...
They layout is right, but the particle system IS the prefab...
And I'm not getting that script part, I'll play around with it more none-the-less...
Thanks though...
No need to go that far. Just say what you don't get and I can re-word the answer to be clearer. As I said, that script part is only if you instantiated your prefab in code.
If your hierarchy matches the one above, then are you certain that you particle prefab instance's transform is not moving and that it is not simply the particles that you see are not moving? For example, does you prefab have a ParticleAnimator?
It does have a particle animator... And that's what's happening... The prefabs transform is moving, but the particles aren't...
The problem is with the prefab and its settings if the prefab instance's transform is moving, but the particles are not. I cannot replicate or identify the exact problem from this information alone. Perhaps you could share more information about your setup? What components do you have on your prefab? What are their settings, etc.? Or stepping through the process you followed to create your broken prefab: 1.GameObject/Create Other/Particle System. 2. Changed setting X. 3.etc. I would think it may have something to do with One Shot, $$anonymous$$ax Energy and Simulate In World Space.
Your answer
Follow this Question
Related Questions
How to add a prefab containing Animation to a GameObject? 1 Answer
Adding prefab ParticleSystem to a GameObject? 0 Answers
Spawn blood particle system prefab where sword hits enemy 1 Answer
Why would the clone of a particle effect not work? 0 Answers
prefab is instantiating without a script 2 Answers