• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Stavros-Dimou · Feb 26, 2017 at 06:55 AM · transformprefabposition

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.

Comment
Add comment · Show 11
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sameel · Feb 26, 2017 at 07:42 AM 0
Share

Hi, Do you have any script attached to that prefab ?

avatar image Stavros-Dimou sameel · Feb 26, 2017 at 07:45 AM 0
Share

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();
     }
 }
avatar image alexander9727 Stavros-Dimou · Feb 26, 2017 at 08:31 AM 0
Share

Is the animation clip you are using the same for all the other prefabs as well?

avatar image sameel · Feb 26, 2017 at 07:54 AM 0
Share

Can you try with the script disabled, and see if it changes the position again ?

avatar image Stavros-Dimou sameel · Feb 26, 2017 at 08:01 AM 0
Share

Sure thing. It moves to that direction with the script disabled too. :/

avatar image sameel Stavros-Dimou · Feb 26, 2017 at 08:29 AM 0
Share

is it a child of some GameObject ?

Show more comments
avatar image sameel · Feb 26, 2017 at 03:51 PM 0
Share

do you have any animation or animator component on it ? if yes, try removing that too.

avatar image Stavros-Dimou sameel · Feb 27, 2017 at 07:36 AM 0
Share

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 ?

avatar image sameel Stavros-Dimou · Feb 27, 2017 at 08:11 AM 0
Share

From the animator component try turnning on the "Apply Root $$anonymous$$otion" option.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

87 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dragging prefab into hierarchy reset position now? 0 Answers

Checking Position 1 Answer

Why can't I instantiate an object that is +5 in the x and z axis? 1 Answer

How can I translate my prefab on Instantiate? 1 Answer

transform getting altered by changing prefab settings 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges