Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption - Help Needed Urgently
Having an issue which has me pretty frustrated, have been through code numerous times and can see no mistakes at all and matches the code given perfectly as far as I can tell, however while defenders launch projectiles I am getting a weird behaviour.
The projectiles are not becoming a child to the Projectiles game object as they should, and I am getting the error message in the console saying "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption"
The code looks spot on as far as I can tell, and I am dragging prefabs to prefabs so cannot work this out at all, below is image of the error warning
Answer by Refzlund · May 19, 2017 at 08:14 AM
Had a similar problem. It's important that projectileParent is defined before the Fire() is called.
Script defining parent
Start()
{
// Defining the fireprojectiles parent
GetComponent<FireScript>().projectileParent = this.transform;
}
Script calling fire
Start()
{
// Calling fire at start for test purposes
GetComponent<Fire>().Fire();
}
The problem is that it may run the script calling fire first since all scripts with Start() doesn't run in a specific order. Therefore the solution (to my problem atleast) would be:
Script defining parent
Awake()
{
// Defining the fireprojectiles parent
GetComponent<FireScript>().projectileParent = this.transform;
}
Script calling fire
Start()
{
// Calling fire at start for test purposes
GetComponent<Fire>().Fire();
}
I know it's a half year ago this question was posted, but I bet someone else will screw up as bad as I did.
Your answer
Follow this Question
Related Questions
Parenting a GameObject with script not working (C#) 0 Answers
how do i get my player get sucked into a gameobject 2 Answers
how can i get the gameobject socket by XRsocket interactor 0 Answers
Instatiate a gameobject/prefab on the parent's current location if the child is destroyed. 1 Answer
UI text not showing in my scrollView 0 Answers