SerializeField
Applies to: properties
Namespace:
namespace Lenga\Engine\Attributes;
Exposes a private or protected property to the Inspector so it can be set without making the property part of the class's public API. This keeps encapsulation intact while still allowing values to be configured from the editor.
Public properties are serialized automatically. Use SerializeField only on private or protected ones.
Example
use Lenga\Engine\Attributes\SerializeField;
use Lenga\Engine\Core\Behaviour;
class PlayerController extends Behaviour
{
// Editable in the Inspector, but private to this class
#[SerializeField]
private float $speed = 5.0;
#[SerializeField]
private int $maxJumps = 2;
private int $jumpsRemaining = 0;
public function start(): void
{
$this->jumpsRemaining = $this->maxJumps;
}
public function update(): void
{
// use $this->speed...
}
}