In unreal using c++ how can I make a function get called every certain amount of time say 0.001s in edit mode(not play mode. The SetTimer API doesn’t seem to work in edit mode ).
Hi Anning5,
I doubt you’ll get to that resolution, but you can hook into the editors tick with:
#if WITH_EDITOR
GEngine->OnPostEditorTick().AddRaw(this,&FMyModule::MyTick);
#endif
Yeah you won’t get any faster than a frame on the game thread.
Not clear why you’d want that update frequency. Given a bit more info, there might be some higher level concept that could apply.
For example, if you need to do a calculation 1000x per second, then you could just calculate how many would have went by over the previous frame, and do them all in a batch. You won’t be able to perceive any visible state update until the next frame anyway.
For another example, you might be trying to do something on a separate thread. Again, you would only affect the game thread once per frame (technically not true but you would be splitting hairs there and functionally be no different than just once per frame anyway) but it would technically have a faster update cycle (up to whatever the OS allows you to run at).
I’m guessing you’re just wanting to update once per frame though.
i vaguely remember having problems with SetTimer when i was making an editor utility. It would work if i was focused on certain windows, but if i clicked on something else, it would stop working.
I ended up just using tick and making my own timer because that was easier
Thanks guys. For the reason of my question, I have been doing some heavy computational task using pixel shader which has a big for loop inside . This task also needs to be spread over thousands of draw calls. Because of the big loop in the pixel shader, even one draw call will stall the GPU for a while, so I can’t put many draw calls in one frame otherwise it will crash unreal. When I was trying it in the play mode I found unreals performance is really bad. In an empty project with nothing rendered and without my task running, the FPS are about 100. The best I got after removing default post process and gfx features was around 180. The time taken by my task is directly affected by the FPS. E.g. without unreal, by using directx directly I can get 1000fps easily without rendering anything, and my task finishes N times earlier there. So I have been thinking doing it unreal in edit mode in the hope of getting rid of those unknown garbages slowing down the FPS in play mode by default. Any better suggestions:)?
Could you share more details about how you make tick work in edit mode please?
i was making an EditorUtilityWidget and i just overrided the tick function.
if you have a UObject, i guess you can follow this tutorial, but i dont know if this will work in editor : How to make a Tickable Object · ben🌱ui
maybe you could include Engine.h and do what RecourseDesign said
or maybe make an EditorSubsystem
The link you suggested indeed works, thanks a lot! @ugmoe
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.