Method FindObjectsOfType<>() doesn’t work, what are the other options for solving this?
Not sure how literal you are with your code snippet.
FindObjectsOfType<>() requires a type. For example:
var objects = FindObjectsOfType<Class_Type>(); // objects would contain all the active Class_Types in the scene.
I only asked about the name of the method (sorry for the shortcut), literal code looks like this:
So it’s just a slight change from the course code (in line 15), but it’s not working.
I’m surprised that code compiles. I would have expected a type mismatch. surfaceEffector2D should be an array as the FindObjectsOfType function returns an array and then you’ll need to loop through each of them if you need to change the speed in all of them.
Change it to FindObjectOfType and it’ll return the first Effector it finds and the rest of your code should work, but not sure if that’s what you want.
The thing is, that I want it to work in all of Effectors, not just in one.
So I guess the solution would be a loop, as you wrote, but would it be the most efficient method for obtaining that? How it would look in the code?
You’ll probably be best to do a loop like you already thought. I’m not going to write it for you, but if you get stuck I’m happy to help, but you gotta try some coding/googling first. Hint: for or foreach is what you should look at.
Gotta be careful what you ask. The most effecient is subjective. Efficient in programming time? Programming execution time? Debugging time?
For me, I might even look at a ScriptableEvent and ScriptableEventListeners but that can introduce a level of abstraction/complexity in code that you might not be ready for yet. If you want to dive in (they’re amazing to learn about), go watch that 65 min video a few times.
It’s a good learning opportunity to go and dig through to figure out how to do it. You’ll learn ten times more than if it was handed to you.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.