Agrarsense
ActorAssetDataAsset.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/DataAsset.h"
11
12#include "ActorAssetDataAsset.generated.h"
13
14/*
15 * Data asset wrapper for ActorAsset
16 */
17UCLASS(BlueprintType)
18class UActorAssetDataAsset : public UDataAsset
19{
20 GENERATED_BODY()
21
22public:
23 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Actor Asset Data")
24 FActorAsset ActorAsset;
25
30 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Actor Asset Data")
31 UStaticMesh* GetDefaultStaticMeshFromActor()
32 {
33 return ActorAsset.GetDefaultStaticMeshFromActor();
34 }
35
36#if WITH_EDITOR
37 void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
38 {
39 Super::PostEditChangeProperty(PropertyChangedEvent);
40
41 // You can check which property was modified if needed
42 FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
43
44 UE_LOG(LogTemp, Warning, TEXT("Property changed in the Data Asset!: %s"), *PropertyName.ToString());
45
46 if (PropertyName == GET_MEMBER_NAME_CHECKED(FActorAsset, Actor))
47 {
48 if (ActorAsset.Actor)
49 {
50 UStaticMesh* MeshFromActor = GetDefaultStaticMeshFromActor();
51 if (MeshFromActor)
52 {
53 ActorAsset.StaticMesh = MeshFromActor;
54 }
55 }
56 }
57 else
58 {
59 if (!ActorAsset.StaticMesh && ActorAsset.Actor)
60 {
61 ActorAsset.StaticMesh = GetDefaultStaticMeshFromActor();
62 }
63 }
64 }
65#endif
66};
UStaticMesh * GetDefaultStaticMeshFromActor()
Definition: ActorAsset.h:66