Godot Invalid get index 'Player' on base 'KinematicBody2D' - gdscript

Ok guys, i just trying to make a function to make a camera like top-down games with rooms, and idk why this appear, can you help me?
Code and error (Screenshot)

In your scene 'player.tscn', is the player Node actually named 'Player' or does it still have the default name 'KinematicBody2D'? The actual node needs to be named 'Player' if you want to use the reference you've given above.

Related

How do you play an animation in the UI when the trigger is in another blueprint?

I am a beginner with unreal engine. My end goal is to play an animation in the user interface that makes the word "coin" move. I have a blueprint called "BP_Coin" which spawns coins that the player can pick up and have it added to their total. When the coin is picked up, I can't get the animation of the "coin" text to play. The animation is in the widget blueprint called UIWidget.
I assume casting is my only issue, but am I doing this inefficiently? What's the easiest way to accomplish something like this?
I've followed a tutorial that mentions creating a reference with a game instance class and using that in the object slot of the CastTo, but I was unsuccessful. It would always come up with "cast failed".
There should be a CreateWidget node (documentation) somewhere in your blueprints in order to even display widget on player's screen. You may pass output of that node into CastToUIWidget function to achive what you probably need.
Hope that answers you question.

Text Mesh Pro UGUI Objects disappearing in Play Mode, Unity Version 2019.3.5fl Personal

So I have been stuck in this issue for awhile now: I get the error message: "Reference Exception: Object reference not set to an instance of an object" but that's because some of my text mesh pro objects gets deleted by itself!!! Apparently every single time I hit play some of the text mesh pro objects disappear from where it was assigned in the first place..
Code Implementation in the script class:
Example: This is how it look before play mode:
Now this is how thei nspector section looks like while on play mode:
Now once I hit play a few text mesh pro objects just got deleted by itself..
Any idea or feedback please?
Thank you in advance!
Amaury
Alright I see what is Wrong.
In the inspector, you set every Text Mesh Pro Object you need.
But in your script, you are using the function GetComponent on every of the object, which is useless and even buggy since you already declarate them in the inspector.
Remove these lines and it should work :)
EDIT: Also, for your interest, the function GetComponent will only return the first component found ATTACHED to the gameObject. But you don't have TMPText attached to your gameObject and more than that, you don't have MULTIPLE TMPText attached.

Can't add Orbital script - "The script needs to derive from MonoBehaviour!"

I am developing in Unity 3D for the Microsoft HoloLens 1. I am trying to add the Orbital script from the Mixed Reality Tool Kit to a GameObject, but no matter what I do I keep getting this error message:
"Can't add script behaviour ScreenSpaceMousePointer. The script needs to derive from MonoBehaviour!"
I don't understand why I'm getting this message, since I'm trying to add Orbital, not ScreenSpaceMousePointer. Is there any way to get around this?
EDIT: For further context, I am trying to affix an upright plane with a little map on it to the bottom right of the HoloLens display such that it follows the user wherever they turn their head (much like how a minimap looks in video games).
Orbital inherits from Solver which inherits from MonoBehaviour. So you should be adding it to a GameObject. It's unclear why that error message is appearing without more information.
What version of MRTK/Unity are you using?
Can you create a cube and add orbital via "AddComponent" in inspector?
Can you search for the orbital script in your assets window and drag it onto a simple cube in inspector?
Unfortunately I cannot repo your issue. You can also try looking at the SolverExamples unity scene.
Please, show this script.
Head of it must be like this:
class Orbital: MonoBehavior {
And file name must be Orbital.cs
You may create this file and put inside code you need, but rename class and file to avoid duplicate class name.
Do you have errors in your project? This usually happens for a message you got.

Find object from another scene

I need to find an object from another scene. I have checked both Find and FindWithTag, but both of them give me this error:
NullReferenceException: Object reference not set to an instance of an object.
As i know - there is no way to find object on other scene.
First idea - you can load it as additive scene using SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);
and then use Find
You may find more info here: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
You can write a Game Manager, which can make a script/object that will persist between different scenes, allowing you to carry variables between them. You could use it to have the button change a variable, then have the other scene check the variable when it loads to change the sprite.
A Unity tutorial is here:
https://unity3d.com/learn/tutorials/projects/2d-roguelike-tutorial/writing-game-manager
In your specific case, I'd use PlayerPrefs.Save/SetString to save the variables when player interacts with your UIs or Game Objects in Scene A.
Then when you loading your Scene B, write a scene manager script and on its Awake(), use PlayerPrefs.GetString to retrieve variables, and change your game object behaviors based on the loaded variables.

UnassignedReferenceException: Event after assigning?

I'm an experienced programmer learning Unity for the first time. I know this is the most basic and common error for the newbies. I think I have got it right but it still produces this error. What am I doing wrong?
UnassignedReferenceException: The variable player of 'GameManager' has not been assigned. You probably need to assign the player variable of the GameManager script in the inspector.
I think the following screenshot provides everything needed.
you have to assign Game Asset in the hierarchy panel to the game object which has GameManager.cs Script Component
I too am new to Unity and had a similar problem, but after thinking about what was going on I came to the conclusion that the error message was misleading me a bit. When it tried to be helpful by suggesting "You probably need to assign the player variable of the GameManager script in the inspector" I went straight to the script and set it but the error persisted.
It was then that I realised that I didn't have an object in the Hierarchy panal which had my script attached. What I was doing was instantiating an object (my 'player' prefab) at runtime and it was the prefab that had the script attached. Of course, my script might be added to any number of objects and each object will have its own variables, so each object needs to have its own instances of its variables set. If you wanted the same value to be set in all instances you probably make your variable static but it won't then appear in the inspector. So, setting the variable in the Script component of my prefab fixed it for me.
I think that's enough waffle for one day - hope it helps somebody! :)