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"

Is there any way to update the value in a costructor script before spawning an actor.?

I have an actor having its constructor script something like this.

 APlanetActor::APlanetActor(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 {
 
 DistanceFromStar = 5000;
 
 }

But I also have an actorcomponent inside the construction script which has some calculation depending upload the variable DistanceFromStar.

After I spawn the actor, then the construction script would have been executed and I don't think there would be a way to change the value given to that actorcomponent. So is there a way change ta value of class variable before the construction script has been executed? Like making another default value?

Product Version: Not Selected
Tags:
more ▼

asked Sep 17 '14 at 08:19 AM in C++ Programming

avatar image

envenger
418 76 117 145

avatar image TheTrice Sep 17 '14 at 09:05 AM

First Why dont you just create a function for that actor which when called sets the value and then actorcomponent does its calculation then ?

avatar image envenger Sep 17 '14 at 09:23 AM

I am creating many splinemeshcomponent actors through a for loop so I need to know how many are their total cause I can use PCIP outside the for loop.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I also had this problem, and wrote a fairly detailed forum post about this.

more ▼

answered Sep 19 '14 at 06:13 AM

avatar image

staticvoidlol
2.6k 95 40 111

avatar image envenger Sep 23 '14 at 09:17 AM

I think this method wont work here. Cause I wont be able to find assets outside constructor. I am thinking of using a static variable now whose value I can change during run time and the static variable is going to have some use in constructor. Let me see if that works.

avatar image staticvoidlol Sep 23 '14 at 09:29 AM

You can always find assets (even outside of the constructor) with StaticLoadObject, e.g.

 Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *(Path)
avatar image envenger Sep 23 '14 at 09:40 AM

I don't want to load something. I want to change variables values before a constructor is called.

e.g. in constructor I got something like this

     ASplineGeneratingActor::ASplineGeneratingActor(const class FPostConstructInitializeProperties& PCIP)
         : Super(PCIP)
     {
         int32 NoOfRings = RingData.Num();
     
         for (int32 i = 0; i < NoOfRings; i++)
         {
             FString StringName = "SplineRing" + FString::FromInt(i);
             FName RingName = FName(*StringName);
             TSubobjectPtr<USplineComponent> SplineComp = PCIP.CreateDefaultSubobject<USplineComponent>(this, RingName);
 .....
 .....
 .....
 }
 }

I need to set the RingData array before the constructor is called.

avatar image staticvoidlol Sep 23 '14 at 09:54 AM

Ah ok, I see that's quite a predicament. I'm assuming you'll be extending classes from this ASplineGeneratingActor for generating specific splines, otherwise there wouldn't be a problem.

I don't have the code in front of me at the moment, but I'd suggest looking into whether it's possible to create default subobjects outside of the constructor, or passing parameters to the constructor via PCIP.

(comments are locked)
10|2000 characters needed characters left
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