Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by Caleb_1701 · Feb 15, 2016 at 09:20 AM · prefabsprefab-instanceprefab changing at runtimeprefab connection

Instances of the same prefab behaving differently

I am currently working on a dungeon game, in which the main enemies are skeletons. I have created a prefab with all the colliders, animator, script, etc. on it, but now it is not really working. By that I mean that about 50% of the clones of the prefab work exactly as they are supposed to, but the other 50% don't move. They play the animations and can reduce player health when you're close enough, but they just stay in one place. I've never seen this happen before, and on an earlier version of my game the enemies worked perfectly fine 100% of the time. However, after running into and solving a different problem (one with similar symptoms on the enemies, but in that case due to unneeded location keyframes, which I removed), this started happening. Does anyone know what could be causing this? And (more importantly) how to fix it? Edit: I should note that the ones that do move often move backwards, sideways, or at the wrong speed. I haven't touched the script since the earlier version where it worked fine. Any ideas what the problem might be? Should I not have deleted the location keyframes in Blender? Or does it have to do with something else, like the root bone I set up (I noticed that turning "Apply Root Motion" on or off will affect whether half or none of the skeletons work correctly)? This is the script:

     using UnityEngine;
     using System.Collections;
     
     public class skeleton1_script : MonoBehaviour {
         
         public float speed;
         public float myViewAngle;
         public float attackdist;
         public int startH;
         public float damage;
     
         private int attacktime = 0;
         private CharacterController contrlr;
         private bool insight;
         private Animator anim8;
         private GameObject Player;
         private int Health;
         //private Collider myTrigger;
     
         // Use this for initialization
         void Start () {
             contrlr = GetComponent<CharacterController> ();
             anim8 = GetComponent<Animator> ();
             Player = GameObject.FindWithTag ("Player");
             Health = startH;
             //myTrigger = GetComponent<SphereCollider> ();
             //state = anim8.GetCurrentAnimatorStateInfo (1);
         }
         
         // Update is called once per frame
         void Update () {
             if (Health <= 0) {
                 return;
             }
             transform.position = new Vector3 (transform.position.x, 0, transform.position.z);
             insight = false;
             Vector3 target = new Vector3 (Player.transform.position.x, Player.transform.position.y + 1, Player.transform.position.z);
             Vector3 direction = target - transform.position;
             float angle = Vector3.Angle (direction,transform.forward);
             if (angle <= myViewAngle * .5f) {
                 RaycastHit hit;
                 if (Physics.Raycast (new Vector3(transform.position.x, transform.position.y + 1, transform.position.z), direction, out hit)) {
                     if (hit.transform.name == "Player") {
                         insight = true;
                     }
                 }        
             }
             if (insight == true) {
                 transform.LookAt(new Vector3(target.x, transform.position.y, target.z));
                 if (Vector3.Distance(transform.position, Player.transform.position) >= attackdist) {
                     anim8.SetBool("moving", true);
                     contrlr.SimpleMove(direction*speed);
                     anim8.SetBool("attacking", false);
                 }
                 else {
                     anim8.SetBool("attacking",true);
                     //if (state.normalizedTime  <= 0.166f) {
                         //myTrigger.enabled = true;
                     //}
                     //else {
                         //myTrigger.enabled = false;
                     //}
                     if (contrlr.velocity == new Vector3(0, 0, 0)) {
                         anim8.SetBool("moving", false);
                     }
                 }
             }
             else {
                 anim8.SetBool("moving", false);
                 anim8.SetBool("attacking", false);
             }
         }
         void Hurt (int amount) {
             Health -= amount;
             if (Health <= 0) {
                 contrlr.enabled = false;
                 StartCoroutine(Die());
             }
             //print ("" + Health);
         }
         void OnTriggerStay (Collider other) {
             if (insight == true) {
                 if (other.tag == "Player") {
                     if (attacktime ==0) {
                         other.SendMessage ("Hurts", damage);
                     }
                     //myTrigger.enabled = false;
                     attacktime = (attacktime + 1)%20;
                 }
             }
         }
         IEnumerator Die () {
             anim8.SetTrigger("die");
             for (int i = 0; i <= 20; i++) {
                 transform.position -= new Vector3(0, 1.5f*Time.deltaTime, 0);
                 yield return null;
             }
             gameObject.SetActive (false);
         }
     
     }
 

Comment
Add comment · Show 6
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 One-Zero · Mar 06, 2016 at 12:45 PM 0
Share

I have same problem as you are. If I add 4 prefab 2 prefab working fine. Why is it that. Did you solve your problem Caleb_1701?

avatar image Caleb_1701 One-Zero · Mar 08, 2016 at 12:43 AM 0
Share

No, I haven't solved it. I'm looking into possible solutions, but so far no success.

avatar image Caleb_1701 · May 16, 2016 at 09:43 PM 0
Share

Wow, still no answer from anyone. I guess this isn't a common problem, so not a lot of people have dealt with it.

avatar image vittu1994 · May 16, 2016 at 09:49 PM 0
Share

share the script for these skeletons

avatar image Caleb_1701 vittu1994 · May 21, 2016 at 02:05 AM 0
Share

I edited the question so the script is now there. I also pointed out some things that may or may not be relevant to solving the problem; I'm hoping they are relevant.

avatar image belamessex · May 10, 2017 at 06:48 PM 0
Share

Hey there, I'm having the same problem with my main character prefab. Her public move multiplier and public gravity multiplier are all out of wack when she instantiates, making her fall way too fast and move at half speed. However, when I click on the Instantiated prefab in the scene hierarchy, the problem goes away. This prefab had been working for months and changed pretty suddenly after 5.6. The fact that it "fixes" itself just by clicking on the prefab in hierarchy makes me think this is a bug. Does that happen for you?

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Instantiate prefab on inspector drop 0 Answers

Unity overwrites prefab values in runtime 0 Answers

Is there a way to control when lighting is generated? 0 Answers

How to safely delete a prefab? 0 Answers

Prefabs created in 2018.2.2f1 are not compatible in 2017? I'm trying to drag a prefab (in 2017) into a scene but nothing happens. 0 Answers


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