#Line 22, motor component is missing
1 messages · Page 1 of 1 (latest)
It looks like a null referance, something is missing a referance,
these is a seperate one for that
You can enforce the component using the RequiredComponent tag
It is not attached to the game object
im sorry this is my first unity game idk anything
No worries
it is it is
both codes are
where do i use RequiredComponent
It will wan't to add it to the top of your code like with this
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/RequireComponent.html
oh alr alr
im pretty sure i initialised both
Can you show the code for those?
Sorry, my bad
The problem is in the input manager line 22
im sorry but what is that?
ok one se
Ok, player input is a MonoBehaviour
You cannot call a new one
You need to add it to the GO
And call the GetComponent
i see
wait like this?
using UnityEngine;
using UnityEngine.InputSystem;
public class NewMonoBehaviourScript : MonoBehaviour
{
private PlayerInput playerinput;
private PlayerInput.OnFootActions OnFoot;
private PlayerMotor motor;
// Awake is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
playerinput = new PlayerInput();
OnFoot = playerinput.OnFoot;
// Ensure the PlayerMotor is attached to the GameObject
motor = GetComponent<PlayerMotor>();
if (motor == null)
{
Debug.LogError("PlayerMotor is not attached to the GameObject!");
}
}
// FixedUpdate is called once per frame
void FixedUpdate()
{
// Ensure motor and OnFoot.Movement are not null before processing
if (motor == null)
{
Debug.LogError("Motor is null, skipping movement processing.");
return;
}
if (OnFoot == null || OnFoot.Movement == null)
{
Debug.LogError("OnFoot or Movement action is null, skipping input processing.");
return;
}
// Process the movement input
Vector2 movementInput = OnFoot.Movement.ReadValue<Vector2>();
motor.ProcessMove(movementInput);
}
private void OnEnable()
{
if (OnFoot != null)
{
OnFoot.Enable();
}
else
{
Debug.LogError("OnFoot input is null in OnEnable.");
}
}
private void OnDisable()
{
if (OnFoot != null)
{
OnFoot.Disable();
}
else
{
Debug.LogError("OnFoot input is null in OnDisable.");
}
}
}
Nope, like you did with the PlayerMotor
oh alr
one sec
this?
using UnityEngine;
using UnityEngine.InputSystem;
public class NewMonoBehaviourScript : MonoBehaviour
{
private PlayerInput playerinput;
private PlayerInput.OnFootActions OnFoot;
private PlayerMotor motor;
// Awake is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
playerinput = new PlayerInput();
OnFoot = playerinput.OnFoot;
// Ensure the PlayerMotor is attached to the GameObject
motor = GetComponent<PlayerMotor>();
if (motor == null)
{
Debug.LogError("PlayerMotor is not attached to the GameObject!");
}
}
// FixedUpdate is called once per frame
void FixedUpdate()
{
// Check if motor and OnFoot.Movement are not null before processing
if (motor == null)
{
Debug.LogError("Motor is null, skipping movement processing.");
return;
}
if (OnFoot == null || OnFoot.Movement == null)
{
Debug.LogError("OnFoot or Movement action is null, skipping input processing.");
return;
}
// Get the movement input and process it
Vector2 movementInput = OnFoot.Movement.ReadValue<Vector2>();
if (movementInput == null)
{
Debug.LogError("Movement input is null or invalid.");
return;
}
motor.ProcessMove(movementInput);
}
private void OnEnable()
{
if (OnFoot != null)
{
OnFoot.Enable();
}
else
{
Debug.LogError("OnFoot input is null in OnEnable.");
}
}
private void OnDisable()
{
if (OnFoot != null)
{
OnFoot.Disable();
}
else
{
Debug.LogError("OnFoot input is null in OnDisable.");
}
}
}
Change it to GetComponent<PlayerInput>()
And add the component to the GO
like this?
You can get rid of the new
Just GetComponent
Ad add it to the GameObject afterwards
Looks like you need to configure your IDE
Also that thing isn't going to be a component regardless
So this is all wrong
Nah that's not a component it's their generated class from the input actions asset (just very unfortunately and confusingly named)
Very confusing indeed. So no need to do a GetComponent
But it seems the RequiredComponent tag is needed
@tropic vine worth read the documentation
i have
@opal folio the example from de documentation call the get component
@tropic vine try adding the required component tag and call the get component and see if it works
omg thankks so much
it works