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"

FObjectFinder.object is null on Tick

I have the following code:

  APracticeProjectCharacter::APracticeProjectCharacter(const FObjectInitializer& ObjectInitializer)
         : Super(ObjectInitializer)
     {
         static ConstructorHelpers::FObjectFinder<UMaterialInstance> materialAsset(TEXT("Material'/Game/ThirdPerson/Materials/playerMaterial_Inst.playerMaterial_Inst'"));
         if (materialAsset.Succeeded())
             material = (UMaterialInstanceDynamic*)materialAsset.Object;
     }
     
     void APracticeProjectCharacter::Tick(float deltaTime)
     {
         Super::Tick(deltaTime);
             material->SetScalarParameterValue(TEXT("power"), maxPowerLevel / powerLevel);
     }
 
 

I am trying to load material from the assets and change some parameters. On the constructor, material is not null and if I ser paramater value there it works. but on Tick function material is null and it leads to run time error. I understand why this is happaning. material is a UMaterialInstanceDynamic pointer and when FObjectFinder.object dies, materials dies too. but why does it goes null? it is static.

I also have tried to change the contructor for the following:

 static ConstructorHelpers::FObjectFinder<UMaterialInstance> materialAsset(TEXT("Material'/Game/ThirdPerson/Materials/playerMaterial_Inst.playerMaterial_Inst'"));
         if (materialAsset.Succeeded())
             material = UMaterialInstanceDynamic::Create(materialAsset.Object, this);

But chainging the paramater is not working. Even if I change it from the constructor. How can I get this work?

Product Version: Not Selected
Tags:
more ▼

asked Mar 31 '15 at 06:24 PM in C++ Programming

avatar image

Darkstorm1997
82 9 17 27

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

0 answers: sort voted first
Be the first one to answer this question
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