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
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.