Skip to content

Add runtime API support for updating characterGO and related offsets in CharacterEntity.cs#29

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-28
Draft

Add runtime API support for updating characterGO and related offsets in CharacterEntity.cs#29
Copilot wants to merge 4 commits intomainfrom
copilot/fix-28

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 16, 2025

This PR adds runtime API support for dynamically updating character properties that were previously only modifiable during initialization. The CharacterEntity class now exposes public methods to update characterGO, characterObjectOffset, characterObjectRotation, and characterLabelOffset at runtime.

Problem

Previously, these critical character properties could only be set during entity initialization via the Initialize() method, making dynamic character management difficult:

// Before: Only possible during initialization
character.Initialize(id, prefab, offset, rotation, labelOffset);

// Runtime updates were impossible - properties had private setters
// character.characterObjectOffset = newOffset; // ❌ Compilation error

Solution

Added five new public methods to enable runtime updates:

// New runtime APIs
bool SetCharacterGO(GameObject newCharacterGO, bool synchronize = true);
GameObject GetCharacterGO();
bool SetCharacterObjectOffset(Vector3 newOffset, bool synchronize = true);
bool SetCharacterObjectRotation(Quaternion newRotation, bool synchronize = true);
bool SetCharacterLabelOffset(Vector3 newOffset, bool synchronize = true);

Usage Examples

Dynamic character model switching:

GameObject newModel = Resources.Load<GameObject>("AlternativeCharacter");
character.SetCharacterGO(newModel);

Runtime position adjustments:

// Adjust character height dynamically
character.SetCharacterObjectOffset(new Vector3(0, 1.5f, 0));

// Rotate character to face a target
character.SetCharacterObjectRotation(Quaternion.LookRotation(targetDirection));

// Move label based on character state
character.SetCharacterLabelOffset(new Vector3(0, isJumping ? 3f : 2f, 0));

Implementation Details

  • Full GameObject replacement: SetCharacterGO() handles mesh updates, bounds recalculation, and cleanup
  • Live transform updates: Position and rotation changes immediately apply to GameObjects
  • Label positioning: Automatically finds and updates TextMeshProUGUI components
  • Error handling: Proper validation with meaningful error messages
  • Synchronization ready: Optional sync parameter for future multiplayer support
  • Backward compatibility: All existing code continues to work unchanged

Testing & Documentation

  • Comprehensive test suite covering all APIs and edge cases
  • Interactive demonstration script for runtime testing
  • Complete API documentation with usage examples
  • Validation of backward compatibility with existing tests

This enables dynamic character customization, procedural generation, animation-driven updates, and improved testing workflows while maintaining full backward compatibility.

Fixes #28.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 16, 2025

@dyfios 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 3 commits August 16, 2025 18:47
Co-authored-by: dyfios <16926525+dyfios@users.noreply.github.com>
Co-authored-by: dyfios <16926525+dyfios@users.noreply.github.com>
Co-authored-by: dyfios <16926525+dyfios@users.noreply.github.com>
Copilot AI changed the title [WIP] Add API support for updating characterGO and related offsets at runtime in CharacterEntity.cs Add runtime API support for updating characterGO and related offsets in CharacterEntity.cs Aug 16, 2025
Copilot AI requested a review from dyfios August 16, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API support for updating characterGO and related offsets at runtime in CharacterEntity.cs

2 participants