Announcement

Collapse
No announcement yet.

Best way to link 2 actors through pointers.

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

    Best way to link 2 actors through pointers.

    When I got an actor which spawns another actor. And I need to connect both of those actors with the help of pointers, whats the best way to do so.

    I was using UPROPERTY() pointer to do such kind of links.
    Code:
    UPROPERTY()
    AActor* Actor
    But, I came across many places in the engine where a SharedPtr and a WeakPtr is used such kinds of links. What are the advantage of using them over normal pointer and how do I link the pointer in that way after spawning?

    #2
    Originally posted by envenger View Post
    When I got an actor which spawns another actor. And I need to connect both of those actors with the help of pointers, whats the best way to do so.

    I was using UPROPERTY() pointer to do such kind of links.
    Code:
    UPROPERTY()
    AActor* Actor
    But, I came across many places in the engine where a SharedPtr and a WeakPtr is used such kinds of links. What are the advantage of using them over normal pointer and how do I link the pointer in that way after spawning?
    SharedPtr and WeakPtr are for anything derived from TSharedFromThis or anything you might call MakeShareable on (mostly structs).

    UPROPERTY() on any pointer that is a UObject (Which includes AActor) will be hard reference
    TWeakObjectPtr is the weak reference version for UObjects

    See the docs for a more detailed description
    https://docs.unrealengine.com/latest...ary/index.html

    Cheers

    Kyle
    @kylerocha
    Luminawesome Games
    http://luminawesome.com/

    Comment


      #3
      Thanks for the link I didn't came across that page some how..

      If I got a character class which spawns an actor called weapon class, which pointers should I use to link them both?

      Comment


        #4
        You should be fine using a normal pointers.
        @kylerocha
        Luminawesome Games
        http://luminawesome.com/

        Comment


          #5
          Originally posted by kylawl View Post
          SharedPtr and WeakPtr are for anything derived from TSharedFromThis or anything you might call MakeShareable on (mostly structs).
          Isn't TSharedFromThis only necessary if you want to obtain the SharedPtr from the class itself? I don't think you need to inherit from TSharedFromThis use it with SharedPtr.

          Thanks

          Comment


            #6
            Originally posted by Trigve View Post
            Isn't TSharedFromThis only necessary if you want to obtain the SharedPtr from the class itself? I don't think you need to inherit from TSharedFromThis use it with SharedPtr.

            Thanks
            Thats right, you can also call MakeShareable on an instance that is not based on TSharedFromThis to get a shared pointer.
            @kylerocha
            Luminawesome Games
            http://luminawesome.com/

            Comment

            Working...
            X