# Why can't I have a UObject Reference as a UFunction Parameter?

**URL:** <https://forums.unrealengine.com/t/why-cant-i-have-a-uobject-reference-as-a-ufunction-parameter/455098>\
**Category:** Editor Scripting\
**Tags:** uobject, reference, Input, ufunction, unreal-engine, question\
**Created:** [September 9, 2019, 9:02pm UTC](https://forums.unrealengine.com/t/why-cant-i-have-a-uobject-reference-as-a-ufunction-parameter/455098 "2019-09-09T21:02:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1cdfb710](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1cdfb710](https://forums.unrealengine.com/u/anonymous_user_1cdfb710)\
**Post date:** [September 9, 2019, 9:02pm UTC](https://forums.unrealengine.com/t/why-cant-i-have-a-uobject-reference-as-a-ufunction-parameter/455098/1 "2019-09-09T21:02:49Z")

</div>

I was trying to write a UFunction that takes a UObject reference as a parameter and realized it won’t compile.

Example

```
.h
UFUNCTION()
	void Reference_Parameter(UPARAM(ref) UObject& reference);

.cpp
void ATestFunction::Reference_Parameter(UPARAM(ref) UObject& reference)
{
	UE_LOG(LogTemp, Warning, TEXT("Function Called"));
}

```

This lead me to realize that I must be missing fundamental UObject knowledge.

Can someone please attempt to provide clarification/understanding?

Thank you.

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [September 11, 2019, 12:22am UTC](https://forums.unrealengine.com/t/why-cant-i-have-a-uobject-reference-as-a-ufunction-parameter/455098/2 "2019-09-11T00:22:50Z")

</div>

You should reference UObjects as pointers and not as reference.

UObject\* MyObject

Since UObjects are garbage collected by the engine, it would destroy the object and set these pointers automatically to null when they are no longer referenced, hence the need for a pointer enforcement

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1cdfb710](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1cdfb710](https://forums.unrealengine.com/u/anonymous_user_1cdfb710)\
**Post date:** [September 11, 2019, 4:00pm UTC](https://forums.unrealengine.com/t/why-cant-i-have-a-uobject-reference-as-a-ufunction-parameter/455098/3 "2019-09-11T16:00:10Z")

</div>

Yes pointers are what I ended up using. This makes sense, thank you.
