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"

I Can't add DeltaTime To Custom Function

Hi, I want to add DeltaTime to a custom function, I want a function that when the player collides with an object, that object moves to the x axis, but I need to add DeltaTime for it to work smoothly, but when I add DeltaTime I get an error in .AddDynamic in this line of the script:

Move->OnComponentBeginOverlap.AddDynamic(this, &AMove :: Move);

It works when I add the normal parameters, but if I add Delta Time it does not work and gives me an error for example

UFUNCTION void Move (float DeltaTime);

If I add that it gives me the error.

Product Version: UE 4.19
Tags:
more ▼

asked May 22 '18 at 04:32 AM in C++ Programming

avatar image

Cereal_Killer_72
11 4 2 9

avatar image Cereal_Killer_72 May 22 '18 at 04:40 AM

Here is part of the cpp script, I get an error on the last line in .AddDynamic

 RootSceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootSceneComponent"));
 RootComponent = RootSceneComponent;

 MyMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));
 MyMesh->AttachToComponent(RootSceneComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

 Trigger = CreateDefaultSubobject<UBoxComponent>(TEXT("Trigger"));
 Trigger->AttachToComponent(RootSceneComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
 Trigger->SetWorldScale3D(FVector(3.0f, 4.0f, 2.0f));
 Trigger->bGenerateOverlapEvents = true;
 Trigger->OnComponentBeginOverlap.AddDynamic(this, &AMove::Move);
avatar image phil_me_up May 22 '18 at 05:58 PM

You can't change the parameters. OnComponentBeginOverlap expects to broadcast with a certain signature and you can't modify this.

There are other options though. What is it you're trying to achieve? What is DeltaTime in this case and what does AMove::Move do when an overlap event occurs?

avatar image Cereal_Killer_72 May 22 '18 at 09:16 PM

Sorry I answered late, I am trying to make a script that when you touch the object it moves, but I don't want it to appear and disappear I want it to move normally for example if the player touches the object it moves to the x axis, I want to use delta time so that the object moves in real time, and AMove::Move is the function that makes the object move. If you have any questions let me know I will answer them.

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

1 answer: sort voted first

Either pass DeltaTime thru argument (ofcorse you can't do that with predeclered delegates) or save DetlaTime on Tick to variable. You can also current DeltaTime from UWorld (GetWorld() in all actors) from DeltaTimeSeconds variable.

more ▼

answered May 22 '18 at 09:48 PM

avatar image

Shadowriver
37.3k 936 172 1116

avatar image Cereal_Killer_72 May 22 '18 at 10:00 PM

Thank you Shadowriver!

(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