虚幻c++使用LineTrace从Actor调用一个void
Unreal c++ Call a void from a Actor With LineTrace
我是 c++ 的新手(用于 c#),当 Actor 被光线投射击中并向其发送绳索时,尝试在 Actor 上调用空洞。这是我尝试调用"EditMesh"的脚本标头(靠近底部)
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ProceduralMeshComponent.h"
//#include "Core.h"
#include "Chunk.generated.h"
UCLASS()
class VOXELWARS_API AChunk : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AChunk();
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, BlueprintReadWrite, Category = Default)
// UMaterialInterface* TheMaterial;
UPROPERTY(EditAnywhere)
AChunk* ChunkRef;
UPROPERTY(EditAnywhere)
class UMaterialInterface* OnMaterial;
UPROPERTY(VisibleAnywhere)
UProceduralMeshComponent * mesh;
UPROPERTY(VisibleAnywhere)
int faceCount = 0;
TArray<FVector> vertices;
UPROPERTY(VisibleAnywhere)
TArray<int32> Triangles;
TArray<FVector> normals;
TArray<FVector2D> UV0;
TArray<FProcMeshTangent> tangents;
TArray<FLinearColor> vertexColors;
TArray<FVector2D> blocks;
int worldData[16][16][16] = { {} };
float tUnit = 0.0625;
public:void CubeTop(int x = 0, int y = 0, int z = 0, int block = 0);
public:void CubeNorth(int x = 0, int y = 0, int z = 0, int block = 0);
public:void CubeEast(int x = 0, int y = 0, int z = 0, int block = 0);
public:void CubeSouth(int x = 0, int y = 0, int z = 0, int block = 0);
public:void CubeWest(int x = 0, int y = 0, int z = 0, int block = 0);
public:void CubeBot(int x = 0, int y = 0, int z = 0, int block = 0);
public:void Cube(FVector2D texturePos);
public:void UpdateMesh();
public:void ClearMeshData();
public:void GenMesh();
public:void EditMesh(int x = 0, int y = 0, int z = 0, int block = 0); //here
public:int Chk(int x = 0, int y = 0, int z = 0);
// int* mBlock(int x = 0, int y = 0, int z = 0);
};
这是我想调用 EditMesh() 的另一个脚本的 cpp 的一部分
#include "Chunk.h"
#include "VoxelWarsCharacter.h"
#include "VoxelWarsProjectile.h"
#include "Animation/AnimInstance.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/InputSettings.h"
#include "HeadMountedDisplayFunctionLibrary.h"
#include "Kismet/GameplayStatics.h"
#include "MotionControllerComponent.h"
#include "XRMotionControllerBase.h" // for
void AVoxelWarsCharacter::OnFire()
{
FVector StartLocation = GetActorLocation(); //your location
StartLocation.Z += 15;
FVector EndLocation = StartLocation + (FirstPersonCameraComponent->GetForwardVector() * 4000.f); //get forward dir
FHitResult Hit;
FCollisionQueryParams ColParms; //ignor stuff
ColParms.AddIgnoredActor(this);//ignor hitting self
GetWorld()->LineTraceSingleByChannel(Hit, StartLocation, EndLocation, ECC_Visibility, ColParms);//ECC_WorldDynamic will only hit Actors, ECC_Visibility is everything
if (Hit.GetActor()) {
//Hit.GetActor()->AChunk::EditMesh(0, 0, 0, 1);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor(255,255,255), "Hit a actor");
UKismetSystemLibrary::DrawDebugLine(GetWorld(), StartLocation, Hit.Location, FColor(255, 255, 0), 5, 1);//FColor::Red
Hit.GetActor()->FindComponentByClass<AChunk>()->EditMesh((int)Hit.Location.X, (int)Hit.Location.Y, (int)Hit.Location.Z, 0);
//How do I do this?????????
}
}
我得到的错误
编译器结果日志:错误:D:\ProgramFiles\Epic Games\4.19\UE_4.19\引擎\源\运行时\引擎\类\游戏框架/Actor.h(2640):错误 C2338:FindComponentByClass 的"T"模板参数必须派生自 UActorComponent CompilerResultsLog:
错误: C:\Usersolan\Desktop\VoxelWarsUR\Project\VoxelWars\Source\VoxelWars\VoxelWarsCharacter.cpp(160):注意:请参阅函数模板实例化 'T 的参考*AActor::FindComponentByClass(void) const' 正在编译
参数到 FindComponentByClass 必须派生自 UActorComponent
VoxelWarsCharacter.cpp的第160行:
FindComponentByClass<AChunk>
AChunk
不是组件。组件以 U
开头
相关文章:
- 如何将指针从一个void函数传递到另一个C++
- 如何将一个 void 函数传递给另一个 void 函数?
- 定义一个 void f(void) 函数,但使用来自同一范围的变量?
- 除了调用全局删除运算符之外,删除一个void指针还能做什么呢
- 将 void 指针分配给另一个 void 指针
- 如何编写一个 void 函数,该函数将在数组中搜索值,并通过引用将该值的位置传递回 main 函数
- 如何在堆上分配一个void*阵列
- 虚幻c++使用LineTrace从Actor调用一个void
- 如何创建一个 void 数组,其大小将由用户从命令行输入指定
- 复制值从一个void **到C 复制构造函数中的另一个void **
- 返回一个void数组*
- static_cast一个void*指针可以吗
- 如何在C++中使一个void函数与另一个void功能协同工作
- 有没有任何情况下,变量可以被赋予一个void函数
- 为什么我们不能声明一个 void 类型的变量?
- 我在我的程序中添加了一个void函数,它不接受任何参数,现在我的程序在运行时只返回一个空白终端
- 如何将地址对齐到一个void指针
- 使用malloc和一个void指针复制一个临时结构
- 为什么这个快速排序的实现从一个void函数返回?
- 将不同的数据类型组合成一个void类型