Object being instantiated with a random a random rotation even when told not to?

I am instantiating an object, at the target position. When I do so, it creates it with a random rotation, for no reason at all. I have tried these things:

Setting it’s rotation to be 0 on all axis’ after it has been created, I’ve tried making a quaternion which will make the objects rotation 0 on all axis’ as the rotation value of the instantiate function, I’ve tried to edit the objects rotation in the inspector and in Blender, but nothing happens.

Code:

GameObject object = (GameObject)Instantiate(objectToMake, objectSpawn.position, Quaternion.identity);

//parentObject is a gun attached to the player.

object.transform.SetParent(parentObject.transform) //this is so the object stays on the gun at all times.

What’s wrong with this code? If you need anymore info, please ask. this is driving me insane!

Is any gameObject in the parent chain animated? it could be zero when not playing however when it is animating, rotations might be happening. the safest bet is that when you instantiate it you can have it match the rotation of the soon to be parent as it is instantiated then attach it to the parent:

  GameObject obj = Instantiate(objectToMake, objectSpawn.position, parentObject.transform.rotation) as GameObject;
     
     //parentObject is a gun attached to the player.
     
     obj.transform.parent = parentObject.transform;
     //this is so the object stays on the gun at all times.