Unity – Universal Render Pipeline and Input System

The Unity URP (Universal Render Pipeline) contains a new Input System.

This is configured slightly differently.

Add some objects to your scene.

Apply a Rigidbody to the player object (in this case the sphere)

Go to Window > Package Manager

Open the package manager and select Unity Registry to see all of the options.

Search for Input System and then install

You might get a warning message, if you do select Restart

In the Inspector select Add Component and then add the Player Input component

Player input is not yet configured.

Click the Create Actions… button to set up default inputs

You will be asked where you want to save the input actions config file.

Make sure you save this in a logical place like an Inputs folder.

Drag the input actions file to the Component

We now have the input system attached to the player object.

If we run the program the object won’t move as we haven’t added code to do this yet.

Create a new C# script called PlayerController

Drag the script onto the player object

Double click the script to open it in the code editor

Add the InputSystem to the player controller

Create the variables for the speed of the object, the Rigidbody (to handle physics movement) and the x and y movement.

In the start method assign the Rigidbody to the rb variable.

Add the OnMove function. This functions detects user input and we then get the x and y movement and stores this as a 2D vector. We then assign the x and y values to the variables we created earlier.

Now we need to add the code to update the object.

Here we are using the Update() function. This will run once per frame. If you want it to update on a fixed time use FixedUpdate() instead.

As we are using a 3D game we need to convert the 2D vector into a 3D vector. Note here we have change the y value to be on the z (depth) axis.

We then use the AddForce function of the Rigidbody to move the object by the vector multiplied by the speed.

Save the script

Switch back to Unity

You can now see the public variables

Set the speed to a value you want

You now have a working input system

The Unity Roll A Ball tutorial works through this process in a clear project.