I have a weapon I need to parent to the camera, unfortunately I keep getting an error. I’ve tried several work arounds, but I can’t get anything to work. Basically function 1 (which also instantiates the object) calls function 2 (the one I need to parent the object) which asks if the boolean value is true. When function 1 is called, the weapon is instantiated and the boolean is changed to true so then function 2 proceeds, but unfortunately I get this error: “Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.” I know this error has something to do with the object not being instantiated when the game tries to parent it, but since this function can’t be called until the object is instantiated I’m not sure what the problem is. Src below:
Any help would be great, I know I shouldn’t need the boolean value, but when I was troubleshooting I thought I’d through it in so I could help narrow things down.
function parentM1887(){
var PlayerScript = GameObject.Find("GameScript").GetComponent(PlayerScript);
if (!PlayerScript.callWeaponBool){
Camera.main.transform.parent = PlayerScript.M1887.transform;
}
}