Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to spawn a prefab from C++? #31

Open
paxer opened this issue Aug 11, 2020 · 1 comment
Open

How to spawn a prefab from C++? #31

paxer opened this issue Aug 11, 2020 · 1 comment

Comments

@paxer
Copy link

paxer commented Aug 11, 2020

Hi,

First of all thanks for this amazing plugin!

I can't find any C++ examples of how to Spawn a prefab. From the source code I see there is a method to do it, but I can't figure out how to include it to my project? I mean what #include I need to use to get access to APrefabActor type and SpawnPrefab method?

    UPROPERTY(EditDefaultsOnly)
    APrefabActor* MyPrefab;

and then I need to call from my cpp

SpawnPrefab(const UObject* WorldContextObject, UPrefabricatorAssetInterface* MyPrefab, const FTransform& Transform, int32 Seed);
@paxer
Copy link
Author

paxer commented Aug 11, 2020

I think I found the solution, I'll leave it here just in case it will help somebody

adding to the [ProjectName].build.cs "PrefabricatorRuntime" to PublicDependencyModuleNames.AddRange will make accessible all the code from the plugin.

then in my .h

#include "Asset/PrefabricatorAsset.h"

    UPROPERTY(EditDefaultsOnly)
    UPrefabricatorAsset* MyPrefab;

and in .cpp

#include "Utils/PrefabricatorFunctionLibrary.h"

UPrefabricatorBlueprintLibrary::SpawnPrefab(GetWorld(), MyPrefab, FTransform(), 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant