6.3 KiB
Building Ghost Preview Troubleshooting
FIXED: Preview Activated But Not Visible
If console shows "Preview activated" but you can't see it, this was a material/transparency issue.
Solution implemented:
- Better material creation supporting both URP and Standard RP
- Proper transparency setup for ghost materials
- Multiple material slots handled correctly
- Auto-creates debug cube if prefab has no renderer
Test the fix:
- Press Play
- Press B to enter build mode
- Move mouse over ground
- You should now see a green transparent ghost of your building
- Invalid positions show red transparent ghost
If still not visible after update, continue with checklist below.
Quick Checklist
Run through these checks in order:
1. Check Console Logs
Press B to enter build mode and look for these messages:
- ✅ "Entered Build Mode"
- ✅ "[BuildingPlacement] Created preview: BuildingPreview"
- ✅ "[BuildingPlacement] Found X renderers"
- ✅ "[BuildingPlacement] Applied valid material to preview"
- ✅ "[BuildingPlacement] Preview activated at (x, y, z)"
If you see errors:
- ❌ "BuildingManager.Instance is null" → Go to Step 2
- ❌ "No buildings available" → Go to Step 3
- ❌ "Prefab is null" → Go to Step 4
- ❌ "Preview deactivated - no ground hit" → Go to Step 5
2. Check BuildingManager Setup
- In Hierarchy, find "BuildingManager" GameObject
- Verify it has:
BuildingManagercomponentNetworkObjectcomponent
- In BuildingManager component:
- Grid Size: Should be > 0 (e.g., 1)
- Ground Layer: Should be set (e.g., "Default" or "Ground")
- Available Buildings: Should have at least 1 BuildingData
Fix: If BuildingManager doesn't exist, create it:
- Create Empty GameObject → Name: "BuildingManager"
- Add Component → BuildingManager
- Add Component → NetworkObject
- Configure settings
3. Check BuildingData Asset
- Project window → Find your BuildingData asset
- Select it and check Inspector:
- Building Name: Should have a name
- Prefab: Should be assigned (not "None")
- Width/Length/Height: Should be > 0
- Verify this BuildingData is in BuildingManager's "Available Buildings" list
Fix: If BuildingData missing:
- Right-click in Project → Create → Northbound → Building Data
- Assign a prefab
- Add to BuildingManager's Available Buildings list
4. Check Building Prefab
- Find your building prefab in Project
- Open it and verify:
- Has a
MeshRendererorSkinnedMeshRenderercomponent - Renderer has a
Materialassigned - Has a
Collider(for placement validation) - Optionally has
NetworkObject(will be removed from preview)
- Has a
Fix: If prefab is missing components:
- Add a 3D object (Cube, for testing)
- Save as prefab
- Assign to BuildingData
5. Check Ground Layer
The preview won't show if the raycast can't hit the ground.
- In Scene view, select your terrain/ground
- Check its Layer (top of Inspector)
- In BuildingManager:
- Ground Layer mask should include this layer
- In BuildingPlacement (on Player):
- Ground Layer mask should match BuildingManager
Fix:
- Set terrain Layer to "Default" or create "Ground" layer
- In BuildingManager/BuildingPlacement → Ground Layer → Check "Default" (or your ground layer)
6. Check Camera
- Verify
Camera.mainexists in scene - Camera should be able to see the ground
Fix:
- Make sure Main Camera has tag "MainCamera"
- Camera should be positioned to see the scene
7. Check Player Setup
- Find your Player prefab
- Verify it has:
BuildingPlacementcomponent- Ground Layer is set
- Max Placement Distance > 0 (e.g., 100)
8. Visual Check in Scene View
- Press B to enter build mode
- Open Hierarchy window
- Look for object named "BuildingPreview"
- If it exists:
- Click on it
- Check if it's active (checkbox next to name)
- Look at its position in Inspector
- Switch to Scene view and look for it
- Check if materials are assigned in Renderer component
9. Test with Simple Cube
Create a minimal test setup:
- Create a Cube in scene → Save as Prefab → Delete from scene
- Create BuildingData → Assign Cube prefab
- Add to BuildingManager → Available Buildings
- Create a Plane → Position at (0, 0, 0)
- Press Play → Press B → Move mouse over Plane
You should see the transparent cube preview.
Common Issues
Preview exists but is invisible
Cause: Materials not rendering or transparent issues Fix (Now Automated):
- The system now auto-detects your render pipeline (URP or Standard)
- Creates proper transparent materials automatically
- If prefab has no renderer, adds a debug cube
Manual Test:
- Add
GhostMaterialTestcomponent to any object with a renderer - Press Play
- Object should become transparent green
- If it works, the ghost system will work too
Preview doesn't follow mouse
Cause: Ground layer not set correctly or no ground detected Fix:
- Check console for "no ground hit" message
- Verify Ground Layer includes your terrain
- Increase Max Placement Distance
- Make sure you're pointing at ground, not sky
Preview spawns at (0,0,0) and doesn't move
Cause: Raycast not hitting ground Fix:
- Same as above - Ground Layer issue
Materials are black/pink
Cause: Shader/material issues Fix:
- Make sure you're using the correct render pipeline shaders
- Standard RP: Use "Standard" shader
- URP: Use "Universal Render Pipeline/Lit" shader
Debug Commands
Add these temporary debug lines to check:
In CreatePreview() after instantiation:
Debug.Log($"Preview position: {previewObject.transform.position}");
Debug.Log($"Preview active: {previewObject.activeSelf}");
Debug.Log($"Renderers: {previewRenderers.Length}");
In UpdatePreviewPosition():
Debug.DrawRay(ray.origin, ray.direction * maxPlacementDistance, Color.red);
This shows the raycast in Scene view (red line from camera to mouse).
Still Not Working?
Check these final items:
- Input Actions are set up (ToggleBuildMode, Rotate, Build)
- BuildingManager is spawned on network (in scene, not prefab)
- You're the owner of the player (IsOwner = true)
- No errors in Console
- Build mode is actually active (check console for "Entered Build Mode")
If all else fails, check the Console for any errors and share them!