I’m having a scroll view issue:
I remember seeing this along time ago but i don’t remember the solution
I’m having a scroll view issue:
I remember seeing this along time ago but i don’t remember the solution
no one has a solution?
I don’t understand what you’re trying to show. Is your text enlarged? What are you showing in the first screenshot?
That’s what happens when I bring data in from my API. It even happens when I split the text. I’ve split it down to just a few letters and it still wants to mess up. I seen this once but not sure how they fixed it.
However you are populating your scroll rect, do those objects have a layout element on them?
Nope, asking about how you’re adding stuff to the content. You need layout elements on those items since you’re using a vertical layout group.
Not sure I understand
I added a layout element to my text object and now I get nothing. Its giving me an error that I have handing elements or something? Just trying to add dynamic text to a scroll view content. .Do you have a video or tut on how to add a simple Game object such as text to a scroll view?
error:
Dangling components have unfulfilled dependencies
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Updated code but now I get nothing:
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Net.Http;
using UnityEngine;
using UnityEngine.UI;
public class PopulateGrid : MonoBehaviour
{
public GameObject prefab; // This is our prefab object that will be exposed in the inspector
public int numberToCreate; // number of objects to create. Exposed in inspector
private DataTable _dtNews;
// Start is called before the first frame update
void Start()
{
Populate();
}
void Populate()
{
GameObject newObj; // Create GameObject instance
string uri = WBG_Config._EndPoint + "api/WhiteBoXGaming/Post_GetWBGNews";
StartCoroutine(NewsWebRequest(uri, WBG_Config._Log_In));
for (int i = 0; i < _dtNews.Rows.Count; i++)
{
//Build Data
DateTime newsdate = new DateTime();
string message = _dtNews.Rows[i]["News_Message"].ToString();
string newsmessage = string.Empty;
newsdate = Convert.ToDateTime(_dtNews.Rows[i]["News_Date"]);
newsmessage = "[" + newsdate.ToShortDateString() + "]" + message;
// Create new instances of our prefab until we've created as many as we specified
try
{
newObj = Instantiate(prefab, transform);
newObj.GetComponent<Text>().text = newsmessage;
}
catch (Exception ex)
{
Debug.LogError(ex.Message);
}
}
}
IEnumerator NewsWebRequest(string uri, object obj)
{
try
{
string json = JsonConvert.SerializeObject(obj);
var client = new HttpClient();
var webRequest = WebRequest.Create(uri);
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)webRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
_dtNews = JsonConvert.DeserializeObject<DataTable>(result);
}
}
catch (Exception ex)
{
Debug.Log(ex);
Debug.Log("Failed To Get News");
}
yield return _dtNews;
}
}
If you’re getting nothing, chances are your dtNews has no data by the time you hit your loop.
However, your problem is most likely a scaling issue. When you instantiate an object and assign it’s parent, it usually isn’t scaled properly. So just set it’s scale it Vector3.one and that might be all you need to fix it. If you select the instantiated object in your hierarchy after it’s added to your scrollview, is it scaled up really large?
I figured it out. So my code above works but I had to put it on the content object its self for this to work on a scroll view. Prior, I had everything on an object and imported the scroll view content etc.