- Home /
Prefab teleporting on play mode ?
Hello. So I have a bunch of prefabs that I created by dragging objects from the Hierarchy window to the Project window.
I noticed that the prefab objects in the Project window, on their transform component keep the data that the scene objects they were made from had. But here is something weird, at least to me, that I'm still new to Unity and learning: After I drag most prefabs to the scene, when I hit Play to enter Play mode, the prefabs stay were I left them.
But there is one particular prefab that its instance behaves differently, and instead of its instance staying were I placed it in the Scene, when I enter Play mode, it moves to the position that its prefab has in its transform. So let's say that the prefab's transform in the Inspector is at (1,24,1), and I drag it to the Scene window to create an instance, that I place at (1203,106,219). When I hit Play, the instance instead of staying at (1203,106,219) will move to (1,24,1). But that's the way only instances of this particular prefab behave. Instances of other prefabs just stay where I left them on the Scene window.
Perhaps it might be a silly or easy question, but why is that happening ? And how can I do the instances of this particular prefab behave like the instances of other prefabs ? Thanks in advance.
Yes, I do. But it doesn't touch the transform in some way.
Here it is: using UnityEngine;
public class WeaponBase : ItemBase
{
public float damagePoints;
public float reach;
public bool is$$anonymous$$ellee;
public Animator anim;
AudioSource audioPlayer;
$$anonymous$$agicEffect effect;
private void Start()
{
anim = GetComponent<Animator>();
anim.SetBool("Is$$anonymous$$oving", false);
anim.SetBool("IsAttacking", false);
}
public void Attack()
{
anim.SetBool("IsAttacking", true);
PlayRandomizedAttackSound();
}
public void Equip()
{
}
public void Play$$anonymous$$ovementAnimation(bool is$$anonymous$$oving)
{
anim.SetBool("Is$$anonymous$$oving", is$$anonymous$$oving);
}
private void PlayRandomizedAttackSound()
{
audioPlayer = GetComponent<AudioSource>();
audioPlayer.pitch = Random.Range(0.8f, 1.1f);
audioPlayer.volume = Random.Range(0.8f, 1f);
audioPlayer.Play();
}
}
Is the animation clip you are using the same for all the other prefabs as well?
Can you try with the script disabled, and see if it changes the position again ?
Sure thing. It moves to that direction with the script disabled too. :/
do you have any animation or animator component on it ? if yes, try removing that too.
Yup, that did it! Turning of the animator made the object to stay where it were. It's a weapon basically that has the attack animation it. I want to place weapons in the map, the player can find and pick them up.
Hmm, so what are you proposing me to do now ?
From the animator component try turnning on the "Apply Root $$anonymous$$otion" option.
Your answer
Follow this Question
Related Questions
GameObject position and localPosition not changing in hiearchy, only in script. 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer
Setting Position of Spawned Prefab 2 Answers
How to change a prefab position during play mode 1 Answer
How to center prefabs' children to (0, 0, 0) without changing their position relative to each other 1 Answer