Noob question about modifying existing c++ classes

Hi,
Usually, I work with Blueprint but now it seems that i need to try to code something in c++.
I would like to add a function to an already existing class (scenecapturecomponent) so that this function appears as a blueprint node.
I tried to do so and to build my project with VS but it seems that it did nothing.
Reading the Epic doc, I found out that building with VS only compile the classes added in the project.
So, how do I modify already existing class? Do I need to download ue4 source code on GitHub and compile the whole thing from this source?

Precision: as i didn’t find a way to add code to scenecapturecomponent, i tried to create a new c++ class from the editor extending from this. But compile in the editor always fails. Errors talks about “unresolved references…”
Any idea of what’s happening here?

You’ll probably need to post your code. If it doesn’t compile in the editor then that’s likely why you can’t see it in the content browser. You can try right click->Rebuild VS files also, which should add it to your VS project.

I want to modifiy SceneCaptureComponent.h and SceneCaptureComponent.cpp

1° - In SceneCaptureComponent.h, you can find:

I want to make this array readable in Blueprint by adding “EditAnywhere, BlueprintReadWrite, Category=SceneCapture” to the macro.

2 ° - There is a function called HideComponent:

In ScenceCatpureComponent.cpp, this function is defined this way:

And I want to add an other function which would be:

And i would define it this way:

And that’s all.

So my questions are:

  • Can I directly implement this modifications in code?
  • How can I compile this so that it work?

Firstly, VS won’t change your edits unless you modify the solution because you’re trying to change the original files, and the VS Solution is told not to compile the original UE4 files to save compile time, because again, they’re not suppose to be modified.

Modifying those files is a very bad idea, you’re never suppose to modify the original files unless you REALLY know what you’re doing and like to open cans of worms.

Instead, what you should do, is EXTEND SceneCaptureComponent with your own version, via the Add Code button inside the File tab of the Editor. Then select SceneCaptureComponent as a parent, and create your own version. From there you can override the original code, without ever actually changing the original code, so it’s always still there. Then use your custom extended class to do the modifications you need, safely.

Thanks for your answer.
So, compiling UE4 from source code is for experts, right?
I already tried to extend SceneCaptureComponent from a project, using “Add code to project”. I thought it was a good idea, as i saw that changes in already existing classes were not compiled.
But as i said, i can’t do this: compile fails and the log window shows several errors: “unresolved reference…”. I didn’t take a screencapture of the log but I could if you think it’s useful.

Otherwise, could I do what I described with a class extending from scenecapturecomponent?

Yes, you can do what you’re attempting by extending. An Unresolved reference error just appears that the compiler can’t figure out what you’re trying to tell it to do. Coding in C++ has some strict requirements, so if you’re unfamiliar with it, it’s probably just something you didn’t write properly enough for the compiler to understand.

Start by creating a C++ class without modifying it is always best, close the editor, and compile, if it succeeds (and it should, as you haven’t touched anything) and see if the class shows up in the Editor. Then you can start attempting to edit it afterwards.

Ok but when I say that compiled failed, it was just when i wanted to add a new c++ class extending from scenecapturecomponent. I didn’t write a single line of code: the class was created, compiling process began and at the end, the editor showed “compile failed”.
I tried to create other c++ classes extending from other classes (actor, scenecapture2D) to see if compilation failed also but it didn’t.
I’ll try to do it again to capture the log window showing errors.

I’ve had that happen occasionally as well. What you can try is opening up the VS file (.sln) and try to compile that. That should give you some more detailed error messages. There should also be a log within the editor itself (Windows->Developer Tools) that you can try to get error messages from. If you can post those I’m sure somebody can help.

Ok, so I have created a new project.
I tried again to extend from SceneCaptureComponent.
And compile failed again.
Here is the log:

Hope someone understands what it means.

Basically It can’t find the implementations of those functions - PostLoad(void) for example. That shouldn’t happen if it’s just a class built by the editor. If you haven’t modified any of the code then I think that is a bug.

If you have modifed the code, Usually these errors are because the compiler has the code in the wrong scope, ie the bold part of :




void **USceneCaptureComponent**::HideComponent(UPrimitiveComponent* InComponent)


The other alternative is that those functions are purely virtual and require you to define those functions before it will compile. You could try extending a class further down the food chain - like USceneCaptureComponent2D instead to see if you get the same error.

If you can post the code contained in CaptCompCust.cpp and .h that would help.

I didn’t modify the existing code and there is no code in CaptCompCust class. It is the class I have added, extending SceneCaptureComponent. UE4 created it but at the end, compile failed and CaptCompCust.cpp and .h remained in the Source folder.
I will try to extend a class further. I thought you could extend from any class, as I read it in the UE4 doc.

I agree, you should be able to extend from any class, or at least I would expect a warning if you tried something you weren’t supposed to do. I’d try extending from another class, and if that fails post the contents of the .cpp and .h file that get created.

So I tried to extend the class, and as well the compile fails. I believe it’s because of a Dependency is missing (a dependency is a pointer/reference for “chunks” of code), I’m just not sure which however. Some classes can’t be extended without adding a dependency into your .CS file (ProjectName.CS). Which finding out which one you need is a little beyond me. I will attempt to see if I can figure it out.

It might be worth posting as a [BUG] inside the Answer Hub.

Thanks for testing.
I tried to extend from SceneCaptureComponent2D: same problem.

I searched for similar problems on the web, typing: "ue4 unresolved external symbol “public: virtual void”
and I found this thread in UE4AnswerHub:

from Epic Staff explains that the problem is due to the fact that the class the user tries to extends is marked MinimalAPI rather than fully exported via ENGINE_API.
And SceneCaptureComponent is marked MinimalAPI too (ckecked it).
So I think that compile failure comes from here.

also indicates that, while this bug is not officially fixed, one could compile UE4 from source, changing MinimalAPI to ENGINE_API, to be able to extend.

I’ll think I will wait a new release of UE4 as building on my old computer takes 2 hours (no kidding!).
Annoyed it doesn’t work but happy to know why !

Anyway, thanks for your help, guys!

EDIT: as i was impatient to see if it was fixed, I downloaded the 4.8 preview. Still doesn’t work, for same reasons.

Still impossible to extend for scenecapturecomponent in the official 4.8.0 release.
Will it be fixed or is it something programmers decided, for some reasons, to let go this way?

Searching through answerhub, i found this post from , reporting the same problem.
And here is the answer from Tim Lincoln from Epic Staff:

Why did they choose this option? As you can however modify the code of this class and add functionnalites, the result is the same as if you were extending. So why not allowing to extend? It’s like forbidding something that is however allowed in an other way. And compiling would be much faster. That would be the main advantage. For the moment, if i have to change a single bracket, I have to recompile everything.

Well you could just cut and paste the code in the existing class into a new one of your own, then you’d only need to recompile that one class?

In fact I just need to add a function to scenecapture component. It takes 5 lines of code and that’s all.
So I only see 2 options: it put it in the class itself or it put it in a class extending from it.
For the moment, I use the first and it works. But each time there’s a new release or preview, I have to rebuild to make it work.
Just a little tedious.