Setting parent to null after getting references
Hello, Sorry in advance if question was asked somewhere, I honestly couldn't find the answer.
So.. Let's say that whenever player shoots, bullet prefab (bulletP) is instantiated and bulletP parent is set to be player. Inside bulletP there is a class called BulletControls. BulletControls needs to get some details about player, for example stats, in order to move with proper speed and apply proper damage when colliding with an enemy. However when bullet is child of player, whenever player is moved by directly setting its position and rotation, bullet is moved as well (which is unwanted). One of the solutions I found was to just throw bulletP for adoption after getting all it need from parent in a Start method. Another way would be to simply move player using physics (AddForce, AddTorque). Questions is: is there any performance impacts or other issues when accessing reference variable of a parent that is no longer a parent? Code snippet below:
Stats stats;
private void Start()
{
player = transform.parent.GetComponent<PlayerControls>();
if (!player)
Debug.LogError("No base ship found in
stats = player.stats;
parent.parent = null;
}
Stats is a class with a bunch of primitive variables like ints and floats.