I've got a basic test going where I spawn in a character prefab that was made as a simple UCC TPS character with no items.
I then have 3 buttons to test with being:
Part of this question is if I'm swapping between playable and AI correctly, and if so, what might be the issue with re-attaching the camera after swapping back to playable?
Spawing character based on this code:
Swapping is then done with this code:
Note that the character prefab I'm using is made from the Demo Nolan model as a simple UCC TPS character, demo item collection and no inventory items.
No items are added during spawn either.
I then have 3 buttons to test with being:
- Spawn new playable character
- delete the old character if it exists
- GameObject.Instantiate(...) the character prefab
- Enable the Opsive camera and set CameraController.Character = spawnedCharacter
- I can now play/move the character around as expected
- Change playable to AI
- Uses CharacterBuilder methods to remove Input and Add AI components
- disables opsive camera
- enables a different non-opsive scene level camera
- I can no longer control the character, the scene level camera is now active as expected
- Change AI back to playable
- Uses CharacterBuilder methods to add Input and remove AI components
- disables scene camera
- Enable the Opsive camera and set CameraController.Character = spawnedCharacter
- I can control the player again, opsive cam is active as expected, but it no longer follows the player in scene
- (Repeat) Spawn a new playable character
- this destroys the previous characters and starts things over again with the Opsive camera back to working as expected and under player control
Part of this question is if I'm swapping between playable and AI correctly, and if so, what might be the issue with re-attaching the camera after swapping back to playable?
Spawing character based on this code:
C#:
spawnedCharacter = GameObject.Instantiate(characterDefaultKits[c].CharacterPrefab);
// attach new character to Opsive camera
opsiveCamera.SetActive(true);
nonOpsiveCamera.SetActive(false);
uccCam.Character = spawnedCharacter;
Swapping is then done with this code:
C#:
private void Update()
{
if (Input.GetKeyDown(KeyCode.Keypad1))
{
print("Spawn Character...");
SpawnACharacter();
}
if (Input.GetKeyDown(KeyCode.Keypad2))
{
print("Convert To AI...");
ConvertPlaybleToAiAgent();
}
if (Input.GetKeyDown(KeyCode.Keypad3))
{
print("Convert To Playable...");
ConvertAiAgentToPlayable();
}
}
public void ConvertPlaybleToAiAgent()
{
CharacterBuilder.AddAIAgent(this.spawnedCharacter);
CharacterBuilder.RemoveUnityInput(this.spawnedCharacter);
Opsive.UltimateCharacterController.Camera.CameraController uccCam = opsiveCamera.GetComponent<Opsive.UltimateCharacterController.Camera.CameraController>();
opsiveCamera.SetActive(false);
nonOpsiveCamera.SetActive(true);
//uccCam.Character = null;
}
public void ConvertAiAgentToPlayable()
{
CharacterBuilder.RemoveAIAgent(this.spawnedCharacter);
CharacterBuilder.AddUnityInput(this.spawnedCharacter);
Opsive.UltimateCharacterController.Camera.CameraController uccCam = opsiveCamera.GetComponent<Opsive.UltimateCharacterController.Camera.CameraController>();
opsiveCamera.SetActive(true);
nonOpsiveCamera.SetActive(false);
uccCam.Character = this.spawnedCharacter;
}
Note that the character prefab I'm using is made from the Demo Nolan model as a simple UCC TPS character, demo item collection and no inventory items.
No items are added during spawn either.
Last edited: