Skip to content
Pablo Rodriguez

Housing System

Extend loot system to support building mechanics through consumable items:

Add housing functionality to existing loot structure:

  • Consumable Boolean: Mark items as usable from inventory
  • Housing Integration: Items spawn as placeable housing objects when consumed

Create placeable housing objects:

  • Static Mesh Component: Root component for visual representation
  • Struct_Loot Variable: Contains item data including appearance
  • Collision Settings: Custom collision for proper world interaction
// Housing Item Appearance Setup
OnConstruct() {
appearance_mesh = Struct_Loot.Appearance_3D;
StaticMesh.SetStaticMesh(appearance_mesh);
// Configure collision for placed objects
StaticMesh.SetCollisionEnabled(NoCollision); // Disabled until placement confirmed
}

Implement consumable item usage from inventory:

Add consumption functionality to inventory items:

// Consumable Item Button Setup
OnConsumableButtonPressed() {
if (F_Check_Inventory([Loot_Item], [1])) {
if (Loot_Item.Consumable) {
// Spawn housing item for placement
housing_item = SpawnActor(Actor_Housing, MouseWorldLocation);
housing_item.Struct_Loot = Loot_Item;
StartPlacementMode(housing_item);
}
}
}

Create intuitive mouse-controlled placement system:

Convert screen mouse position to world coordinates:

// Mouse to World Position
OnPlacementUpdate() {
mouse_world_location = ConvertMouseLocationToWorldSpace();
ground_trace_start = mouse_world_location + Vector(0,0,250);
ground_trace_end = mouse_world_location + Vector(0,0,-5000);
LineTraceForObjects(ground_trace_start, ground_trace_end, [WorldStatic]);
final_location = hit_location;
housing_item.SetActorLocation(final_location);
}

Implement grid-based placement for clean building:

// Grid Snapping Logic
SnapLocationToGrid(Location, GridSize = 50) {
snapped_x = (Location.X / GridSize).Round() * GridSize;
snapped_y = (Location.Y / GridSize).Round() * GridSize;
snapped_z = Location.Z; // Maintain ground height
return Vector(snapped_x, snapped_y, snapped_z);
}

Create smooth placement experience:

  • Timer_Housing_Item_Placement: High-frequency timer (0.01 seconds) for smooth updates
  • Looping Timer: Continuous updates during placement mode
  • Mouse Tracking: Real-time position updates following mouse movement

Implement placement controls:

// Confirm Placement
OnLeftClickDuringPlacement() {
if (IsTimerActive(Timer_Housing_Item_Placement)) {
// Final validation check
if (F_Check_Inventory([Housing_Item.Loot], [1])) {
// Confirm placement
StopPlacementTimer();
housing_item.StaticMesh.SetCollisionEnabled(QueryAndPhysics);
// Remove item from inventory
Interface_Inventory_Remove([Housing_Item.Loot], [1]);
housing_item_reference = nullptr; // Clear reference
}
}
}
// Cancel Placement
OnRightClickDuringPlacement() {
if (IsTimerActive(Timer_Housing_Item_Placement)) {
// Cancel placement
StopPlacementTimer();
DestroyActor(housing_item);
housing_item_reference = nullptr;
// Item remains in inventory
}
}

Allow recovery of placed housing items:

Use existing interaction system for housing recovery:

// Housing Item Recovery
OnHousingItemInteract(PlayerCharacter) {
// Add item back to inventory
PlayerCharacter.Interface_Inventory_Add(Struct_Loot);
// Remove from world
DestroyActor(Self);
}

This allows players to reclaim and reposition housing items as needed.

Connect housing system to existing UI:

  • Inventory Widget: Consumable button enables housing placement
  • Mouse Controls: Left click to place, right click to cancel
  • Grid Visualization: Optional grid overlay during placement mode
  • Collision Management: Proper collision states for placed vs. unplaced items
  • Performance: Efficient placement update system
  • Visual Feedback: Clear indication of placement mode vs. normal gameplay

Create simple housing items for testing:

  • DT_Loot_Cube: Basic building block
  • Consumable Setting: Enable consumable flag
  • 3D Appearance: Simple cube mesh for building

Test housing system with multiple items:

  • Multiple Cubes: Place several items to test inventory consumption
  • Grid Alignment: Verify snapping works correctly
  • Recovery System: Test pickup functionality after placement

The housing system provides creative building mechanics while maintaining integration with existing inventory and interaction systems for seamless gameplay experience.