I am using UnrealEngine 4.27.2. While Compiling my C++ code i am getting this error " Unknown function specifier "BluePrintImplementableEvent" after creating a UFUNCTION.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "damageableActor.generated.h"
UCLASS()
class BASICS_API AdamageableActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AdamageableActor();
UFUNCTION(BlueprintImplementableEvent, Category = "Damage")
void onTakeAttack();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void takeAttack();
};
Related
I just want to create a node that simply specifies the bone name of the character and rotates it.
I want to move multiple bones, not just one bone, using the naming method.
I wrote the following codes.
MyCharacter.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"
class USkeletalMeshComponent;
class UPoseableMeshComponent;
UCLASS()
class TESTPLUGIN_API AMyCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMyCharacter();
FRotator RotationValue;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
UPoseableMeshComponent* PoseableMesh;
};
MyCharacter.cpp
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"
class USkeletalMeshComponent;
class UPoseableMeshComponent;
UCLASS()
class TESTPLUGIN_API AMyCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMyCharacter();
FRotator RotationValue;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
UPoseableMeshComponent* PoseableMesh;
};
When I compile the above code and open it with a level blueprint, I see a node like the one in the figure below.
This node is not what I wanted.
I want to create a node that can connect to FinalAnimationPose as shown in the image below.
How can I create a node like this?
All I want to do is simply rotate the bones every second. I couldn't find this information.
I am a beginner in both UE4 and C ++. Any answer will help.
I am new to UE but I think it was the same question which was asked in UE community to rotate but it was for a single bone:
Here's the link to that: https://answers.unrealengine.com/questions/47930/how-to-rotate-bone-in-c.html
I'm trying to implement weapon firing in my game!
My inheritance chain looks like this:
ACharacter -> AMainCharacter
AActor -> AWeapon -> ALaserGun
I'm trying to call a function in the ALaserGun class, but for some reason Weapon isn't of type ALaserGun. How can I use SpawnActor<>() to spawn an actor that's the same type as WeaponAtSpawnClass if I'm setting WeaponAtSpawnClass in blueprint? Right now, I'm spawning an AWeapon actor. I want to spawn a child of AWeapon which has OnFire() in it. The type of Weapon being the class stored in WeaponAtSpawnClass.
Some things that I've noted that might be causing the issue:
Weapon in MainCharacter.h is of type AWeapon*
SpawnActor<>() in Main Character.cpp uses AWeapon as the spawned type.
Would I have to change AWeapon in these statements to something else?
Here's my code:
MainCharacter.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MainCharacter.generated.h"
class AWeapon;
UCLASS()
class TEST_API AMainCharacter : public ACharacter
{
GENERATED_BODY()
public:
AWeapon* Weapon;
UPROPERTY(EditAnywhere)
TSubclassOf<AWeapon> WeaponAtSpawnClass;
void OnFire();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
MainCharacter.cpp
#include "MainCharacter.h"
#include "Weapon.h"
// Called when the game starts or when spawned
void AMainCharacter::BeginPlay()
{
Super::BeginPlay();
Weapon = GetWorld()->SpawnActor<AWeapon>(WeaponAtSpawnClass);
}
void AMainCharacter::OnFire()
{
Weapon->OnFire();
}
// Called to bind functionality to input
void AMainCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &AMainCharacter::OnFire);
}
Weapon.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Weapon.generated.h"
UCLASS()
class TEST_API AWeapon : public AActor
{
GENERATED_BODY()
};
There is no code in Weapon.cpp
LaserGun.h
#pragma once
#include "CoreMinimal.h"
#include "Weapon.h"
#include "LaserGun.generated.h"
UCLASS()
class TEST_API ALaserGun : public AWeapon
{
GENERATED_BODY()
public:
void OnFire();
};
LaserGun.cpp
#include "LaserGun.h"
void ALaserGun::OnFire()
{
UE_LOG(LogTemp, Warning, TEXT("Gun fired"))
}
AWeapon* Weapon; declares a pointer to any AWeapon. How whould the compiler know, that it points to a instance of a class that has some specific method?
Of course you could start casting Weapon to ALaserGun, but that's going to result in a mess. The better alternative is to declare the method in the interface AWeapon:
UCLASS()
class TEST_API AWeapon : public AActor
{
GENERATED_BODY()
public:
virtual OnFire() = 0;
};
And for good style declare that you override that method:
UCLASS()
class TEST_API ALaserGun : public AWeapon
{
GENERATED_BODY()
public:
void OnFire() override;
};
Naming is of course up to you, for example, if not every weapon can fire, name the method OnAttack or something, then call OnFire from OnAttack or something like that.
I'm trying to write an Actor in Unreal Engine C++, that gets texture data from a render target.
I have an Actor class:
#include "RenderActor.h"
#include "Engine.h"
#include <stdio.h>
// Sets default values
ARenderActor::ARenderActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
UE_LOG(LogTemp, Warning, TEXT("Init RenderActor\n"));
}
// Called when the game starts or when spawned
void ARenderActor::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("BeginPlay RenderActor\n"));
UTextureRenderTarget2D* target = GetTextureByName(TEXT("MyCanvas"));
}
// Called every frame
void ARenderActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
UTextureRenderTarget2D* GetTextureByName(const TCHAR* name)
{
return LoadObject<UTextureRenderTarget2D>(NULL, name, NULL, LOAD_None, NULL);
}
int ARenderActor::GetTextureData(UTextureRenderTarget2D* TextureRenderTarget ,void* out_ptr,int length)
{
int sx=TextureRenderTarget->SizeX,sy=TextureRenderTarget->SizeY;
TArray<FColor> SurfData;
FRenderTarget *renderTarget = TextureRenderTarget->GameThread_GetRenderTargetResource();
check((sx*sy*4)<=length);
renderTarget->ReadPixels(SurfData);
memcpy(out_ptr,reinterpret_cast<void*>(SurfData.GetData()),sx*sy*4);
return sx*sy*4;
}
There is a .h below:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Components/WindDirectionalSourceComponent.h"
#include "Runtime/Engine/Classes/Engine/WindDirectionalSource.h"
#include "Runtime/CoreUObject/Public/UObject/UObjectBaseUtility.h"
#include "Runtime/CoreUObject/Public/UObject/UObjectGlobals.h"
#include "Runtime/Engine/Classes/Engine/TextureRenderTarget2D.h"
#include "RenderActor.generated.h"
UCLASS()
class MEMRENDER_API ARenderActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ARenderActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UTextureRenderTarget2D* GetTextureByName(const TCHAR* name);
int GetTextureData(UTextureRenderTarget2D* TextureRenderTarget ,void* out_ptr,int length);
};
Now I can compile it on Ubuntu 18.04, but get a runtime error:
/home/starrabb1t/UnrealEngine/Engine/Binaries/Linux/UE4Editor: symbol lookup error: /home/starrabb1t/Documents/Unreal Projects/MemRender/Binaries/Linux/libUE4Editor-MemRender-7856.so: undefined symbol: _ZN12ARenderActor16GetTextureByNameEPKDs
P.S: I have a scene with RenderActor object. Also I created render target MyCanvas in root of content directory.
We tried to initialize components inside our character's constructor. The code worked on v4.15 but not v4.21.
Here is our code (.h file and .cpp file respectively):
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MainCharacter.generated.h"
UCLASS()
class VRET_API AMainCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMainCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
UPROPERTY()
class UCameraComponent * camera;
UPROPERTY()
class USceneComponent * VRroot;
};
#include "MainCharacter.h"
#include "Camera/CameraComponent.h"
#include "MotionControllerComponent.h"
#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
// Sets default values
AMainCharacter::AMainCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
VRroot = CreateDefaultSubobject<USceneComponent>(TEXT("VRroot"));
VRroot->SetupAttachment(GetRootComponent());
camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
camera->SetupAttachment(VRroot);
}
The code compiles, but when we run the game our character's components aren't being initialized and we cannot find them in the editor during gameplay BUT the default character components (eg:capsule component) work and show properly.
This happened to me. Try to unparent your blueprint class from AMainCharacter to just ACharacter, and then again parent it from AMainCharacter.
It worked for me!
I am using Unreal 4.18 and Visual Studio 2017. Using certain class like UShapeComponent, UBoxComponent, USphereComponent gives identifier is undefined error while likes of USceneComponent, UStaticMeshComponent works just fine. What's wrong?
Here is my code:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class UNREALTUROIAL_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* PickUpMesh;
UPROPERTY(EditAnywhere)
UShapeComponent* PickUpBox;
UPROPERTY(EditAnywhere)
USceneComponent* PickUpRoot;
};
enter code hereYou can try adding this include to your .h file
#include <Runtime/Engine/Classes/Components/SphereComponent.h>