Spawn on mouse location

Hi ,I want to spawn an specific actor on mouse cursor location , so far this is my code (on character class):

UWorld* const World = GetWorld();
if (World) {
	FActorSpawnParameters SpawnParams;
	SpawnParams.Owner = this;
	SpawnParams.Instigator = Instigator;
	FRotator SpawnRotation = FRotator(0,0,0);	
	APlayerController* pc = World->GetFirstPlayerController();
	FVector Direction = FVector(0, 0, 0);
	FVector Location = FVector(0,0,0);
	pc->DeprojectMousePositionToWorld(Location, Direction);
	FVector SpawnLocation = FVector(Location.X,Location.Y, 0);

	APickup2* YC = World->SpawnActor<APickup2>(BlueprintVar, SpawnLocation, SpawnRotation, SpawnParams);	
}

but what dose this do is spawning my actor on player location, not exact location of cursor.

i want something like this but with c++ :

There’s nothing like mouse location in game’s world in this case. Your mouse location on screen translates to a ray in the game’s world (i.e. all the points below the cursor), so you first have to decide at which point of the ray you want to spawn the new object.

To uniquely define a ray you need a starting point and a direction of the ray. You already have them from DeprojectMousePositionToWorld named Location and Direction.
However, what you’re doing now is spawning the object at Location(ish) which is where the ray starts → i.e. spawning on your player’s location.

What you really want to do I think is to spawn in the place where the “mouse ray” intersects another actor. Try to do a raycast into the world like here:

You’ll find an intersection position and then use that position as the spawn location.

ty, this is exactly what i needed.