#null self on character controller

10 messages · Page 1 of 1 (latest)

hazy haven
#

how is it possible for self to be null when it's attached to a node?? Plugin is character controller

I tried inheriting from the charactercontroller3d class to make my own controller for my character but _direction_base_node keeps returning null and the program will not run

    _direction_base_node = self
    _abilities = _load_nodes(abilities_path)
    _default_height = collision.shape.height
    _connect_signals()
    _start_variables()```
sage mantle
#

Can you share more of the script?:

Can you show where _direction_base_node is initialized?

Can you show the script you're working with (show the top where it extends CharacterController3D) and show the object it is attached to in the inspector?

hazy haven
#

the top looks like this (with comments). three dots (...) means there is other code inbetween

class_name CharacterController3D

## Main class of the addon, contains abilities array for character movements.

## Emitted when the character controller performs a step, called at the end of 
## the [b]move()[/b] 
## function when a move accumulator for a step has ended.
signal stepped

...

var _direction_base_node : Node3D

...
func setup():
    _direction_base_node = self
    _abilities = _load_nodes(abilities_path)
    _default_height = collision.shape.height
    _connect_signals()
    _start_variables()

## Moves the character controller.
## parameters are inputs that are sent to be handled by all abilities.
func move(_delta: float, input_axis := Vector2.ZERO, input_jump := false, input_crouch := false, input_sprint := false, input_swim_down := false, input_swim_up := false) -> void:
    var direction = _direction_input(input_axis, input_swim_down, input_swim_up, _direction_base_node)
    if not swim_ability.is_floating():
        _check_landed()
    if not jump_ability.is_actived() and not is_fly_mode() and not is_submerged() and not is_floating():
        velocity.y -= gravity * _delta

...
func _direction_input(input : Vector2, input_down : bool, input_up : bool, aim_node : Node3D) -> Vector3:
    _direction = Vector3()
    *var aim = aim_node.get_global_transform().basis*
    if input.x >= 0.5:
        _direction -= aim.z
    if input.x <= -0.5:
        _direction += aim.z
    if input.y <= -0.5:
        _direction -= aim.x
    if input.y >= 0.5:
        _direction += aim.x
    # NOTE: For free-flying and swimming movements
    if is_fly_mode() or is_floating():
        if input_up:
            _direction.y += 1.0
        elif input_down:
            _direction.y -= 1.0
    else:
        _direction.y = 0    
    return _direction.normalized()


it is called within the move function but only fails when aim_node.get_global_transform().basis is called

#

here is a screen shot of the node it's attached to including the script that extends CharacterController3D

hazy haven
sage mantle
#

Where is your aim node set? Is that the _direction_base_node from your CharacterController script?

#

I would be interested to see where aim_node is initialized and what it is set to (if it is not set in @onready or through @export).

uncut night
#

also when does setup get called

hazy haven
#

dang that was it