Disable controller in game

Tempus

New member
I am wanting to disable the controller while in game. Just have the character in Idle state.
My game is in two parts. Part "A" is a layout part. While part "B" is the playing part.
Part "A" is using controls already for navigation and placement of items. This conflicts with the UCC controller.
I need to be able to place my character in the idle animation ( or T-Pose if not able to idle ) , but not affect the already in place navigation in the scene.
Then when you select "play" , it is the UCC controller.
Is there a way to disable the controller without removing it from the scene as it is part of the character?
 
Take a look at the event section of this page:

 
Thanks for that, but still locked out.
EventHandler.ExecuteEvent(m_Character, "OnEnableGameplayInput", false); - now the character is behaving as intended.
However the camera is locked up. Mouse rotation wont work and the pointer is stuck in the centre of the screen.

I noticed that the command deactivates a few of the scripts. As such, I tested by disabling all scripts on the character and then running game.
Character foot effects reactivated, but the rest did not. Camera was then working as before.
So I turned them back on and ran the game again, slowly turning them off to see which one was locking up the camera. But camera stayed locked up. So what ever is being initiated is staying even after deactivation.

EDIT: A separate problem is that when I am dragging the character around the scene (In game) , and then letting it go, it returns to its starting location.
 
Last edited:
The input event completely stops the input for the camera and character. Another option is to disable the character locomotion and handler so it does not respond to input.

EDIT: A separate problem is that when I am dragging the character around the scene (In game) , and then letting it go, it returns to its starting location.

See the API section of this page:

 
Is there a way to disable selected scripts that are on the character? Then re enable them later?
I need to deactivate UnityInput.cs and UltimateCharacterLocomotion.cs ( possibly others as well ) while I am in the Part "A" setup area.
Then reactivate for play in the Part "B" area.
I am also using "Easy Save" for my saving.
My setup is 2 scenes. A load and edit scene, and a Load and play scene. It is all working to a point, but that is because I am manually turning off the scripts and re enabling them.

Something that I noticed as well, whether or not it is a unity problem I don't know. But when I run
Opsive.Shared.Events.EventHandler.ExecuteEvent(m_Character, "OnEnableGameplayInput", false);
from the Start() or from Awake().
The UnityInput.cs is deactivated, but for some reason has no affect.
If I reactivate in the editor (while game is running), click in game scene, then deactivate manually again in editor (while game is still running), then it works.
I am using Unity 2020.3.0f1 for this project.
 
Last edited:
Instead of enable / disable components. Why don't you just restrict the character movement?


(You could also disable the character abilities during layout part)

Then when you get to the Part "B", just change the movement type, enable the abilities and you're good to go!
 
Instead of enable / disable components. Why don't you just restrict the character movement?


(You could also disable the character abilities during layout part)

Then when you get to the Part "B", just change the movement type, enable the abilities and you're good to go!
Conflict of scripts. And not the functionality I require. But I will have a look just in case.

EDIT: Stops the character as intended, but mouse is still locked up.
I need to stop the selected scripts from running at all in Part "A", then when loaded into Part "B" they can load as normal.
 
Last edited:
As Justin suggested it should be fine to just disable UltimateCharacterLocomotion and UltimateCharacterLocomotionHandler on the character during runtime. You can just get a reference to each of them and set enabled=false, e.g.

C#:
var locomotion = character.GetComponent<UltimateCharacterLocomotion>();
var handler = character.GetComponent<UltimateCharacterLocomotionHandler>();
locomotion.enabled = false;
handler.enabled = false;

Alternatively you could have those components disabled by default, then set enabled=true at some point during runtime.
 
As Justin suggested it should be fine to just disable UltimateCharacterLocomotion and UltimateCharacterLocomotionHandler on the character during runtime. You can just get a reference to each of them and set enabled=false, e.g.

C#:
var locomotion = character.GetComponent<UltimateCharacterLocomotion>();
var handler = character.GetComponent<UltimateCharacterLocomotionHandler>();
locomotion.enabled = false;
handler.enabled = false;

Alternatively you could have those components disabled by default, then set enabled=true at some point during runtime.

Thank you. Just needed to find the right thing to make it come together.
I have opted to set the selected scripts ( including the UnityInput script for the above reasons ) and then activating them when loading the "Play" section.
One of the problems was round the fact that the character is a prefab and gets instantiated when needed. So the same prefab is used in both scenes. So one scene needed to have the scripts "Stopped" or never started to begin with to avoid conflicts.

Initial tests are good and working.
Thanks to all for helping.
 
I'm glad you got this working!

Just as an idea, to simplify your workflow, you could also put the model of the character with the idle animation (without the controller at all, just the mesh) to move it around. When you change your game to phase 2, replace that model with the prefab that contains de character controller (That is, destroy the model and instanciate the character model at the position desired)
 
I'm glad you got this working!

Just as an idea, to simplify your workflow, you could also put the model of the character with the idle animation (without the controller at all, just the mesh) to move it around. When you change your game to phase 2, replace that model with the prefab that contains de character controller (That is, destroy the model and instanciate the character model at the position desired)
I did think to try that and did do some testing, but did not work out as I needed. But is all working so far..... fingers crossed.
 
Top