Agrarsense
BoundsVisualizerComponent.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
8
9#include "Components/PrimitiveComponent.h"
10#include "UObject/SoftObjectPath.h"
11#include "UObject/ConstructorHelpers.h"
12#include "Engine/StaticMesh.h"
13#include "Materials/Material.h"
14
15UBoundsVisualizerComponent::UBoundsVisualizerComponent()
16{
17 PrimaryComponentTick.bCanEverTick = false;
18
19 SetCollisionEnabled(ECollisionEnabled::NoCollision);
20
21 bCastDynamicShadow = false;
22 bCastStaticShadow = false;
23 bVisibleInRayTracing = false;
24 bVisibleInReflectionCaptures = false;
25 bVisibleInRealTimeSkyCaptures = false;
26 bAffectDynamicIndirectLighting = false;
27
28 SetCastShadow(false);
29
30 static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshAsset(TEXT("/Engine/BasicShapes/Sphere"));
31 if (MeshAsset.Succeeded())
32 {
33 SetStaticMesh(MeshAsset.Object);
34 }
35
36 static ConstructorHelpers::FObjectFinder<UMaterial> MaterialAsset(TEXT("/Game/Agrarsense/Materials/Misc/M_GridWireFrame"));
37 if (MaterialAsset.Succeeded())
38 {
39 SetMaterial(0, MaterialAsset.Object);
40 }
41}
42
43void UBoundsVisualizerComponent::BeginPlay()
44{
45 Super::BeginPlay();
46
47 // Hide this Component from all cameras expect Spectator camera
48 ASensor::HideComponentForAllCameras(Cast<UPrimitiveComponent>(this));
49}
50
51void UBoundsVisualizerComponent::SetSphereMesh()
52{
53 FSoftObjectPath Path(TEXT("/Engine/BasicShapes/Sphere"));
54 UStaticMesh* Mesh = Cast<UStaticMesh>(Path.TryLoad());
55
56 if (Mesh)
57 {
58 SetStaticMesh(Mesh);
59 }
60}
61
62void UBoundsVisualizerComponent::SetCubeMesh()
63{
64 FSoftObjectPath Path(TEXT("/Engine/BasicShapes/Cube"));
65 UStaticMesh* Mesh = Cast<UStaticMesh>(Path.TryLoad());
66
67 if (Mesh)
68 {
69 SetStaticMesh(Mesh);
70 }
71}
static void HideComponentForAllCameras(UPrimitiveComponent *PrimitiveComponent)
Definition: Sensor.cpp:255