Download

How to create a const TweakObjectPtr<UObject>

Hello, i’m having warning while compiling my code, i deactivate it but i would prefere set this correctly.
The error is is the following from Engine\Source\Runtime\Core\Public\UObject\WeakObjectPtrTemplates.h (Line 89):


template<typename T>
FORCEINLINE static const TWeakObjectPtr<T> ToWeak(const T* object)
{
//#pragma warning( disable: 4996 )
    const TWeakObjectPtr<T> _toReturn(object);
//#pragma warning( default: 4996)
    return _toReturn;
};

I was not able to found a way to create const TWeakObjecPtr, i searched in FWeakObjectPtr too but nothing about that, how should i do since it is DEPRECATED? What is the explicit way?

I think you meant TWeakObjectPtr<const UObject> here? Your version would be a const weak pointer to a mutable object, which doesn’t make too much sense when starting from a pointer to a const object.

Yes that’s totaly right but TWeakObjectPtr<const UObject> was the thirst think i tried and i was not able to compile, i’ll take a look again in next hours. Thank you.

It work perfectly, i don’t know what i had done last time…
Thank you very much.


template<typename T>
FORCEINLINE static TWeakObjectPtr<const T> ToWeak(const T* object)
{
    return TWeakObjectPtr<const T>(object);
};