Error C2664 "Cannot Convert Argument"

I am trying to register the player character with CrowdManager so the AI entities avoid the player as well.

Following the instructions on this page, I implemented

include “Navigation/CrowdManager.h”
include “Navigation/CrowdAgentInterface.h”

in my MyCharacterC file, and entered the code provided into the ::BeginPlay() function.

UCrowdManager* CrowdManager = UCrowdManager::GetCurrent(this);

if (CrowdManager)
	   {
	CrowdManager->RegisterAgent(this);
	
}

The error I then get when I compile is:

error C2664: ‘void UCrowdManager::RegisterAgent(ICrowdAgentInterface *)’ : cannot convert argument 1 from 'AMyCharacterC *const ’ to ‘ICrowdAgentInterface *’ 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

How do I pass a the reference to the player character to this function?

Your AMyCharacterC needs to implement the ICrowdAgentInterface interface. Just add it to parent classes list.

Cheers,

–mieszko

Ah, thanks! Not sure what the right line for that is, could you give me the code example?

Adding “AMyCharacterC : public ACharacter, public ICrowdAgentInterface” to the .h file fails with a new and exciting error, even when not attempting to register player with UCrowdManager.

error LNK2019: unresolved external symbol “__declspec(dllimport) class UClass * __cdecl Z_Construct_UClass_UCrowdAgentInterface_NoRegister(void)” (_imp?Z_Construct_UClass_UCrowdAgentInterface_NoRegister@@YAPEAVUClass@@XZ) referenced in function “class UClass * __cdecl Z_Construct_UClass_AMyCharacterC(void)” (?Z_Construct_UClass_AMyCharacterC@@YAPEAVUClass@@XZ)

Thanks!

You need to include AIModule as your project’s dependency.

Thanks! And partial victory!

No more errors and MyCharacterC compiles now. Code for registering character with CrowrdManager is put into the BeginPlay() (as above), and MyCharacter is re-parented to MyCharacterC.

Game runs.

Problem is however, that the core reason for all this is not actually working, the AI entities, which are using DetourCrowdAIController as the parent for their AIController are not avoiding the player, opting instead to try walking straight through the player character as before.

What’d be the next thing to try to fix this particular issue?

Have you implemented any of ICrowdAgentInterface's functions?

What do I need to implement in my MyCharacterC’s code to make the line that is in the documentation work please?

Ok, so I’ve been messing with it the whole day and the result is still nothing.

So far, I added

virtual FVector GetCrowdAgentLocation() const override;
virtual FVector GetCrowdAgentVelocity() const override;
virtual void GetCrowdAgentCollisions(float& CylinderRadius, float& CylinderHalfHeight) const override;
virtual float GetCrowdAgentMaxSpeed() const override;

to the MyCharacterC.h file

Then implemented those functions in the MyCharacterC.cpp file.

The first two return the actual results, the third I am not really sure about, but it did

if (MovementComp && MovementComp->UpdatedComponent)
{
MovementComp->UpdatedComponent->CalcBoundingCylinder(CylinderRadius, CylinderHalfHeight);
}

in CrowdFollowingComponent.cpp so I tried that
and the last just returns a constant float value at the moment.

Overall visible result in game? bupkis.

It does still compile though.

Still stuck.