> For the complete documentation index, see [llms.txt](https://steijn.gitbook.io/devlogs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://steijn.gitbook.io/devlogs/blewscreen/everlake/placement.md).

# Placement

## Proper start

For the Everlake project, we needed to find a way to place the furniture in runtime. I started by checking what existing code there was and analysed how I could implement my feature into it.&#x20;

I also looked at what would be necessary for the process and set out to make a small-scale class diagram that included the code that seemed useful to my project, as seen below.

![Class diagram, blue is what i'll be adding/adjusting](/files/Tc6JfqPuiCb5uJx9kBpA)

It covered most of the basic features we discussed at first such as rotations, a ghost object and a validity check.

The previous developers had left the project with some loose ends which were intended for object rotations. This is where I decided to begin with my project.

```csharp
Vector3 newRotation = DirectionConverter.GetDegreesFromDirection(direction); 
    gameObject.transform.rotation = Quaternion.Euler(newRotation); 
```

This code block needed to be added to the current code to make the objects rotate. Before I added this it was just changing the Enums but not the rotation.

### Ghost

* Literature study
* product review
* code review
* prototyping
* observation

My next goal was setting up a ghost object. For this, I knew I needed a way to store the original materials as well as adjusting the materials on the object.&#x20;

```csharp
public void SaveOriginalMaterials() 
{ 
    originalMaterialsList.Clear(); 
    foreach (Renderer renderer in GetComponentsInChildren<Renderer>()) 
    { 
        Material[] mats = new Material[renderer.materials.Length]; 
        int actualSize = 0; 
        for (int i = 0; i < renderer.materials.Length; i++) 
        { 
            mats[i] = renderer.materials[i]; 
            actualSize += 1; 
        } 
        Array.Resize(ref mats, actualSize); 
        originalMaterialsList.Add(mats); 
    } 
} 
```

With this code block I went over each renderer in the game Object that is the ghost. I retrieved all materials in the renderer and stored them into a list for later use.

```csharp
public void SetGhost(Material ghostMat) 
{ 
    int j = 0; 
    foreach (Renderer renderer in GetComponentsInChildren<Renderer>()) 
    { 
        Material[] mats = new Material[originalMaterialsList[j].Length]; 
        for (int i = 0; i < originalMaterialsList[j].Length; i++) 
        { 
            mats[i] = ghostMat; 
        } 
        renderer.materials = mats; 
        j += 1; 
    } 
} 
```

This code block somewhat the same but then I’ll set the materials list to be a ghost list afterwards.

![Final result](/files/SwS2m7yB9889jOzBezbZ)

This is what my ghost object looked like after I implemented it. As you can see it rotates, has a valid placement check and allows the player to pick up the placed object and place it elsewhere.
