Announcement

Collapse
No announcement yet.

Clone/Copy/Duplicate actor using blueprints?

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

    Clone/Copy/Duplicate actor using blueprints?

    Is there are a way to make a copy of an actor using a blueprint?
    Spawning a new actor and copying parameters one by one from another actor is a tedious and error prone approach. Simply because "copy_parameters" part of blueprint have to be adjusted every-time I make changes to blueprint variables.
    The same issue is with exposing them to SpawnActor function as they had to be linked one by one.

    I found this post:
    https://answers.unrealengine.com/que...ctor-in-c.html
    but this works only in C++. The "Template" parameter doesn't seam to be exposed to SpawnActorFromClass node...

    Am I missing something?
    Youtube Channel

    #2
    Have you tried, I think it is called, Make a copy of this, and it makes a child BP.

    Edit: Have you thought about making custom events or interfaces, or would that not work?

    Narg
    Last edited by Narghile; 02-01-2015, 06:59 AM.
    http://www.seven-mountains.eu/

    Comment


      #3
      Nope, don't see anything like that in blueprint editor.

      Unfortunately, interfaces won't really help here.

      It's weird that template parameter is not exposed to us.
      Youtube Channel

      Comment


        #4
        Make a base BP, Right click on it in content browser and the choice at the top is "Create a Blueprint based on this"

        1 child BP

        Narg
        http://www.seven-mountains.eu/

        Comment


          #5
          I don't want to copy a blueprint - I want to copy an actor using blueprints.
          Youtube Channel

          Comment


            #6
            Can you give a little more detail about what you are trying to achieve. Just to help us along a little.

            There may be a completely different way around if we had a little more detail.

            Narg
            http://www.seven-mountains.eu/

            Comment


              #7
              I have an actor somewhere in the level, with some specific set of properties. I want to make a copy of that actor, with exactly the same properties. I can't just copy/paste it in the editor as it needs to be done dynamically.
              In C++ you can do this: "SpawnActor has a parameter named Template. If you pass an actor in that, the newly spawned actor will copy the properties from the Template.". But this parameter is not exposed in "Spawn Actor from Class" node, so I'm looking at how else it can be done.
              Youtube Channel

              Comment


                #8
                Hello,
                Maybe a structure is what you need : https://forums.unrealengine.com/show...-actually-work .

                Comment


                  #9
                  I've considered structures, but this option is very limited. Placing all of the variables of a blueprint into a structure limits the possibility of inheriting this blueprint as any new parameters had to be placed in some extra structure.
                  Adding a structure just to pass all parameters creates a spaghetti in Blueprint which have to be maintained after any changes to a set of parameters that Actor needs to have.
                  Youtube Channel

                  Comment


                    #10
                    Well maybe is C++ is the only way.

                    sometimes, BP are ugly. But with comments and collapsed nodes. It can be easy to follow.

                    Narg
                    http://www.seven-mountains.eu/

                    Comment


                      #11
                      Sorry from necroposting but Google's results for "Clone Actor Blueprint" points here so the answer is more useful here.

                      Is true you can't clone an actor in runtime using blueprint but isn't too hard to create a custom blueprint who do this work:

                      1) In the editor go on File/Add C++Class and select "Blueprint Function Library" from the menu.

                      2) Rename it and click on "Create Class"

                      [...] wait compiler and Visual Studio time

                      3) Open the file NAMEOFYOURLIBRARY.h (if you can't find it in Visual Studio look in the Source folder of your project)

                      4) Copy this code:
                      Code:
                      #pragma once
                      #include "CoreMinimal.h"
                      #include "Kismet/BlueprintFunctionLibrary.h"
                      #include "NAMEOFYOURLIBRARY.generated.h"
                      
                      UCLASS()
                      class NAMEOFYOURPROJECT_API UNAMEOFYOURLIBRARY : public UBlueprintFunctionLibrary // Note: replace the project name and put a U before the name of your library
                      {
                          GENERATED_BODY()
                      
                              UFUNCTION(BlueprintCallable, Category = "ActorFuncions", meta = (WorldContext = WorldContextObject))
                              static AActor* CloneActor(AActor* InputActor);
                      
                      };
                      5) Find and open the NAMEOFYOURLIBRARY.cpp fine (same of point 3)

                      6) Copy this code:
                      Code:
                      #include "NAMEOFYOURLIBRARY.h"
                      #include "Runtime/Engine/Classes/Engine/World.h"
                      
                      AActor* UNAMEOFYOURLIBRARY::CloneActor(AActor* InputActor) // Note: put a U before the name of your library
                      {
                          UWorld * World = InputActor->GetWorld();
                          UE_LOG(LogTemp, Log, TEXT("Actor Duplication"));
                          FActorSpawnParameters params;
                          params.Template = InputActor;
                      
                          UClass * ItemClass = InputActor->GetClass();
                          AActor* const SpawnedActor = World->SpawnActor<AActor>(ItemClass, params);
                          return SpawnedActor;
                      }
                      7) Compile (from the solutions at the right, or from the compiling menu in the menu bar or MAYBE from the editor, not 100% sure)

                      NOTE: replace NAMEOFYOURLIBRARY with the name you give to your library in point 2, where there's UNAMEOFYOURLIBRARY put a U in front of it. Ex: MyCPPLib -> UMyCPPLib

                      You can now call anywhere a node called "Clone Actor" who take in input an actor and clone it (giving you the reference to the cloned actor in output).


                      P.S: I'm not a C++ programmer, I only need that node and I HAD to find a way, and I wanted tho share the solution.
                      Last edited by Iohoilpotere; 10-19-2018, 09:51 AM.

                      Comment


                        #12
                        Originally posted by Iohoilpotere View Post
                        Sorry from necroposting but Google's results for "Clone Actor Blueprint" points here so the answer is more useful here.

                        ....

                        P.S: I'm not a C++ programmer, I only need that node and I HAD to find a way, and I wanted tho share the solution.
                        Thank you for sharing!
                        Youtube Channel

                        Comment


                          #13
                          Hi,
                          I’m not sure if it’s the same question asked in this post, but I appreciate any help.
                          i have one actor and a target point. What I want to do is, when I provide a new target point, I want to duplicate my actor in the new target position with the same properties . I am going to create many of these duplicates. My actor is a sphere mask, and has simple material attributes. Is there any way to do such a thing in either blueprints or c++? This actor is going to be static actor with no movement.
                          i can’t predefine these actors as my target points are random

                          Comment


                            #14
                            @Iohoilpotere - I tried your interesting code and, although it compiled in visual studio (2017) without a complaint (alongside a couple of other functions in my functionlibrary) I am afraid that when I ran it as a blueprint, it crashed the engine 4.22 editor. I fed it pawns and simple actors but nothing made it happy. I appreciate that you make no claims to be a programmer but I wonder if you would have any clues at all?

                            Comment

                            Working...
                            X