BuilderComponent struct in Thread
"This entity can build." Free-form placement in the Green Hell / Valheim sense — no grid, no sockets. The system casts a ray along this entity's forward axis, shows a ghost of the blueprint where it lands, lets the player turn it, and on commit turns that ghost into a real, saved entity.
Put it on whatever the player aims with: the camera entity, or the character carrying it.
A blueprint is just a .prefab — there is no separate asset type.
Properties
| Enabled | bool | Master switch. |
| Blueprint | std::string | The .prefab to place. Empty means nothing is selected, which is also how a game "puts the hammer away". |
| Settings.MaxDistance | float | How far the player can place from themselves. |
| Settings.MaxSlopeDegrees | float | Steeper than this is a hillside, not a building site. |
| Settings.AlignToSurface | bool | Off (default) keeps the object upright on sloped ground, the way a shelter does not lean downhill. On makes it hug the surface — a rug, a sign nailed to a rock. |
| Settings.YawSnapDegrees | float | 0 is free rotation, which is the point of this model. Set e.g. 15 for a little order without a grid. |
| BlockRadius | float | Radius of the "is this spot free" test. Roughly the footprint of what is being placed: too small and buildings interpenetrate, too large and the player cannot build next to anything. |
| RotateSpeed | float | Degrees per second while a rotate key is held. |
| PlacedCategory | std::string | Written into the placed entity's PersistentComponent. |
| ToggleKey / RotateLeftKey / RotateRightKey | Key | Default B, Q, E. |
| PlaceButton | Mouse | Default left button. |
What the player sees
The ghost is the interface. It is an instance of the blueprint, stripped of everything physical so it cannot collide with the world or with itself, outlined green where the spot is legal and red where it is not.
A refused ghost keeps following the aim. One that freezes on the last legal spot reads as the game having stopped responding; one that follows and turns red reads as "not here".
Why a spot is refused
| No surface | Aimed at open sky, or past everything. |
| Too far away | Something is there, but out of reach. |
| Ground is too steep | Slope exceeds MaxSlopeDegrees. |
| Something is in the way | The clearance test found an obstruction. |
Placement rules are separate from the scene
The decision — is this spot legal, what transform does the object get, where to test for
clearance — lives in BuildPlacement.h as free functions over plain structs, with no
knowledge of a scene, physics or rendering. BuildingSystem is the half that needs a
scene: the raycast, the overlap query, the ghost entity and the commit.
Two of those rules are decided before the solver is called, and both have an obvious wrong version that makes the whole feature look broken while every rule is correct:
MaxDistance makes "too far" unreachable — a wall past your reach returns no hit at all,
so the player is told No surface while looking straight at it.The clearance test must lift off the surface. Centred on the hit point it is always touching the floor, so every spot on the map reports Something is in the way.
Notes
Everything placed is tagged PersistentComponent, which is what makes a built wall survive quitting.
The pivot goes on the surface with no height offset, so blueprints should be authored with their origin at the base. A mesh whose origin is its centre will sink halfway in.
BuildingSystem runs only while playing. A ghost following the editor camera around
in Edit mode would be noise, and worse, an entity appearing in the outliner that the author never
made. BuildingSystem::Place and ClearGhost are public so a game can drive
placement from its own input, a UI button or a script instead of the bindings above.
BuilderComponent struct w Thread
„Ta encja może budować.” Swobodne stawianie w duchu Green Hell / Valheim — bez siatki, bez gniazd. System rzuca promień wzdłuż osi „do przodu” tej encji, pokazuje ducha projektu tam, gdzie trafi, pozwala go obracać, a po zatwierdzeniu zamienia ducha w prawdziwą, zapisywaną encję.
Umieść go na tym, czym gracz celuje: na encji kamery albo na postaci, która ją niesie.
Projekt (blueprint) to po prostu .prefab — nie ma osobnego typu assetu.
Właściwości
| Enabled | bool | Główny przełącznik. |
| Blueprint | std::string | .prefab do postawienia. Pusty znaczy, że nic nie wybrano — tak też gra „odkłada młotek”. |
| Settings.MaxDistance | float | Jak daleko od siebie gracz może stawiać. |
| Settings.MaxSlopeDegrees | float | Bardziej stromo to zbocze, nie plac budowy. |
| Settings.AlignToSurface | bool | Wyłączone (domyślnie) trzyma obiekt pionowo na pochyłym gruncie — szałas nie pochyla się w dół zbocza. Włączone przykleja go do powierzchni — dywan, tabliczka przybita do skały. |
| Settings.YawSnapDegrees | float | 0 to swobodny obrót, o który w tym modelu chodzi. Ustaw np. 15 dla odrobiny porządku bez siatki. |
| BlockRadius | float | Promień testu „czy to miejsce jest wolne”. Mniej więcej obrys stawianego obiektu: za mały — budynki się przenikają, za duży — nie da się budować obok czegokolwiek. |
| RotateSpeed | float | Stopnie na sekundę przy trzymaniu klawisza obrotu. |
| PlacedCategory | std::string | Wpisywana do PersistentComponent postawionej encji. |
| ToggleKey / RotateLeftKey / RotateRightKey | Key | Domyślnie B, Q, E. |
| PlaceButton | Mouse | Domyślnie lewy przycisk. |
Co widzi gracz
Duch jest interfejsem. To instancja projektu pozbawiona wszystkiego, co fizyczne, żeby nie kolidowała ze światem ani sama ze sobą, z obrysem zielonym, gdzie miejsce jest dozwolone, i czerwonym, gdzie nie.
Odrzucony duch dalej podąża za celownikiem. Duch, który zamarza w ostatnim dozwolonym miejscu, wygląda jak gra, która przestała reagować; taki, który podąża i robi się czerwony, mówi „nie tutaj”.
Dlaczego miejsce jest odrzucone
| Brak powierzchni | Celowanie w niebo albo poza wszystko. |
| Za daleko | Coś tam jest, ale poza zasięgiem. |
| Grunt zbyt stromy | Nachylenie przekracza MaxSlopeDegrees. |
| Coś przeszkadza | Test prześwitu znalazł przeszkodę. |
Reguły stawiania są oddzielone od sceny
Decyzja — czy miejsce jest dozwolone, jaką transformację dostaje obiekt, gdzie testować prześwit —
żyje w BuildPlacement.h jako wolne funkcje na zwykłych strukturach, bez wiedzy o scenie,
fizyce czy renderowaniu. BuildingSystem to część, która potrzebuje sceny: raycast,
zapytanie o nakładanie, encja ducha i zatwierdzenie.
Dwie z tych reguł rozstrzyga się przed wywołaniem solvera, i obie mają oczywistą błędną wersję, przez którą cała funkcja wygląda na zepsutą, choć każda reguła jest poprawna:
MaxDistance czyni „za daleko” nieosiągalnym — ściana poza zasięgiem w ogóle nie daje
trafienia, więc gracz słyszy Brak powierzchni, patrząc prosto na nią.Test prześwitu musi być uniesiony nad powierzchnię. Wyśrodkowany w punkcie trafienia zawsze dotyka podłogi, więc każde miejsce na mapie zgłasza Coś przeszkadza.
Uwagi
Wszystko postawione dostaje PersistentComponent — dlatego postawiona ściana przetrwa wyjście z gry.
Pivot trafia na powierzchnię bez przesunięcia w pionie, więc projekty powinny mieć początek układu u podstawy. Siatka z początkiem w środku zapadnie się do połowy.
BuildingSystem działa tylko w trakcie gry. Duch chodzący za kamerą edytora w trybie
edycji byłby szumem, a co gorsza encją w outlinerze, której autor nigdy nie zrobił.
BuildingSystem::Place i ClearGhost są publiczne, więc gra może sterować
stawianiem z własnego wejścia, przycisku UI albo skryptu zamiast powyższych skrótów.