- Home /
Transform.parent returns only null
I am trying to find an object that is the parent of the object that instantiates a projectile:
GameObject bulletInstance;
bulletInstance = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
bulletInstance.GetComponent<bullet>().MainPlayer = transform;
This code informs the bullet of what shot it, and that works.
REALPLAYER = MainPlayer.transform.parent;
When I debug.log for MainPlayer, it returns the proper result, the weapon. But if I debug.log for RealPlayer, it returns Null. How to fix?
bulletInstance.GetComponent<bullet>().$$anonymous$$ainPlayer = transform;
this is the $$anonymous$$ainPlayer property of instantiated bullet that's ok but what is the $$anonymous$$ainPlayer here REALPLAYER = $$anonymous$$ainPlayer.transform.parent;
??? I think you have a misconception here. Cause if you want to get the parent of that very bullet instance you should call it like bulletInstance.GetComponent<bullet>().$$anonymous$$ainPlayer.parent;
. And this will work if your bullet instantiating script is attached to a weapon of a player.
Answer by xxmariofer · Apr 05, 2019 at 09:54 PM
You are accessing the transform of a transform just leave MainPlayer.parent since mailplayer iw a transform
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Instantiated object not keeping transform of the instantiator after instantiator is destroyed 2 Answers
How to instanciate transform to element of a list?,How Get Transform of a instanciated Prefap 3 Answers
problems parenting a gameObject to another upon instantiating when same name exists 1 Answer
Player Respawn Rotation Troubles 1 Answer