- Home /
char and char*
How do I convert a char to char*?
Code:
DeathText.text = new String(' ');
Error CS1503 Argument 1: cannot convert from 'char' to 'char*'
I'm using Visual Studio
Answer by Bunny83 · Jan 03, 2018 at 11:36 PM
You don't want to use a char pointer in Unity as it requires unsafe code. The String constructor has several overloads but there is none that takes just a single char value. In almost all cases you don't need / want to use a string constructor at all.
If you want to set the text to a string that contains a single space character you would just do
DeathText.text = " ";
Though in most cases when you want to clear the text you would assign an empty string:
DeathText.text = "";
Note that string literals use double quotes "
while char literals use single quotes '
.
unity gives me a NullReferenceError: Object not set to an instance of an object
when i do DeathText.text = ""; it says that a string cannot be converted to char when i do DeathText.text = ''; it says it cannot be an empty char literal.
What is "DeathText" and how is "text" declared? As i said you should never even think about char*
in C#. Char pointer require an unsafe context to be used. A single char variable can only hold a single character.
Your question is missing a lot of details. We can only guess those missing things. You may want to edit your question and add more details.
Answer by OneCept-Games · Jan 03, 2018 at 11:26 PM
This does not look like Unity, but try:
DeathText.text = new string(' '); string with small s.
Your answer
![](https://koobas.hobune.stream/wayback/20220612145756im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
error with GUI in c sharp 2 Answers
Distribute terrain in zones 3 Answers
Asset Bundle export script 'Cannot convert' error 1 Answer
Object Reference not set to an instance of an Object Help 1 Answer