How to execute my custom C++ Actor (procedural level generator) at runtime
Disclaimer: I'm fairly new to UE. I recently moved to it from Unity because of some limitations Unity has (but that's not the scope of this post). I translated to C++ a code I wrote in C# (Unity), that generates procedural maps. And now I'm trying to integrate it into UE (after watching/reading lots of tutorials).
What I have done in UE:
1) creates an empty Scene Component
Basically everything is inside this Actor's Constructor (leaving its BeginPlay and Tick blanks). And it works quite well. If I drag and drop the Actor inside the Viewport, it generates a beautiful random dungeon, as expected.
What the problem is:
What the question is:
asked Feb 21 '16 at 06:32 PM in C++ Programming
It's always difficult to answer these questions without seeing the code but i'll see what I can do.
What you could try doing is in the GameMode class you can create a virtual function named Begin Play that spawns this particular actor in your world space. GameMode is called before the character being created.
Inside the actual character being created -- where he is created doesn't really matter. Just this->SetActorLocation() as soon as he enters the world.
Since you're creating a (random landscape right?) what you can do is shoot a Line Trace above the Actor and onto the ground and grab the hit location. Pass this value to the Set Actor Location. If you want a random location shoot multiple lines across a radius, number them(An array), and then randomly select which one you would like.
Assuming part 1 didn't work out... you need to find out what is re-executing in the code. Why is it being called twice? Something tells me that your constructor is the culprit. Unless somewhere in your code you are calling to generate it twice?
In the Generated Mesh's BeginPlay try putting this in it...
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::White, FString::FString("I am being called!");
Ideally, this should only appear once. If it does... then it means your generation method needs to be worked on.
ANYWAYS... give these ideas a try and let me know how it goes.
answered Feb 22 '16 at 12:30 AM
Mark James G
Follow this question
Once you sign in you will be able to subscribe for any updates here