Question about character instantiation

Help, support and information for our Game Framework Unity Asset.
If posting about the assets in the extras bundle then please use the appropriate forum.
Post Reply
bradjensen68
Posts: 65
Joined: Thu Dec 08, 2016 7:34 pm

Question about character instantiation

Post by bradjensen68 » Fri Jul 13, 2018 4:09 pm

Hello! I am trying to combine the Game Framework with another framework deisgned to racing games. In that context, when the race begins, that framework instantiates the player from a public variable. However, I want it to not use the value of the public variable, but rather to use the character that I have selected previously in Game Framework.

so I want to add something like RaceManager.instance.playerVehicle = GameManager.Instance.Characters.Selected.GetComponent<RaceCompetitor>(); to their script but this does not seem to work. Can you give me a tip on how to do this? Thanks!

--Brad

mahewitt
Site Admin
Posts: 241
Joined: Thu May 05, 2016 8:06 pm

Re: Question about character instantiation

Post by mahewitt » Sun Jul 15, 2018 8:34 pm

GameManager.Instance.Characters.Selected will return a GameItem, so I am assuming that the GetComponent<RaceCompetitor> is causing issues?

You could try adding a prefab to the Character configuration files and then use a call to GameManager.Instance.Characters.Selected.GetPrefab(name);

Let me know if that helps.

Mark

bradjensen68
Posts: 65
Joined: Thu Dec 08, 2016 7:34 pm

Re: Question about character instantiation

Post by bradjensen68 » Sun Jul 15, 2018 9:42 pm

Do I actually use "name" or do I need the name of the prefab I am trying to get?

Right now, I am getting:

Cannot implicitly convert type `UnityEngine.GameObject' to `RGSK.RaceCompetitor'

EDIT** Seems I need to do "type casting", correct? Perhaps

return (RaceCompetitor) GameObject; ?? - I have no idea :(

mahewitt
Site Admin
Posts: 241
Joined: Thu May 05, 2016 8:06 pm

Re: Question about character instantiation

Post by mahewitt » Tue Jul 17, 2018 2:43 pm

That call will indeed return a reference to the prefab (a gameobject). You can then either instantiate it (if you need copies in your scene) or call things like GetComponent<RaceCompetitor>() to get that component.

blamejane
Posts: 6
Joined: Wed Feb 20, 2019 1:07 am

Re: Question about character instantiation

Post by blamejane » Wed Mar 13, 2019 12:38 am

Hey Brad (jaberwoky?)

I am finally ready to do the same race car/character instantiation and I'm wondering if you created a custom script to do the assignment from Game Framework selected character to race manager player instance? I'll assume you did because I can't imagine that you could do it without a custom script, unless you modified your race manager script. Anyway, could you tell me which game object you put the character assignment script on. Was the the Race manager component, or was it the _SceneScope for the current level?

Thanks,

blame jane/Valerie

bradjensen68
Posts: 65
Joined: Thu Dec 08, 2016 7:34 pm

Re: Question about character instantiation

Post by bradjensen68 » Sun Mar 24, 2019 11:49 am

So what I did was kind of a hack but it seems to work alright. I have one game object that is instantiated by RGSK that has all of the scripts attached to it that RGSK needs and it contains all of the vehicle bits that are the same regardless of which vehicle I have selected, For example, the steering column. Then I have a "Instantiate Character Prefab" attached to it that adds the actual vehicle. It also contains an empty game object that has a "Instantiate Player Prefab" script that drop the chosen driver and the IK targets into the scene.

Note for anyone reading this that doesn't know what the heck we are talking about - it is the integration of Game Framework with Racing Game Starter Kit.

Post Reply