ConstructorHelpers::FObjectFinder isn't getting my material parameter collection

I’m not sure what is wrong with it but it seems to not be setting it to my variable. From the look of my code and its output it finds the object but doesn’t set it to the variable. Here’s a picture of the code: https://cdn.pbrd.co/images/HLtfjQK.png and this is a picture of what it outputs: https://cdn.pbrd.co/images/HLteUxu.png

If anyone can workout why this isn’t working could you explain to me?

To help figure out your issue can you please post the entire code where ConstructorHelpers is used. Having more context might help in solving the problem.

ok, here’s the header file if needed: https://pastebin.com/h8M3Y76X and the c++ code: https://pastebin.com/6JkbCnsf

Please note that I don’t know much of c++, but i’m very familiar with other languages like c# and I have made it this far.

The goal if the entire code is to create a day/night cycle with a weather system using an existing skysphere and directional light source in the level. I have mostly figured it out but i can’t get it to change the material parameter collection that controls the snow and rain on textures. This will be a part of a plugin im making so i would prefer it to be c++ rather than blueprint.

It looks like you have a scoping problem when assigning your variable.

You declare matParam at a class variable but you re-declare it in your constructor with this line:

if (WeatherMPC_ASSET.Succeeded()) {
        UMaterialParameterCollection* matParam = WeatherMPC_ASSET.Object;
        if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, TEXT("MPC IS FOUND!"));
}

This assigns that local version of the variable, but leaves the class variable un-assigned. You need to change things from

UMaterialParameterCollection* matParam = WeatherMPC_ASSET.Object;

to

matParam = WeatherMPC_ASSET.Object;

I made them changes and the editor crashes while compiling with “Access violation - code c0000005 (first/second chance not available)”.

The full log is here: https://pastebin.com/gxMKQ5Pi

It looks like you are crashing inside UWorld::GetParameterCollectionInstance. You should debug your application (use the DebugGame build configurations) and step into that function and see if a) the world is initialized properly and b) the ParameterCollectionInstances have been initialized properly

I have stepped in to the function and it appears that “this” is null, given that it’s type is a UWorld is suggesting that the world is not initializing? It shows that it is able to get my collection as the parameters are in the locals.

I’m not sure on how I would approach fixing this or if it can be fixed.
Here’s the code and locals I got: https://cdn.pbrd.co/images/HLXzz62.png

Since the UWorld only exists on objects which have been spawned into the world it might be that the constructor is being called for the CDO which would not be able to access a UWorld object. You can try doing a check for a valid UWorld pointer before initializing these variables.

Another possibility is moving this initialization to BeginPlay.