Announcement

Collapse
No announcement yet.

How to create a const TweakObjectPtr<UObject>

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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):
    DEPRECATED(4.19, "Implicit conversions from const pointers to non-const TWeakObjectPtrs has been deprecated. Please const-correct this usage.")

    Code:
    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?

    #2
    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.
    Last edited by Zeblote; 12-17-2018, 09:08 AM.

    Comment


      #3
      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.

      Comment


        #4
        It work perfectly, i don't know what i had done last time...
        Thank you very much.
        Code:
        template<typename T>
        FORCEINLINE static TWeakObjectPtr<const T> ToWeak(const T* object)
        {
            return TWeakObjectPtr<const T>(object);
        };
        Last edited by ElFab; 12-18-2018, 05:24 AM.

        Comment

        Working...
        X