Download

Help needed to convert simple BP to C++

I have extracted this question from this thread because I think this isolated problem should be quite simple to answer:

I have this blueprint:

5cdcdc3a045cd948a1673b8f6eed25d613b1458a.png

Where “Mesh” and “Height” are visible variables in my blueprint.
How do you convert this to C++?
I have tried several different implementations but I can’t get updates of the “Mesh” and “Height” variables to work.

Sorry for a simple newbe question, but I really need some help here…

just woke up but it should be something like this:

in the header:

in the cpp (in side the constructor thingy EX: AYourActor::AYourActor()):

disclaimer: im terrible at this stuff

edit: public: because VS says so
edit2: untested also

Well, I’m sorry to say I have already tested this, but it wont work. It will only take the default values of MeshToUse and Height and will not update the Actor if you change any of the variables like the BP does :frowning:

Can this really be so complicated?

Try putting the height setting in your BeginPlay. Construction may not be called every time you update it in C++.

BeginPlay will not be called until the game is started, so you won’t see your changes in the editor then…
I made a solution that works in thisthread, but it has some major issues so I hope there exists a better way.

Well the problem is, the Construction Script is not “easy” at all.
There is no plug and play version of it in C++.

I already tried that a few months ago. You need to actually remove your Instances again, before spawning new once.

The Construction Script handles that a bit different. All in all, that’s why no one can give you a clear and straight answer.
The Construction Script is not an actual function that you can call in your C++ Class and it will do the same stuff for you.

You could just create a function with the “AddStaticMeshComponent” stuff, and make it “BlueprintCallable”. Then let the
derived Blueprint Class call it in its Construction Script.

There is no shame in using a Blueprint as a last C++ Child Class. It’s even recommended to combine your C++ with Blueprints.

Question: Why exactly does your Solution from the other Thread crash? Do you have any Crashlogs and Errorlogs, which you could post?
Maybe it’s something simple.

This is the crash report: “You do not have any debugging symbols required to display the callstack for this crash.”
And I have compiled the C++ with debug symbols, so that is not the case.
The strange thing is that if I start with an empty level i can drag in my C++ actor to the level and everything works fine, but if i close the editor and opens it again, it crashes.
To me that indicates that I have put the code in the wrong place.

About using a combo of BP and C++:
I agree that there is no shame about using BP’s, but my goal is to use actors within actors and actors with parameters that control their appearance to procedurally generates levels.
And if every actor consists of code that goes back and forth between C++ and BP i suppose that the architecture will quite fast grow to an unmaintainable mess.

Is UE4 not a suitable engine for doing what i am trying to do?

This is a major design flaw of the engine and generated project files.
As you can see by reading through the forum, everything related to edit/design time is complicated to do in C++, because there is no entry point.
The generated C++ files focus on a game with it’s “BeginPlay”. What we need is a similar “BeginEdit”, which provides us with a valid UWorld at edit time.

I found that OnConstruction can be use for exactly this purpose.
I recommend anyone that are interested to read this tutorial, an excellent work!