cppファイルでの私の使用:
BoxComp->OnComponentBeginOverlap.AddDynamic(this, &AAICharacter::OnBoxOverlap);
BoxComp->OnComponentEndOverlap.AddDynamic(this, &AAICharacter::OnBoxEndOverlap);
次のエラーが発生しました:
cannot convert argument 2 from 'void (_cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)' to 'void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
関連する関数を含むヘッダーファイルは次のようになります。最小限の再現可能な例であると私が考えたものを作成するために、コードの一部が省略されています。専門知識の欠如に基づいて価値のあるものを省略した場合は、lmk:
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Engine/DataTable.h"
#include "Subtitle.h"
#include "Components/BoxComponent.h"
#include "Components/AudioComponent.h"
#include "AICharacter.generated.h"
/**
* The purpose of this class is to create a dummy AI for testing out the code for character interactions.
*/
UCLASS()
class GV_PROJECT_API AAICharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AAICharacter();
private:
UFUNCTION()
void OnBoxOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex, bool bFromSweep, const FHitResult & SweepResult);
UFUNCTION()
void OnBoxEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex)
protected:
/*If the player is inside this box component he will be able to initiate a conversation with the pawn*/
UPROPERTY(VisibleAnywhere)
UBoxComponent* BoxComp;
このエラーに精通している人はいますか?
エラーはかなり自明です。
cannot convert argument 2 from 'void (_cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)' to 'void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
示された行の2番目の引数(so&AAICharacter::OnBoxOverlap
および&AAICharacter::OnBoxEndOverlap
)は、メッセージにリストされている最初の型を持っていますが、呼び出されている関数(AddDynamic()
)は2番目の型を予期しています。異なるタイプが問題にならない場合もありますが、この場合、一方から他方に変換する方法はありません。
私が見る唯一のトリックは、問題のタイプを比較した後です。物事がよりよく整列するようにスペースを挿入するのに役立ちます。
void (_cdecl AAICharacter::*)( AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
2つのメンバー関数は、予想よりも少ないパラメーターを取ります。これらの関数が使用されるのがこれだけの場合は、追加のUPrimitiveComponent*
パラメーターを直接関数に追加できます。それ以外の場合は、必要な署名を持つラッパー関数を導入し、最初のパラメーターを無視して、メソッドを呼び出すことができます(一方のラッパーはを呼び出しOnBoxOverlap()
、もう一方はを呼び出しますOnBoxEndOverlap()
)。例えば:
UFUNCTION()
void OnBoxOverlapWrapper(UPrimitiveComponent* /*ignored*/, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex, bool bFromSweep, const FHitResult & SweepResult)
{
OnBoxOverlap(OtherActor, OtherComp, OtherIndex, bFromSweep, SweepResult);
}
これには注意が必要です。無視しているパラメータの重要性を知っていますか?コードには、その最初のパラメーターを使用しないことに起因する、現在気づいていないバグが含まれている可能性があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加