Agrarsense
ActorAsset.h
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
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Engine/Texture2D.h"
10#include "Internationalization/Text.h"
11#include "GameFramework/Actor.h"
12#include "Misc/Guid.h"
13#include "UObject/ObjectPtr.h"
15#include "Engine/StaticMesh.h"
16#include "Engine/Texture2D.h"
17#include "Components/StaticMeshComponent.h"
18
19#include "ActorAsset.generated.h"
20
21/*
22 * Actor asset struct for assets to spawn in the simulation
23 */
24USTRUCT(BlueprintType)
26{
27 GENERATED_BODY()
28
29public:
30 UPROPERTY(EditAnywhere, BlueprintReadOnly)
31 FString UniqueIdentifier;
32
33 UPROPERTY(EditAnywhere, BlueprintReadOnly)
34 EActorAssetType AssetType = EActorAssetType::Unspecified;
35
36 UPROPERTY(EditAnywhere, BlueprintReadOnly)
37 TSubclassOf<AActor> Actor;
38
39 UPROPERTY(EditAnywhere, BlueprintReadOnly)
40 TObjectPtr<UStaticMesh> StaticMesh;
41
42 UPROPERTY(EditAnywhere, BlueprintReadOnly)
43 TObjectPtr<UTexture2D> Image;
44
45 UPROPERTY(EditAnywhere, BlueprintReadOnly)
46 FText DisplayName;
47
48 UPROPERTY(EditAnywhere, BlueprintReadOnly)
49 float DefaultHeightOffset = 0;
50
51 UPROPERTY(EditAnywhere, BlueprintReadOnly)
52 float SpawnHeightOffset = 0;
53
54 UPROPERTY(EditAnywhere, BlueprintReadOnly)
55 bool SnapToGround = false;
56
58 {
59 UniqueIdentifier = FGuid::NewGuid().ToString();
60 }
61
67 {
68 if (Actor)
69 {
70 AActor* DefaultActor = Actor->GetDefaultObject<AActor>();
71 if (DefaultActor)
72 {
73 UStaticMeshComponent* StaticMeshComponent = DefaultActor->FindComponentByClass<UStaticMeshComponent>();
74 if (StaticMeshComponent)
75 {
76 return StaticMeshComponent->GetStaticMesh();
77 }
78 }
79 }
80
81 return nullptr;
82 }
83};
EActorAssetType
UStaticMesh * GetDefaultStaticMeshFromActor()
Definition: ActorAsset.h:66