Page 1 of 1
Issue having Game Object Spawn to player's position on load.
Posted: Wed Nov 03, 2021 5:27 pm
by Omniclause
First off I just want to say what a wonderful asset this has proven to be. It has given me the opportunity to add tons of functionality to my game that I would have been able to code from scratch myself. I have learned the basics of the dialogue system and am starting to delve into the save system. I have a player that saves the game to slot whenever it encounters a checkpoint save. This is working fine and it is saving the player's position as expected. One of the main mechanics of my game is that there is a cart in the game that the player pushes around and interacts with the environment with. In the cart scripts start function I have it's transform set to wherever the player is with a slight offset. This works fine in normal testing, but when I load from the save slot the cart's transform is set to where the player is placed in the scene view and does not move to the player's saved transform. Is there any way to fix this?
Re: Issue having Game Object Spawn to player's position on load.
Posted: Wed Nov 03, 2021 8:22 pm
by Tony Li
Hi,
You could add a Position Saver component to the cart to save its position in saved games and when returning to scenes.
However, if you need the cart to move to the player when the player spawns into the scene at a spawnpoint, you'll need to handle it a little differently. Let's say your cart script's Start() method calls a method PositionCartNearPlayer():
Code: Select all
public class CartScript : MonoBehaviour
{
private void Start()
{
PositionCartNearPlayer();
}
public void PositionCartNearPlayer() // (Example)
{
transform.position = GameObject.FindWithTag("Player").transform.position + Vector3.right;
}
}
Add a Dialogue System Trigger to the cart. Set its Trigger dropdown to OnSaveDataApplied. Then Add Action > OnExecute() UnityEvent, and configure the OnExecute() event to call the cart script's PositionCartNearPlayer() method.
Re: Issue having Game Object Spawn to player's position on load.
Posted: Fri Nov 05, 2021 7:54 pm
by Omniclause
Thank you so much! This worked for me! I basically had it set up exactly like that but with one minor difference which I'm assuming is what was breaking it. I had the player's transform set as a public variable and clicked and drug it from the player in the inspector. Which was working in playtesting before I implemented the save system. I guess the cart loses the player when it's not where it was expected. Thank you for your speedy response and props again for developing and maintaining such a wonderful asset.
Re: Issue having Game Object Spawn to player's position on load.
Posted: Fri Nov 05, 2021 9:34 pm
by Tony Li
Happy to help! I'm glad you got it working.