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"

Call UpdateSunDirection function in the SkySphereBP from C++, is it possible?

Hi everyone I am just getting into Unreal C++, and I was wondering if it is possible to call a blueprint function using c++.

I am writing a fairly advanced day/night cycle and it would be inefficient to do all the calculations in blueprints, so I'm writing the calculations in c++ and then want to rotate the light source and call the update skySphere function.

Is this possible, if yes then how?

Product Version: UE 4.7
Tags:
more ▼

asked Jun 07 '15 at 12:33 AM in C++ Programming

avatar image

klon230
6 1 1 1

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

1 answer: sort voted first
 FOutputDeviceNull ar;
 mSkySphere->CallFunctionByNameWithArguments(TEXT("UpdateSunDirection"), ar, NULL, true);

but i still dont now how to set the actor pointer into spawned blueprint actor:

 //UObjectProperty* ObjectProp = FindField<UObjectProperty>(mSkySphere->GetClass(), FName("Directional light actor"));
 UObjectPropertyBase* ObjectProp = FindField<UObjectPropertyBase>(mSkySphere->GetClass(), FName("Directional light actor"));
 
 ObjectProp->SetObjectPropertyValue_InContainer(mSunLight, mSkySphere); // FAILED
more ▼

answered Jun 26 '15 at 07:11 AM

avatar image

xDPa
21 1 2

avatar image xDPa Jun 26 '15 at 08:28 AM

okay, found the right method:

 UObjectPropertyBase* ObjectProp = FindField<UObjectPropertyBase>(mSkySphere->GetClass(), FName("Directional Light Actor")); // not case sensitive
 
 if(ObjectProp) {
     ObjectProp->SetObjectPropertyValue_InContainer(mSkySphere, mSunLight); // first parameter is sky sphere and second the directional light
 
     //// check only
     void* ObjectPtr = ObjectProp->GetObjectPropertyValue_InContainer(mSkySphere);
 
     if(ObjectPtr) {
         ADirectionalLight* actor = static_cast<ADirectionalLight*>(ObjectPtr);
         ULightComponent* component = actor->GetLightComponent();
         
         // compare xy
     }
     
     // calculate
     FOutputDeviceNull ar;
     mSkySphere->CallFunctionByNameWithArguments(TEXT("UpdateSunDirection"), ar, NULL, true);
 }
avatar image 황용수 Oct 19 '15 at 10:30 AM

Hi!

How can i define mSkySphere and mSunLight?

avatar image TaurusI76 Feb 24 '17 at 10:43 AM

If your SkySphere and directional light (sun) are already created in the editor, you can search for them in your c++ code (in BeginPlay for example) and store the reference to it there.

Define the reference like this:

 UPROPERTY()
 AActor* mSkySphere = nullptr;

 UPROPERTY()
 ADirectionalLight* mSunLight = nullptr;

Search for the actors like this:

 for (TActorIterator ActorItr(world); ActorItr; ++ActorItr)
 {
     if ((*ActorItr)->GetName().Equals("SkySphere")) // Adapt to the name of your Sky Sphere
     {
         mSkySphere = *ActorItr;
 
         // quits the loop if both actors are found
         if (mSunLight != nullptr)
         {
             break;
         }
     }
 
     if ((*ActorItr)->GetName().Equals("DirectionalLightSun")) // Adapt to the name of your directional light (your sun)
     {
         mSunLight = (ADirectionalLight*)(*ActorItr);
 
         // quits the loop if both actors are found
         if (mSkySphere != nullptr)
         {
             break;
         }
     }
 }

(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