Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial setup for _follow_spring_arm_node is delayed for first time assignment of Properties.follow_target_node #193

Closed
ZenithStar opened this issue Jan 23, 2024 · 4 comments · Fixed by #282

Comments

@ZenithStar
Copy link
Contributor

ZenithStar commented Jan 23, 2024

Issue description

When in ThirdPersonFollow mode and follow_target is assigned to something non-null for the first time, the initial setup for _follow_spring_arm_node is triggered, but not until the next _process tick of the PhantomCamera3D. # The default behavior is for the spring arm orientation to be initialized to the orientation of the PhantomCamera3D, however, I would like for it to initialize to the orientation of the follow_target that was just assigned. If I try to set it immediately after I assign follow_target (pcam._follow_spring_arm_node.basis = pcam.get_follow_target_node().global_basis), the initialization code inside PhantomCamera3D._process will overwrite it on the next process tick.

This is only a problem for the first assignment of follow_target. Subsequent assignments will not trigger the initialization code and so I can immediately set the orientation of the spring arm. Currently, a simple workaround for my use case is to add a small delay so that _process can tick once before I assign the orientation:

if not pcam.get_parent() == pcam._follow_spring_arm_node:
	get_tree().create_timer(0.01).timeout.connect(func(): pcam._follow_spring_arm_node.basis = pcam.get_follow_target_node().global_basis )
else:
	pcam._follow_spring_arm_node.basis = pcam.get_follow_target_node().global_basis

IMO, the best solution would be to take any initialization code out of _process and instead trigger it from its own function when conditions for initialization have been met.

Steps to reproduce

  1. Create a scene with a PhantomCamera3D in Follow Mode: Third Person without assigning a follow target.
  2. Assign a follow target and immediately try to pcam.set_third_person_rotation. This assignment will apply, but will be immediately overwritten.
@eliaskowitz
Copy link

i ran into the same issue of needing to initialize some properties of the third person spring_arm on ready and it not working. instead of a using a timer i added a signal to the phantom camera that emits after it reparents the spring_arm. that seemed to work for my use case and it might work for yours. i don't know if its a good solution over all or not though

@ramokz
Copy link
Owner

ramokz commented May 1, 2024

Is this still an issue in 0.7?

@ZenithStar
Copy link
Contributor Author

Yes. I didn't realized it when I made this change, but there's still initialization code inside PhantomCamera3D._process
Moving the rest of the initialization code into _ready() allows for me to change the workaround code from

if not pcam.get_parent() == pcam._follow_spring_arm:
	get_tree().create_timer(0.01).timeout.connect(func(): pcam._follow_spring_arm.basis = pcam.follow_target.global_basis )
else:
	pcam._follow_spring_arm.basis = pcam.follow_target.global_basis

into

pcam._follow_spring_arm.set.call_deferred("basis", pcam.follow_target.global_basis)

@ramokz
Copy link
Owner

ramokz commented May 2, 2024

Can see you're assigning a basis value to the springarm node, would adding a setter function to the addon script make that easier?

ramokz pushed a commit that referenced this issue May 2, 2024
…282)

* Move all spring arm initializaiton code out of _process into _ready. Resolves #193

* Making _follow_spring_arm explicitly top_level

* Default _follow_spring_arm.position initialization to the original pcam position if follow_target is not available
@ramokz ramokz closed this as completed in 0b2b1a9 Jun 1, 2024
ramokz added a commit that referenced this issue Jun 3, 2024
* Move all spring arm initializaiton code out of _process into _ready (#282)

* Move all spring arm initializaiton code out of _process into _ready. Resolves #193

* Making _follow_spring_arm explicitly top_level

* Default _follow_spring_arm.position initialization to the original pcam position if follow_target is not available

* Updated plugin.cfg to 0.7.1

* Change Camera3DResource.cull_mask to use export_flags_3d_render. Resolves #290 (#293)

* Only show viewfinder if the active PCam's mode is framed (#295)

* Only show viewfinder in the correct follow mode

* Adjust comments

* Reorder early returns

* Remove unneeded type cast

* Updated Editor Updater wording for major releases

* Improved Limit Target error setter

* Added FUNDING.yml

* 2D Follow Physics Interpolation (#294)

* Initial _process / _physics_process logic split

* More 2d physics interpolation supported
- [Added] Interpolation Update Mode to PCamHost
- [Added] Additional warnings

* Commented out 4.3 specific code

* Stripped out a few todo comments

* Removed uneeded checkers

* Added physics body checker for Group Follow

* Added reset_physics_interpolation
- [Updated] Physics Interpolation to use string setters

* Added physics target checker to PCam3D
- [Moved] Follow Targets setters/getters closer to other Follow setters/getters

* Aligned PCam2D' script with PCam3D's

* Added missing variable assignment

* Added missing return for Framed Follow checker

* Removed unneeded boolean flag

* Tidied up process logic

* Added Jitter Tip output

* Added physics checker to Look At Group

* Updated parameter type from NodePath to Node3D

* Updated spacing for setters/getter functions

* Set _player_visual to top level in 2D example scene

* Added additional jitter context

* Phantom Camera Manager (#306)

* Initial _process / _physics_process logic split

* More 2d physics interpolation supported
- [Added] Interpolation Update Mode to PCamHost
- [Added] Additional warnings

* Commented out 4.3 specific code

* Stripped out a few todo comments

* Removed uneeded checkers

* Added physics body checker for Group Follow

* Added reset_physics_interpolation
- [Updated] Physics Interpolation to use string setters

* Added physics target checker to PCam3D
- [Moved] Follow Targets setters/getters closer to other Follow setters/getters

* Aligned PCam2D' script with PCam3D's

* Added missing variable assignment

* Added missing return for Framed Follow checker

* Removed unneeded boolean flag

* Tidied up process logic

* Added Phantom Camera Manager singleton

* Minor fix for when not having a PCam in scene

* Removed print statement

* Fixed merge error

* Removed unneeded print statement

* Improved viewfinder detection (#307)

* Added PCamHost warning when not child of Camera

* Additional camera3d parameters (#308)

* Added additional PhantomCamera3DResource properties

* Shortened Camera3DResource local variable names

* Updated Editor Updater to be less intrusive (#309)

* Conditional checker for Cam3DRes changes

* Added support for disable_3d export templates (#311)

* Fixed viewfinder during play error

* Minor tweaks

* Minor post-main merge fix

* Updated plugin.cfg to 0.7.2

* Resolved issue with disabled tween on load for Third Person Follow (#319)

* Updated Third Person to update follow_position instead of global_position

* Removed commented out code in PCamHost

* Resolved issue with Follow Mode None getting stuck (#320)

* Added public properties and getters for PCamManager

* Updated git issue link

---------

Co-authored-by: ZenithStar <ZenithStar@users.noreply.github.com>
Co-authored-by: audeck <55060124+audeck@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants