x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.20
Tags:
more ▼

asked Nov 03 '18 at 06:43 PM in C++ Programming

avatar image

jordonbc
1 2 4

avatar image Brian Johnstone Nov 05 '18 at 04:25 PM

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.

avatar image jordonbc Nov 05 '18 at 04:43 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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;
more ▼

answered Nov 05 '18 at 08:40 PM

Brian Johnstone (suspended)
avatar image jordonbc Nov 05 '18 at 09:47 PM

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

avatar image Brian Johnstone Nov 06 '18 at 04:19 PM

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

avatar image jordonbc Nov 06 '18 at 08:39 PM

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

avatar image Brian Johnstone Nov 12 '18 at 04:21 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question