NullReferenceException on trying to get the parent object

In the subobject script, when trying to get the parent object, an error is output:

NullReferenceException: Object reference not set to an instance of an object
PlBCC.Update () (at Assets/Scripts/PlBCC.cs:62)

Test code:

    private GameObject player;

    private void Start()
    {
        player = gameObject;
    }
    private void Update()
    {
        Debug.Log(player.name);
        player = player.transform.parent.GetComponent<PlayerControl>().getGameObject();
    }

The parent object contains an another script that just sets the default params of the Player object

There is also an object on the scene that assigns a reference to the Player object in the GameObject Player variable

Hello hello,
I would formulate it that way.

GameObject player;
// [...] not using player = player.transform, since you are probing the current GO
player = GetComponentInParent<PlayerControl>().gameObject;

What you are doing is recursively searching for a parent, which eventually fails. (since you set player = player.[components].gameObject on update. Every frames, it will reassign player to the parent gameObject and find its parent. Let’s say it’s 5 childs deep, in the 5th frame (1 sec) it will be at the root of your hierarchy, thus returning null for parent.
if you need to go deeper, there is a method GetComponentsInParent() that will return an array of T

Oh, sorry. This is incorrect example. But I tried to use GetComponentsInParent:

    private void Start()
    {
        player = gameObject;
    }
    private void Update()
    {
        Debug.Log(player.name);
        player.gameObject.GetComponentInParent<PlC>().testCode();
    }

But this is also unsuccessful, error is still the same

Your present code does look better, even if, fyi, I’m not sure you need the add .gameobject after player: it is already a gameObject.
Now to diagnose I usually try to surround it with

if(transform.parent != null)
{
// your code
}

Just to check if the NullReference comes from parenting issues. What does the Debug.Log returns?

Update:

        if (transform.parent != null)
        {
            Debug.Log(player.name);
            transform.GetComponentInParent<PlayerControl>().setSurfaceCollisionStatus(); //64th code line
        }

Debug:
NullReferenceException: Object reference not set to an instance of an object
PlBCC.Update () (at Assets/Scripts/PlBCC.cs:64)

The problem is that Unity defines the object as null when trying to refer to it if it is already in use somewhere (in some other script, the object already has a link).
In my case, in one of the scripts there was already a link to the Player object of the scene, and, when I tried to call something, this object displayed a null error, because in another script there was a link to the Player object.

DECISION:
In my script, I used get / set to get and set parameters. From ScriptB, I tried to call the Player object (which was involved in ScriptA) in the ScriptA method. So, instead of calling the set method in ScriptA in UpdateB (ScriptA) in ScriptA, I just made the get method in ScriptA and put its call into the Update() method

That’s something I didn’t know. I usually use get methods like you did and it never happened to me. Thanks for teaching me something tonight, and glad you found your error.

That’s not even true, or I understood you wrong.
ScriptA - public GameObject serialized with ‘dummy object’
ScriptB also has a public GameObject and also references to the same GameObject ‘dummy object’. No problem there. It’s not magically null.

Your problem is the component you’re trying to get… in this case PlayerControl does not exist in any of the parent.

GameObject (A) PlayerControl
GameObject (B) which is Child of GameObject (A) and has the ‘PlBCC’ component attached
Then it would work to use GetComponentInParent<T>.

You need to make sure that the component you’re trying to get is actually on a parent in your hierarchy.