FComponentReference crashes the engine

Hello there!
I’m trying to get a reference to a component in my c++ actor; however, when I call the function, it crashes.

In my .h I have this:

UFUNCTION(BlueprintCallable, Category = "VRTK")
void GetNeededComponent(FName name, USceneComponent* &neededComponent);

and in my cpp:

void MyClassName::GetNeededComponent(FName name, USceneComponent* &neededComponent)
	FComponentReference componentThing;
	componentThing.ComponentProperty = name;
	neededComponent= componentThing.GetComponent(this);

When I call that function from a blueprint node, the editor crashes. Any ideas?
Thanks in advance

[EDIT: Fixed code]

Hey mago314-

Can you provide the callstack and log files from the crash for additional information? Also, in attempting to reproduce the issue on my end I copied the code provided into an Actor class. Can you explain what the collisionComponent is (UBoxComponent*, UCapsuleCompnent*, etc.) and how it’s created/setup? Please include any other information or steps to recreate the crash in a fresh project.

Hi. You’re goal is to determine if a collision component is attached and if so, return TRUE? Did I get that right?

After reading teak421’s comment I noticed that your function declaration says that the function returns a bool, but your function definition has a return value of void. I would expect this to cause compile errors that would need to be fixed before it could be used in the editor. Let me know if this is simply a typo when creating the AnswerHub post of if this is copied from your code? Also, where in your blueprint are you calling this function (ConstructionScript, BeginPlay, Tick, etc.)?

Oops, fixed the code. Now it reflects the problem. The idea is to get a reference to an existing component.

Thank you for clarifying the code difference. Can you also provide the callstack and log file from the crash for additional information? How are you using the code above? What is the “collisionComponent” variable and where is this code being called from? Are you adding this inside your actor or gamemode code or elsewhere? Please provide as much information as possible to help me reproduce the crash on my end.

I got a hunch and it fixed it. How or why it works, that’s a mystery reserved to the inner workings of the engine:

The .h:

	void GetNeededComponent(FComponentReference nameThing, USceneComponent* &neededComponent);

The .cpp:

void MyClassName::GetNeededComponent(FComponentReference nameThing, USceneComponent* &neededComponent)
	collisionComponent = nameThing.GetComponent(this);