Search Unity

Object and prefab are different

Discussion in 'Prefabs' started by edufissure, Feb 5, 2019.

  1. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    I have an object which i want to use as fireball ( similar laser in Star Wars, a cylinder with x rotation of 90)...

    So in scene seems right:

    But when i use it as prefab ( drag from scene to hierachy, it turns vertical although the x,y,z values seem the correct ones:



    So when i use this as prefab of fireball, the fireballs seem like candles as you can see above, the cylinder is vertical..

    Any ideas ??

    To shoot i use, so the prefab i select in editor, but the main problem is that scene and prefab objects are not the same...

    1. if (Physics.SphereCast(ray, 0.75f, out hit))
    2. {
    3. GameObject hitObject = hit.transform.gameObject;
    4. //Player is detected in the same way as the target object in RayShooter
    5. if (hitObject.GetComponent<PlayerCharacterManager>() && Time.time > nextFire) {
    6. //Same null GameObject logic as SceneController ( if no fireball in scene, create new one instantiate)
    7. Debug.Log("Torret laser Hit en: " + hitObject.name + "a una distancia de " + hit.distance);
    8. nextFire = Time.time + fireRate;
    9. //Like SceneController instantiate method
    10. //_animator.SetBool("ElyEnemyShoots", true);
    11. soundSource.PlayOneShot(shootGun);
    12. _fireball = Instantiate(fireballPrefab) as GameObject;
    13. Debug.Log("Torret Laser: Ha disparado" + hit.distance);
    14. //Place the fireball in front of the enemy and point in the same direction
    15. //_fireball.transform.position = transform.TransformPoint(Vector3.forward * 1.5f);
    16. _fireball.transform.position = gunEnd.transform.position;
    17. //_fireball.transform.rotation = Quaternion.Euler(90, transform.rotation.y, transform.rotation.z);
    18. //_fireball.transform.rotation = temp; // and save the modified value
    19. //Vector3 rotationFireball = new Vector3(90);
    20. _fireball.transform.rotation = transform.rotation;
    21. //_fireball.transform.rotation.x = 90;
    22. Destroy(_fireball, 6.0f);
    23. }
    24. } //If physics.spherecast
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Position and rotation of the root transform of a Prefab are default overrides and are not applied. Open the Prefab in Prefab Mode to change the rotation of the Prefab itself.
     
  3. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    It didnt work.. what seems strange is here in the image:

    upload_2019-2-5_17-3-10.png

    The prefab FireballTorretLaserTurn....when you drag to scene it apperas correct as you can see, but stills in the prefab inspector appears vertical. And when created a instance by code scriptitng as shown in first post, the bullets appear vertical.... Im in 2017.4.19f so the prefab mode think it doesnt exist... just in case in the object in the scene i ve pressed apply but didnt work... perhpas a bug ?

    upload_2019-2-5_17-7-6.png
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Can you post screenshots of what the cylinder looks like in the Inspector and Scene view in Prefab Mode?
     
  5. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    As i ve read, or i understood the second image in the first post, is ... your changes to the object are applied to the prefab if you click on the apply button just down the layers and tags... im using unity 2017.4.19

    Also the rest of the properties are applied ( ex: scale or material color....)

    You can see in the first image the "numbers" are applied the right way: scale and rotation, the numbers that appear are the same.... All is applied to prefab except the rotation....

    Thanks
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Oh you're not on 2018.3. Right.

    Then select the Prefab Asset and edit the values in the Inspector there, not in an instance of it.

    No, as I wrote in my first reply:
    Position and rotation of the root transform of a Prefab are default overrides and are not applied.
     
  7. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    Thanks for your help, but in third post, first image you can see that the values are modified in the prefab but seems that rotation fails, other values get saved, but not rotation....
     
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Yes, that's what I keep saying. This is by design. It's intended behavior.

    To modify the position and/or rotation select the Prefab Asset in the Project window and modify that, not the Prefab instance in the Hierarchy window.
     
  9. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    Sorry for my bad english, but i have changed in both cases.. i have edited many prefabs and other parts like scale...but the problem is the rotation....