我的巨剑能轻松搅动潮汐 2023-01-18 11:33 采纳率: 28.6%
浏览 19

虚幻引擎4 addforce闪退报错

问题遇到的现象和发生背景

UE4 C++
使用addforce函数时,可以生成解决方案,但是在ue4按下模拟运行时,先是卡一下啊,然后闪退,再报错。

img

遇到的现象和发生背景,请写出第一个错误信息
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Mycube.generated.h"

UCLASS()
class TEST_API AMycube : public AActor
{
    GENERATED_BODY()
    
public:    
    // Sets default values for this actor's properties
    
    /// 
    /// 声明模型变量
    /// 
    UPROPERTY(EditAnywhere,Category="ActorMeshCompoment")
    UStaticMeshComponent* StaticMesh;

    /// 
    /// 位置信息
    /// 
    UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "MyValues")//场景中可见
        FVector InitialLocation;//初始位置

    /// 
    /// 使用xxx功能吗?
    /// 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
        bool use_InitialLocation;//使用初始位置吗
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
        bool Use_World;//使用世界坐标吗?

    /// 
    /// 移动和旋转方向
    /// 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
        FVector Initial_Direction;//移动方向
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
        FRotator Initial_Rotation;//旋转方向
    /// 
    /// 力和扭矩
    /// 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
        FVector InitialForce;//力
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyValues")
        FVector InitialTorque;//扭矩
protected:
    AMycube();
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

};

// Fill out your copyright notice in the Description page of Project Settings.


#include "Mycube.h"
#include "Components/StaticMeshComponent.h"
// Sets default values
AMycube::AMycube()
{
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    AActor::PrimaryActorTick.bCanEverTick = true;
    StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));//创建默认子物体<类型>(名字)
    //设置初始位置
    InitialLocation = FVector(-100,350,420);
    //设置方向
    Initial_Direction = FVector(1, 0, 0);
    //设置旋转
    Initial_Rotation = FRotator(90, 0, 0);
    //设置力和扭矩
    InitialForce = FVector(0);
    InitialTorque = FVector(0);
}

// Called when the game starts or when spawned
void AMycube::BeginPlay()
{
    Super::BeginPlay();
    if (use_InitialLocation) {
        SetActorLocation(InitialLocation);
    }
    StaticMesh->AddForce(InitialForce, TEXT("NAME_None"), false);

    //StaticMesh->AddTorque(InitialTorque);
    
}

// Called every frame
void AMycube::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    FHitResult HitResult;//声明变量
    /*if (Use_World) {//根据世界坐标移动
        AddActorWorldOffset(Initial_Direction, true, &HitResult);//添加对象移动/移动式是否开启扫描/扫描(碰撞)结果
        AddActorWorldRotation(Initial_Rotation);
    }
    else {
        AddActorLocalOffset(Initial_Direction, true, &HitResult);//添加对象移动/移动式是否开启扫描/扫描(碰撞)结果
        AddActorLocalRotation(Initial_Rotation);
    }*/

    /*if (HitResult.bBlockingHit) {
        UE_LOG(LogTemp, Warning, TEXT("@@f Hit@:x=%f,y=%f,z=%f"),HitResult.Location.X, HitResult.Location.Y, HitResult.Location.Z);
    }*/
    if (HitResult.bBlockingHit) {
        UE_LOG(LogTemp, Warning, TEXT("@@s Hit@:x=%s,y=%s,z=%s"),*FString::SanitizeFloat(HitResult.Location.X), *FString::SanitizeFloat(HitResult.Location.Y),* FString::SanitizeFloat(HitResult.Location.Z));
    }
}



运行结果及详细报错内容
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”
  • 写回答

1条回答 默认 最新

  • 快撑死的鱼 2023-01-18 23:11
    关注

    回答不易,求求您采纳点赞哦

    您遇到的“addforce”函数导致虚幻引擎 4 闪退错误的问题可能是由几个不同的潜在问题引起的。以下是一些可能的原因和解决方案:

    • 施加的力太大或施加得太快。这可能会导致物理模拟变得不稳定并导致闪回。尝试减少施加的力或增加力施加之间的时间。

    • 施加力的物体太重或质量太大。这可能会导致物理模拟变得不稳定并导致闪回。尝试减少物体的质量或减少施加的力。

    • 施加力的对象未正确配置以进行物理模拟。确保对象在对象设置中启用了“模拟物理”选项,并且正确设置了碰撞网格。

    • 代码本身可能存在问题,例如无限循环或空指针。检查您的代码并确保没有无限循环或其他可能导致模拟冻结的问题。

    您可能需要检查您的系统要求,以确保它们满足运行模拟的最低要求。

    需要注意的是,以上建议只是导致问题的几种可能原因,需要进行彻底的调试。查看 Unreal Engine 4 文档或论坛以获取有关解决物理相关问题的更多信息也可能会有所帮助。

    评论

报告相同问题?

问题事件

  • 创建了问题 1月18日

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配