Deproject/Project - are there similiar functions outside of HUD/Canvas?

I could really use them outside of HUD. but right now Project/Deproject for all practical purposes are accessible only from HUD or Canvas.

Are there static/World function that would accomplish similar thing ?

In my static trace functions, weapon, everywhere where I need to match trace to offseted crosshair position.

I can of course grab deproject results from HUD, but that involves a lot of casting and hacking around.

#Yes

Open up PlayerController.h!

I helped Epic complete the set of functions so that you can indeed Deproject and Project outside of the HUD class!

My addition was ProjectWorldLocationToScreen via GitHub pull request

The other two functions are being updated in 4.5 to also return bool as my function does.

/** Convert current mouse 2D position to World Space 3D position and direction. **/
	UFUNCTION(BlueprintCallable, Category="Game|Player", meta=(FriendlyName="ConvertMouseLocationToWorldSpace"))
	void DeprojectMousePositionToWorld(FVector & WorldLocation, FVector & WorldDirection) const;

	/** Convert current mouse 2D position to World Space 3D position and direction. **/
	UFUNCTION(BlueprintCallable, Category = "Game|Player", meta = (FriendlyName = "ConvertScreenLocationToWorldSpace"))
	void DeprojectScreenPositionToWorld(float ScreenX, float ScreenY, FVector & WorldLocation, FVector & WorldDirection) const;

	/**
	 * Convert a World Space 3D position into a 2D Screen Space position.
	 * @return true if the world coordinate was successfully projected to the screen.
	 */
	UFUNCTION(BlueprintCallable, Category = "Game|Player", meta = ( FriendlyName = "ConvertWorldLocationToScreenLocation" ))
	bool ProjectWorldLocationToScreen(FVector WorldLocation, FVector2D& ScreenLocation) const;

Hey Rama, I’m actually trying to utilize DeprojectMousePositionToWorld to move the player around and I’ve hit a wall, maybe you’ll be able to help with my issue.
In my case, it seems the projection seems to hit some sort of invisible plane in front of the camera, rather that my level’s ground. So for instance, if I have my camera set to pointing directly down the Z axis, the returned value will always have a Z value of Camera.Z-10 for instance, independently of how far my camera is from any of the scenery. It almost seems to be returning a value on a fixed camera’s clipping plane.
I’m sure this will be some misunderstanding on my part on what this function is actually supposed to be doing, or on its usage, but I’d appreciate if you could shed some light on it.

EDIT: I think I just figured it out. Is it the case that this returns you a point through which you can trace a ray from camera pos using a separate set of functions, allowing you to manually detect a collision with any given object/thrace? I just started using UE4 and trying to get my ehad around a few things :slight_smile:

“I think I just figured it out. Is it the case that this returns you a point through which you can trace a ray from camera pos using a separate set of functions,”

Yes indeed!

The point given to you is the 3D point in space that is right up against the camera.

You must then move forward from that point along the World Direction to actually trace into the scene

//Use these values!
TraceStart = Deprojected 3D Point;
TraceEnd = Deprojected 3D Point + World Dir * 10000;

#:heart:

rama