r/unrealengine•
emp-

[Tip] How to see c++ source of a BluePrint function

In another thread I mentioned that in the BluePrint editor you can right click a function and see the c++ source.

Now it seems that a whole lot of people didn't know about this feature so i figure i post it here so more people will know about it since it is such a time saver.

Now, everything in BluePrint does not have a c++ source, for instance the tick function: BluePrint Event Tick

But other functions do, like Break Hit Result . There is probably some documentation about what in BluePrint has a c++ source some where but i have not been able to find it.

Right click on the BluePrint function and click "Go to code definition"

Hope that will help you guys speed up your work flow!

Edit:

Gif http://i.imgur.com/uiyBpds.gif

Posted Jun 10, 2015, 1:36 AM UTC · edited

1917
Night_Lamp•

Cheers! Thanks for that!

2
KeoneShyGuyHobbyist•

Cool. After this and Shia yelling at me, I have no excuses for not learning how to code in Unreal.

edit: I think you may need to already have code in your project for this to work.

2
Realitynaut•

Very useful!

I was thinking about trying to assemble a set of reference C++ implementations of each of the Blueprint nodes as a way to help me get more comfortable in UE4's C++.

It seems I no longer need to!

2
drenmon•

I have been thinking about converting my blueprint only project in to c++ purly for better performance on the gearVR as calling c++ functions from blueprints is apparently quite CPU consuming.

2
HoodieWearer•

Thank you so much!

2
wildw1ng•

I dont have that context menu item either. Is there an engine option to activate this? or do you use a newer engine version than 4.7.6?

1
Kuzune•

It must be a code project for the option to appear. If it is purely BP it is not visible.

A project becomes a code project whenever code is added to it.

2
emp-OPHobbyist•

4.7.6 and i think that feature has been there since forever. However you must right click the function itself not somewhere on the "board" and again not all of the functions have a c++ source.

1
wildw1ng•

i do but i just dont have that context menu entry if i right click on "break hit result". I think it must be a setting in the engine options since you have the same version.

1
emp-OPHobbyist•

No idea then, then only thing i can think of is if you are right clicking on pin instead of the function itself.

Added a gif of how it works on my end http://i.imgur.com/uiyBpds.gif

1
thoosequa•

If you open up the source code of a function are you simply able to see it or can you alter it as well? If you do so, will it automatically create a copy for you or are you running in dangerous territory by changing the source code?

1
Kuzune•

All the code of the editor and your game is available to edit. So yes, you can alter the code of existing functions and those changes will be represented in the BP editor.

And I'm pretty sure you are altering the actual source files of the engine, not a copy, so for the most part you should only do it if you can handle it. But you could also just make backup copies of whatever file you are modifying.

1
thoosequa•

Say I want to modify Break Hit Result to work a little different for me. Is there a way to make a copy of that BluePrint node and alter nothing but the copy?

1
emp-OPHobbyist•

If you right click and go to code definition you end up in the .H file. From there you have to Right click the function definition and go to deceleration to see the .cpp code

In GamePlaySatics.h

/** Extracts data from a HitResult. 
 * @param Hit			The source HitResult.
 * @param bBlockingHit	True if there was a blocking hit, false otherwise.
 * @param Time			'Time' of impact along trace direction ranging from [0.0 to 1.0) if there is a hit, indicating time between start and end. Equals 1.0 if there is no hit.
 * @param Location		Location of the hit in world space. If this was a swept shape test, this is the location where we can place the shape in the world where it will not penetrate.
 * @param Normal		Normal of the hit in world space, for the object that was swept (e.g. for a sphere trace this points towards the sphere's center). Equal to ImpactNormal for line tests.
 * @param ImpactPoint	Location of the actual contact point of the trace shape with the surface of the hit object.
 * @param ImpactNormal	Normal of the hit in world space, for the object that was hit by the sweep.
 * @param PhysMat		Physical material that was hit. Must set bReturnPhysicalMaterial to true in the query params for this to be returned.
 * @param HitActor		Actor hit by the trace.
 * @param HitComponent	PrimitiveComponent hit by the trace.
 * @param HitBoneName	Name of the bone hit (valid only if we hit a skeletal mesh).
 * @param HitItem		Primitive-specific data recording which item in the primitive was hit
 */

	UFUNCTION(BlueprintPure, Category = "Collision", meta=(NativeBreakFunc))
	static void BreakHitResult(const struct FHitResult& Hit, bool& bBlockingHit, float& Time, FVector& Location, FVector& Normal, FVector& ImpactPoint, FVector& ImpactNormal, class UPhysicalMaterial*& PhysMat, class AActor*& HitActor, class UPrimitiveComponent*& HitComponent, FName& HitBoneName, int32& HitItem);

in GamePlayStatics.cpp

void UGameplayStatics::BreakHitResult(const FHitResult& Hit, bool& bBlockingHit, float& Time, FVector& Location, FVector& Normal, FVector& ImpactPoint, FVector& ImpactNormal, UPhysicalMaterial*& PhysMat, AActor*& HitActor, UPrimitiveComponent*& HitComponent, FName& HitBoneName, int32& HitItem)
{
	bBlockingHit = Hit.bBlockingHit;
	Time = Hit.Time;
	Location = Hit.Location;
	Normal = Hit.Normal;
	ImpactPoint = Hit.ImpactPoint;
	ImpactNormal = Hit.ImpactNormal;	
	PhysMat = Hit.PhysMaterial.Get();
	HitActor = Hit.GetActor();
	HitComponent = Hit.GetComponent();
	HitBoneName = Hit.BoneName;
	HitItem = Hit.Item;
}

You could copy paste that into your own file and change it to the way you wanted it to work. And then call that function instead of the one in UGameplaySatics.

3
m4xwHobbyist•

Shouldn't you rather inherit your own class and override the function?

That's a way better solution else you will get into trouble if anything gets deprecated.

And with deprecated I rather mean the function gets changed more than removed or other stuff.

1
emp-OPHobbyist•

You will see the source of the engine code so i would advice to not change anything there. But you will see how they did the blueprint function in c++ and can copy paste that into your own code and use it.

1