Is it ok to have this many bindableevents?

I’m recreating the mouse object using userinputservice, and i am using bindableevents for the events. Is it good to use this much or maybe should i try something else like a signal module?


function event()
	return Instance.new("BindableEvent",script)
end
local events = {
	KeyDown = event(),
	KeyUp = event(),
	Button1Down = event(),
	Button1Up = event(),
	Button2Down = event(),
	Button2Up = event(),
	Move = event(),
	Idle = event(),
	WheelBackward = event(),
	WheelForward = event()
}

I dont see an issue with it. but there probably is a quicker solution on what your trying to create

1 Like

If you’re going to be creating BindableEvents each time a keystroke is recorded you should destroy those events once the keystroke has ended.

1 Like

I already have a solution, and no, i dont create bindable events every keystroke.

I know this is already solved, but I wouldn’t really recommend doing this because more instances > more memory usage which in turn adds more lag. What I would do instead is have one bindable event for every event, and have the first parameter be the key such as: “KeyDown” and then interpret that for each event.

Thats exactly what i did, but thanks for your post

1 Like

I’ll pitch in another suggestion: use pure Lua signals. You’re still going to be consuming memory when creating the signal object but the difference doesn’t matter that much. Pure Lua signals will give you a lot more power in most cases (e.g. being able to pass by reference instead of copy and being able to pass tables with metatables).

The memory consumption of BindableEvent instances isn’t significant enough to warrant any trouble, you can realistically have as many of them as you want so long as they make sense to have them. You want to think more about the architecture of your code in this scenario (e.g. is it smarter, as previously suggested, to just pass an argument to one event?).

2 Likes