Hi,
I’ve created an extension with some custom behaviors and I’m trying to use the some of the camera properties to adjust the position of an object. My problem is that all of the camera functions seem to return 0.
So if I use the debugger to log values of CameraCenterX() or CameraWidth() within a behavior action, they always just return 0. If I use the same functions within the main events, they return the correct values.
I’ve worked round this by passing the value to the behavior’s action from the main event, but I can’t see why they shouldn’t work within the custom behavior.
I’m certain I’m missing something about how the cameras work.
Can you provide more context or a screenshot? I tested the camera center X in a behavior and it worked in the doStepPreEvents and as an action.
To test it, I created a behavior that worked on text objects. I then added an action to set the objects text to the camera center X. It worked fine.
You are taking about custom behaviors and not custom objects? Also, just to eliminate possible issues, the behavior is assigned to an object and that object is in a scene?
Hi,
As you had it working, I created a test to find out what was happening. As you found, CameraCenterX() works fine in a behavior.
So I played around a bit more to find out what is happening in my code. It turns out the problem occurs when the camera functions are called from a custom object(prefab) in the extension.
I’ve created a custom extension with a custom behavior TestObject and a custom object called Prefab.
The custom object comprises a single sprite to which the TestObject custom behavior has also been attached. The problem still occurs without this additional step, but I was looking at all possibilities.
The TestObject behavior has a single function:
- BehaviorDebugCamera: logs CameraCenterX() directly
The custom object has two functions:
- DebugCameraPrefabFunction: just logs CameraCenterX() directly.
- CallBehaviorDebugCamera: calls the BehaviorDebugCamera function from the TestObject behavior attached to the custom object’s internal sprite.
In the scene I’ve got two objects: a standard sprite TestSprite with the custom behavior and the custom object, PrefabSprite, which also has the custom behavior.
In the events, I log CameraCenterX() in four ways:
- directly from the events
- By calling the behavior’s function from the TestSprite.
- By calling the PrefabSprite’s own function that logs CameraCenterX()
- By calling another function in the PrefabSprite that logs CameraCenterX() via the behavior that’s attached to its internal sprite.
The result is that CameraCenterX() is fine except when it’s called from within the custom object.
I’m wondering if the camera value you are getting is for the custom object. They use their own layers. It’s a bit like a scene within a scene.
You might need to use a behavior to get the scene camera. IDK if there’s a way to get it from a custom object.
I don’t have time now but I’ll read thru your last post more when I can. I currently just skimmed it.
That makes sense. I hadn’t really thought of them as having their own scene, but that might well be the issue.
There are plenty of work arounds, so it’s not an issue, but I couldn’t see why it wouldn’t work. The camera width also comes in as 0 which I think fits in with your suggestion.
Cheers.
1 Like
Custom objects have their own layers. I was able to hide and show a layer but I don’t know if the camera does anything yet. Changing the position or the zoom didn’t seem to change anything. I know this doesn’t pertain to your issue. I was just curious.
It is quite interesting. I tried to get the camera info using the runtime scene object in JavaScript, but got the same result.
Custom objects have layers but at the same time, you set the size of the object, so the layers don’t seem to really be infinite. Unless the object size is more like the scene size. Prefabs are still a work in progress. I’m hoping one of the people more involved with the inner workings would chime in.
Thanks for this. There’s not much online about how the custom objects work, so as you say, it would be great if someone with knowledge of the inner workings could drop in their two pennies worth.
Thanks for looking into this though.
1 Like