I want to design a button that automatically adds a specified actor to the level selected.How to implement this function?
you mean from the editor?
I’ve already done an actor and a button.I want to implement this, press this button, and automatically add the actor to the level.C++ programming only through the implementation, not through the blueprint.
Call the following function to spawn the actor:
SpawnActor<AMyActorClass>(AMyActorClass, Transform);
This function resides in UWorld
which you can access by calling GetWorld()
from the actor you’re spawning it from.
So for example: GetWorld()->SpawnActor<AMyActorClass>(AMyActorClass, Transform);
Note: you need to include the following file to call this function: #include "Runtime/Engine/Classes/Engine/World.h"
Let me know if this answers your question.