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

Open
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
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