Hello Brian.
I’m following your course in the github and must admit I encounter some trouble with some part.
I’ve read the BAhaa topic (Bahaa’s problem), have the same trouble but not the same solution unfortunatly.
The targeting Problem.
Like Bahaa, i’m unable to target an enemy.
The Console says me:
NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.Targeting.Target.Awake () (at Assets/Scripts/Combat/Targeting/Target.cs:26)
it sends me to the same’s Bahaa line:
private void Awake()
{
health.onDie.AddListener(()=>
{
OnDeath?.Invoke(this);
});
}
in the PlayerAttackingState.
Bahaa seems sold this by removing the “!” in the boolean line on the top:
public bool IsValid() => health.IsDead();
But i doesn’t change anything for me…
I’ve too an animator.GotoState errot:
Animator.GotoState: State could not be found
UnityEngine.Animator:CrossFadeInFixedTime (int,single)
RPG.States.Player.PlayerFreeLookState:Enter () (at Assets/Scripts/States/Player/PlayerFreeLookState.cs:20)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Scripts/States/StateMachine.cs:13)
RPG.States.Player.PlayerStateMachine:Start () (at Assets/Scripts/States/Player/PlayerStateMachine.cs:25)
Line 20 in Enter method in PlayerAttackingState is:
stateMachine.Animator.CrossFadeInFixedTime(FreeLookBlendTreeHash, stateMachine.CrossFadeDuration);
Line 13 in the same scrit, for SwitchState Method:
currentState?.Enter();
and line 25:
SwitchState(new PlayerFreeLookState(this));
I’ve an invalide index error too, sending to the same lines (13-20-25):
Invalid Layer Index ‘-1’
UnityEngine.Animator:CrossFadeInFixedTime (int,single)
RPG.States.Player.PlayerFreeLookState:Enter () (at Assets/Scripts/States/Player/PlayerFreeLookState.cs:20)
RPG.States.StateMachine:SwitchState (RPG.States.State) (at Assets/Scripts/States/StateMachine.cs:13)
RPG.States.Player.PlayerStateMachine:Start () (at Assets/Scripts/States/Player/PlayerStateMachine.cs:25)
I’ve the parameter ForwardSpeed doesn’t find:
Parameter ‘ForwardSpeed’ does not exist.
UnityEngine.Animator:SetFloat (string,single)
RPG.Movement.Mover:UpdateAnimator () (at Assets/Scripts/Movement/Mover.cs:75)
RPG.Movement.Mover:Update () (at Assets/Scripts/Movement/Mover.cs:35)
The last line in UpdateAnimator method in mover Script:
private void UpdateAnimator()
{
//Création de la variable de vitesse:
Vector3 velocity = navMeshAgent.velocity;
//On transforme l'informationd e vitesse gloable en locale
Vector3 localVelocity = transform.InverseTransformDirection(velocity);
//On récupère l'inforamtion locale de vitesse actuelle
float speed = localVelocity.z;
//On applique à l'Animator la valeur récupérée plus haut.
GetComponent<Animator>().SetFloat("ForwardSpeed", speed);
}
And in the Update when it calls the UpdateAnimator Method:
void Update()
{
if(isPlayer) return;
navMeshAgent.enabled = !health.IsDead();//Le navmesh est actif seulement si le joueur est vivant. sinon il est
UpdateAnimator();
}
When I approach my enemy, I’ve a problem with the Targeter script in the Targeter object in the Player Prefab:
NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.Targeting.Target.IsValid () (at Assets/Scripts/Combat/Targeting/Target.cs:22)
RPG.Combat.Targeting.Targeter.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Combat/Targeting/Targeter.cs:30)
So line of Target Script (where Bahaa remove the !):
public bool IsValid() => !health.IsDead();
And in Targeter script, the if test line in the CurrentTarget method:
private void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent(out Target target) && target.IsValid())
{
Debug.Log($"Adding Target {target}");
targets.Add(target);
target.OnDeath += RemoveTarget;
}
}
I’m a little bit lost.
I assume following Nathan chapter step by step to match with your code modification but I must have miss something unfortunatly…
I’m actually in chapter 20 in the github, and have actually errors according Fighter’s calls:
public PlayerAttackingState(PlayerStateMachine stateMachine, Attack attack) : base(stateMachine)
{
currentAttack = attack;
stateMachine.Fighter.SetCurrentAttack(attack); //Inform fighter of new attack
}
public PlayerAttackingState(PlayerStateMachine stateMachine, int attack) : base(stateMachine)
{
currentAttack = stateMachine.Fighter.GetCurrentAttack(attack);
}
I’ve a missing method in the PlayerAttackingState part 19 of the tutorial.
The name “SetLocomotionState” doesn’t exist in thae actual context.
public override void Enter()
{
if (currentAttack == null)
{
SetLocomotionState();
return;
}
and here:
public override void Tick(float deltaTime)
{
float normalizedTime = GetNormalizedTime();
if (hasCombo && normalizedTime>currentAttack.ComboAttackTime && stateMachine.InputReader.IsAttacking)
{
stateMachine.SwitchState(new PlayerAttackingState(stateMachine, currentAttack.NextComboAttack));
return;
}
if (normalizedTime > .99f)
{
SetLocomotionState();
}
Move(deltaTime);
}
I haven’t SetLocomotionState method in this script actually.
Maybe it will be implemented later in the course?
I have a doubt because i’m in chapter 21 on the GitHub and the next lesson concern the inventory.
I precise the GamePad movment or the mouse control works perfectly, so I really want to go farther
When I press the targeting button, TAB or Left Shoulder, i’ve the debug message displying in the console:
Selecting Target…
It’s the same for the Targeting or cancel targeting action lol
Thank you for reading my prose and for your help.
François