hello
am using UE4.7 i have an actor class and i want to use a decal as a component in the component tab,
in blueprints i would just add decal component form the drop-down menu
but when i try to create UDecalComponent in C++ i try the following in my AActor Class
.h
UPROPERTY(VisibleDefaultsOnly, Category = "Decal")
class UDecalComponent* ActiveDecal;
Epic has provided all the required functions here in GameplayStatics!
Enjoy!
GameplayStatic.h
/** Spawns a decal at the given location and rotation, fire and forget. Does not replicate.
* @param DecalMaterial - decal's material
* @param DecalSize - size of decal
* @param Location - location to place the decal in world space
* @param Rotation - rotation to place the decal in world space
* @param LifeSpan - destroy decal component after time runs out (0 = infinite)
*/
UFUNCTION(BlueprintCallable, Category="Rendering|Components|Decal", meta=(WorldContext="WorldContextObject", UnsafeDuringActorConstruction = "true"))
static UDecalComponent* SpawnDecalAtLocation(UObject* WorldContextObject, class UMaterialInterface* DecalMaterial, FVector DecalSize, FVector Location, FRotator Rotation = FRotator(-90, 0, 0), float LifeSpan = 0);
/** Spawns a decal attached to and following the specified component. Does not replicate.
* @param DecalMaterial - decal's material
* @param DecalSize - size of decal
* @param AttachComponent - Component to attach to.
* @param AttachPointName - Optional named point within the AttachComponent to spawn the emitter at
* @param Location - Depending on the value of Location Type this is either a relative offset from the attach component/point or an absolute world position that will be translated to a relative offset
* @param Rotation - Depending on the value of LocationType this is either a relative offset from the attach component/point or an absolute world rotation that will be translated to a realative offset
* @param LocationType - Specifies whether Location is a relative offset or an absolute world position
* @param LifeSpan - destroy decal component after time runs out (0 = infinite)
*/
UFUNCTION(BlueprintCallable, Category="Rendering|Components|Decal", meta=(UnsafeDuringActorConstruction = "true"))
static UDecalComponent* SpawnDecalAttached(class UMaterialInterface* DecalMaterial, FVector DecalSize, class USceneComponent* AttachToComponent, FName AttachPointName = NAME_None, FVector Location = FVector(ForceInit), FRotator Rotation = FRotator::ZeroRotator, EAttachLocation::Type LocationType = EAttachLocation::KeepRelativeOffset, float LifeSpan = 0);
#C++ Code
Here’s the C++ Code inside of GameplayStatic.cpp for creating a decal component!